Brock Rozen wrote,
| I'm using the following recipe to save messages to a unique folder based
| on their dates.
|
| :0:
| * $ ^From: majordomo$PGHOST
| * ^Subject: (Majordomo results:) .* (who)
| PG/Backup-`date +%m-%d`
A big problem there is that you run date for every incoming letter. If you
extract the month and date from the From_ line you won't need to.
[I don't understand what good the parentheses are doing in that second
condition, though.]
| I haven't figured out how to have it delete the previous folder
| automatically. These messages are received (if everything works out) once
| a day. Thus, the previous folder is the day before.
|
| If you can figure out how to have it check to see if the previous folder
| exists and how to delete it, I'd appreciate it.
How's this: check if today's folder *doesn't* exist. If not, rm all files
that can match that pattern before you save mail in the new day's folder --
and put a regional lockfile around the routine in case the first two such
letters of the day come in together.
So let's try this:
:0
* $ ^From: majordomo$PGHOST
* ^Subject: Majordomo results: .* who
{
LOCKFILE=PG/Backup.lock # note, no hyphen in lockfile's name
# Get current month and day from From_ header.
:0 # There are two spaces below the "es" of "spaces".
* ^From [^ ]+ ... \/... ?[0-9]+
{ DATE=$MATCH }
:0 # Yank month.
* DATE ?? ^^\/...
{ MONTH=$MATCH }
:0 # Yank day.
* DATE ?? ^^... +\/[0-9]+
{ DAY=$MATCH }
# If $DAY has only one digit, prepend a 0.
:0
* DAY ?? ^^.^^
{ DAY=0$DAY }
folder=PG/Backup-$MONTH-$DAY
:0Wchi # don't think "$" modifier is needed but it won't hurt
* $ ? [ ! -s $folder ]
| rm -f PG/Backup-*
:0 # regional lockfile is still in effect
$folder
LOCKFILE # remove regional lockfile in case of fall-through
}