Procmail recipe for sorting by date
This is not a super complex recipe or anything, but I’ve wanted this functionality for a while and never quite got around to working though procmail’s arcane syntax.
Basically it saves a copy of each incoming mail into a folder ‘$YEAR/$MONTH’ so that I can easily go back and look through older mail. It also lets me delete anything in my inbox, knowing I have a backup.
Here it is:
PMSRC=/usr/share/procmail-lib INCLUDERC = $PMSRC/pm-jadate.rc
:0 c .$YYYY.$MM/
This example works for maildir style folders. For mbox, try this:
PMSRC=/usr/share/procmail-lib INCLUDERC = $PMSRC/pm-jadate.rc
:0 c: /$YYYY/$MM
Save one of the above into the .procmailrc file in your home directory on your mail server or workstation as appropriate. You’ll need the “procmail-lib” package installed in order for this to work and you may need some extra environment variables for your server (mine are all defined globally in /etc/procmailrc).
pm-jadate.rc tries to set $YYYY and $MM (amongst other variables) according to the information stored in the mail, such as the Date: field. It does this so you can run old mail though the filter and have it sort properly. If it can’t figure out the date, it uses today’s instead. Docs for the whole (and rather useful) procmail-lib can be found here.
This was made on an Ubuntu server. The PMSRC path may be different on other flavours of linux/unix.