Mike A. Harris wrote:
a better alternative would be a mail backup that puts a copy of all
messages received for the entire DAY into a file in a backup
directory with the date as part of the title. Something like:
~/mail/incoming/backups/backup-$(date +"%Y-%m-%d")
I'm using something like that, but I try to avoid the date call for
each single message by extracting the date from the From_ line
instead. In messages I download from my ISP it always looks like this:
From someone(_at_)some(_dot_)domain Tue Jan 23 12:34:56 2001
So I have the following near the beginning of my .procmailrc (well,
actually I've moved most of it to a separate file that gets pulled in
via INCLUDERC, but you get the idea):
/---------- snip ----------\
# Parse date in From_ header (or call date(1) if the format is
# different from the expected one), and store the results in the
# variables YYYY (four digits), MM (two), DD (two).
DAYNAME="(Mon|Tue|Wed|Thu|Fri|Sat|Sun)"
MONTHNAME="(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"
MONTHNUMS="Jan01Feb02Mar03Apr04May05Jun06Jul07Aug08Sep09Oct10Nov11Dec12"
:0
* $ ^^From .* $DAYNAME \/$MONTHNAME [ 0123][0-9] .* 200[0-9]
{
YYYY=yyyy
MM=mm
DD=dd
# If one of those values still appears in the result,
# something has gone wrong.
# Save entire matched string in FROM_DATE, so that \/
# can be used without destroying anything.
FROM_DATE=$MATCH
:0
* FROM_DATE ?? ()\/....^^
{ YYYY=$MATCH }
:0
* FROM_DATE ?? ^^\/...
* $ MONTHNUMS ?? $MATCH\/..
{ MM=$MATCH }
:0
* FROM_DATE ?? ^^[a-z ]+\/[0-9]+
{ DD=$MATCH }
:0
* DD ?? ^^.^^
{ DD=0$DD }
}
# Fallback: If the From_ line didn't have the expected format,
# we call date(1) and set the variables by splitting the result.
:0 E
{
YYYYMMDD=`date +%Y%m%d`
:0
* YYYYMMDD ?? ^^\/....
{ YYYY=$MATCH }
:0
* YYYYMMDD ?? ^^..\/..
{ MM=$MATCH }
:0
* YYYYMMDD ?? ^^....\/..
{ DD=$MATCH }
}
:0 c:
/tmp/mail-backup/$LOGNAME/$YYYY-$MM-$DD
\---------- snap ---------/
I know, I know, it's not really necessary to set three variables if
all I want is to combine them again anyway, but this way I can still
use the values separately later on, e.g., to save some lists in
monthly and some others in daily folders.
Comments, anyone?
And then have it auto-delete all backup files that are a month
old. This would likely be most easily implemented as a cronjob.
Left as an exercise for the reader. :-)
/HW
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail