USING PROCMAIL TO FILTER MAILING LISTS

If you use a text-mode e-mail client such as pine or mutt, you can make use of procmail to sort messages into different mailboxes. Typically, Linux MTAs (like sendmail and postfix) deliver to /var/spool/mail/username, and the MUAs (like pine or mutt) read mail from that file.

You can also direct the mail to go through procmail. Using simple pattern matching called recipes, you can tell procmail to deliver different types of mail to different mailboxes, usually in your home directory or a subdirectory called ~/Mail/. To do this, you need to create a file called ~/.procmailrc, which contains the procmail recipes. A simple ~/.procmailrc file would look like this:

VERBOSE=off ## Set to on when debugging

MAIL=$HOME/mail ## Set directory for mailboxes

FORMAIL=/usr/bin/formail ## Set location for formail

MAILDIR=$HOME/mail ## Replace $HOME/Msgs with your message

## directory; mutt and elm use $HOME/Mail;

## pine uses $HOME/mail

:0 Wh: .msgid.lock

| formail -D 8192 .msgid.cache

:0:
* ^TO_(cooker|cooker-firewall)@((linux- mandrake|mandrakesoft).com|mandrax.org) mdk-cooker

:0:

*^TO_sawfish(-announce)?(-admin)?@lists.eazel.com /dev/null

You can see that we set a few global variables such as the location of your mailboxes and the verbosity of procmail. Then we specify a recipe to remove any duplicate messages we receive (the headers of which are stored in a 8-KB cache file). Then we use regular expressions to filter based on the To and CC headers. The first line, :0:, indicates the beginning of a recipe, the next line indicates the string to match, and the third line indicates the mailbox file to write to. In the case of the last recipe, we direct those messages to /dev/null so we don't have to read them.

For more procmail recipe examples, type man procmailex at the command line to view the man page. To use it, simply put |/usr/bin/procmail -f- in your ~/.forward file.