procmail
[Top] [All Lists]

Re: Archiving mail

1997-11-12 11:26:17
On Wed, 12 Nov 1997 08:08:08 -0800, PSE-L(_at_)mail(_dot_)professional(_dot_)org
(Professional Software Engineering) wrote:
At 04:12 PM 11/12/97 +0100, Andreas Sikkema wrote:
Is there a way to get procmail save mail to a folder with a date in
the name? I want procmail to save some mail to a folder that changes
it's name every month. Or do I need another app to do this?
In your .procmailrc before you start recipes:
# Check man date for formatting info. This is YYYYMM format. To add
# DD (day) to the end, append %d to the format string
MAILDIR=$HOME/Mail/`date +"%Y%m"`
# this makes the directory if it doesn't already exist
DUMMY=`test -d $MAILDIR || mkdir $MAILDIR`

It bears pointing out that this may be unacceptably heavy if you
receive a lot of mail, as it will spawn a couple of processes for
every message that are mostly going to do nothing. A different
approach -- I don't do this myself, so this is basically off the top
of my head -- could be to create a file you INCLUDERC which contains
whatever date your most recent cron job created. Then run a
monthly/daily/whatever job from cron which recreates this file with an
appropriate date stamp and makes sure the corresponding directory
exists.

OTTOAHWIAVF: *

    #!/bin/sh

    TODAY=`date %Y%M`

    MAILDIR=$HOME/Mail
    DEST=$MAILDIR/$TODAY
    PMDIR=$HOME/procmail

    echo "TODAY=$TODAY" >$PMDIR/date.rc
    test -d $DEST || mkdir $DEST

* (Off The Top Of A Head Which Is Already Very Flat)

Then from your .procmailrc, INCLUDERC=$HOME/procmail/date.rc and
wallah, you have [a reasonable approximation of] today's date. 

... It is approximate because you probably don't want to run this job
exactly at midnight. For one thing, it's a good habit to not run
regular processes on times other people are somewhat likely to also
run theirs. For another, the "mental" date change is probably closer
to four in the morning if you're like me. (If you always go home at
five PM and return to your desk at nine in the morning and read new
mail, five in the evening would be a reasonable time to run it.)

It is also approximate because you can't be sure the machine won't be
down when the job is scheduled to run. If this happens often, you want
a backup method, perhaps in conjunction with your login or logout
scripts. In fact, a backup method would always be a good idea. 

/* era */

It is +reasonably+ approximate because the bad things always seem to
happen only to others, and real [gender]s don't need backups.

-- 
 Paparazzi of the Net: No matter what you do to protect your privacy,
  they'll hunt you down and spam you. <http://www.iki.fi/~era/spam/>

<Prev in Thread] Current Thread [Next in Thread>