Procmail cookbook for better mail reading

Thanks to egroups.com (now yahoogroups.com), sourceforge.net and others any online Outlook Express wielding moron can set up a mailing list. In order to not confuse said user into thinking that he or she is receiving fan mail, the software adds the name of the mailing list to the Subject line in the mail header, and sets the Reply-To.

But why should good netizens be subject to this unfortunate and ill mannered message mangling? Why indeed, when procmail is available.

Step by Step

You need procmail, GNU sed and m4. You probably already have them on your system.

In order to simplify things (grin) your .procmailrc will be preprocessed with the m4 macro processor. You need to download the relevant mail cleaning macros. Another helpful feature of these macros is that duplicate messages (i.e. emails that end up heading into the same mailbox twice) are bunged into a duplicates mailbox.

Then you must set up the input procmail file: call it .procmailrc.m4 or something. The start should look more or less like this:

include(`procmail-cleaning.m4')

MAILDIR=$HOME/Mail/
DEFAULT=$MAILDIR/spam
LOGFILE=$HOME/Mail/Procmail/log

:0 c:
$MAILDIR/mail-archive
    

If you don't have a Mail subdir in your home directory you should mkdir one, and make sure that it is not readable by your enemies. If you want to be able to see where your messages go, make a Mail/Procmail subdir.

A copy of all of your mail will be stored in ~/Mail/mail-archive before we try any magic, so it won't get lost. See the procmail(1), procmailex(5), procmailrc(5) manpages for more information.

Polite mailing lists

For each mailinglist which doesn't mess messages up too much, put

      MAILINGLIST(
	`mailbox-name',
	`mailinglist@address',
	`procmail-regexp'
	)
    

where mailbox-name is the path of the mailbox into which you want mail from this list to be put, relative to $MAILDIR, and procmail-regexp is what procmail will use to decide whether a message belongs in the mailing list or not.

For example,

MAILINGLIST(
	`freebsd-hackers',
	`freebsd-hackers@freebsd.org',
	`^Sender.*owner-freebsd-hackers@FreeBSD.ORG')
    

Rude mailing lists

Similarly to polite mailing lists,

RUDE_MAILINGLIST(
	`mailbox-name',
	`mailinglist@address',
	`procmail-regexp',
	`stuff-to-strip-from-subject')
    

This time mailinglist@address will be removed from the Reply-To line if present and the subject line will be cleaned. Note that you need to quote [ and ] characters with \\ in stuff-to-strip-from-subject.

For example, to remove [Linux-7110-psion] from each message's subject line,

RUDE_MAILINGLIST(
	`linux-7110-psion',
	`linux-7110-psion@lists.sourceforge.net',
	`^Sender: linux-7110-psion-admin@lists.sourceforge.net',
	`\\[Linux-7110-psion\\]')
    

Normal mailboxes

If after keeping up with all your mailing lists you still have time to read personal mail, you might like to organise it into mailboxes - otherwise it will end up in $DEFAULT (i.e. $MAILDIR/spam). The syntax for this is

MAILBOX(
	`mailbox-name',
	`procmail-regexp')
    

For example, to keep bounce messages out of your personal mail, you could do

MAILBOX(`bounces',`^From:.*MAILER-DAEMON@')

Finishing off

Now all that remains is to run m4 on your little masterpiece

 m4 .procmailrc.m4 > ~/.procmailrc 

and you're away!

John Fremlin

Last modified: Thu Jun 21 01:46:20 BST 2001