[pmmail-list] Manual Filter to Delete old E-mail
James Moe
pmmail-list@blueprintsoftwareworks.com
Wed, 19 Nov 2003 21:42:45 -0700 (MST)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Wed, 19 Nov 2003 18:33:31 -0500 (EST), Kenn Yuill wrote:
>
>Has anyone devised or discovered a method of deleting week-old or
>month-old e-mail using a /maintenance-free/ manual filter?
>
I devised the following script to do a similar job, that of deleting files over a
certain age (in days) and keeping the quantity below a limit. For you only the aging
part is of interest.
The day calculation is simple-minded. It does not account for leap years or other
long term effects.
Change the directory name(s) to suit your needs. Maybe add another sysfiletree() and
do-loop to get a list of directories to clean out.
====[ age-files.cmd ]====
/* rexx */
/*
Call and register ALL of the REXX extended functions.
*/
if RxFuncQuery('SysLoadFuncs') then do
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs';
call SysLoadFuncs;
end
/*
parse source os func exe;
*/
'@echo off'
x = setlocal();
parse arg cmdline;
parse source . . argv0 .;
lpos = lastpos("\", argv0);
if (0 < lpos) then do
dpos = lastpos(".", argv0);
argv0 = substr(argv0, lpos+1, dpos-lpos-1);
end;
argv0 = translate(argv0);
DIR_BASE = "i:\assp";
DIR1 = DIR_BASE || "\spam";
DIR2 = DIR_BASE || "\notspam";
x = directory(DIR_BASE);
if ("" = x) then do
say "?"argv0"-I-The main directory," DIR_BASE", is incorrect.";
exit 9;
end
fname_pattern = "*.eml";
max_age = 60;
max_files = 2000;
age1 = age_dir(DIR1, fname_pattern, max_age, max_files);
age2 = age_dir(DIR2, fname_pattern, max_age, max_files);
say "?"agrv0"-I-Oldest file in" DIR1 "is" age1 "days.";
say "?"agrv0"-I-Oldest file in" DIR2 "is" age2 "days.";
x = endlocal();
exit 0;
/* ----[ age_dir ]---- */
/*
Delete files from the directory that are more than some number of days old,
and the total number of files is less than some number. The age is repeatedly
reduced until the number of files is sufficiently small.
*/
age_dir: procedure
parse arg dirname, filnam_pattern, max_age_days, max_files;
x = directory(dirname);
oldest = 0;
do forever
age = delete_files(filnam_pattern, max_age_days);
if (oldest < age) then
oldest = age;
x = sysfiletree(filnam_pattern, "files.", "f");
if (files.0 < max_files) then
leave;
/*
Reduce age by a week until num of files is small enough.
*/
max_age_days = max_age_days - 7;
if (max_age_days < 7) then
leave; /* My, what a lot of files you have! */
end
return oldest;
/* ----[ delete_files ]---- */
delete_files: procedure
parse arg filnam_pattern, max_age_days;
parse value date('u') with mon "/" mday "/" syear;
age_now = calc_days(syear, mon, mday);
oldest = 0;
x = sysfiletree(filnam_pattern, "files.", "f");
do i = 1 to files.0
parse var files.i fdate ftime fsize fattr fname;
parse value fdate with mon "/" mday "/" syear;
age = age_now - calc_days(syear, mon, mday);
if (oldest < age) then
oldest = age;
if (max_age_days < age) then do
say "?Deleting" fname;
x = sysfiledelete(fname);
end
end
return oldest;
/* ----[ calc_days ]---- */
/*
Calculates the number of days since 0 AD. Doesn't bother with leap years,
julian/gregorian changeover, the lack of 0 AD, etc.
Assumes: 2 digit year starting in 2000.
*/
calc_days: procedure
parse arg syear, mon, mday;
mon_accum = "0 31 59 90 120 151 181 212 243 273 304 334 365";
ndays = ((syear + 2000) * 365) + word(mon_accum, mon) + mday;
return ndays;
====[ end age-files ]====
- --
jimoe at sohnen-moe dot com
pgp/gpg public key: http://www.keyserver.net/en/
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 5.0 OS/2 for non-commercial use
Comment: PGP 5.0 for OS/2
Charset: cp850
wj8DBQE/vEZFsxxMki0foKoRAq5lAJ94MsqbgJgQ3WCX4RrsbH59A8zGEgCfSNXA
TlENYW/wttrcS+Xk1MgcDbA=
=nAa9
-----END PGP SIGNATURE-----
- pmmail-list - The PMMail Discussion List ---------------------------
To POST to the list, send your message to:
pmmail-list@blueprintsoftwareworks.com
To UNSUBSCRIBE, send a message to mdaemon@bmtmicro.com
with the first line of the message body being...
UNSUBSCRIBE pmmail-list@blueprintsoftwareworks.com
---------------------------------------------------------------------