Find out how to set up basic e-mail filtering in Linux with the procmail Mail Delivery Agent (MDA).
Procmail is a powerful Mail Delivery Agent (MDA) that can be used for any number of things including personal mail filtering, mail delivery on servers, and much more. More often than not, individuals using fetchmail to download e-mail will use procmail to file and deliver it to its final destination—typically an mbox file somewhere on the user's hard drive.
Many users have GUI e-mail clients that can read standard mbox files, but because of procmail's flexibility, they opt to use fetchmail and procmail to download and filter their mail rather than their e-mail client.
For instance, procmail can filter messages based on pretty much any criteria you for which you can write a regular expression. If you wanted to filter mailing list messages into separate mbox files, you could do so based on the Return-Path e-mail header like this:
This snippet of a ~/.procmailrc file uses the regular expression denoted by the line beginning with an asterisk (*); in this case, we are looking for a line in the e-mail message that begins with Return-Path, has any number of spaces or characters, and also contains the e-mail address we want to base the filter on. The next line contains the path of the mbox to which the message delivers if it matches.
The final line in a .procmailrc might look like:
This is a fairly drastic measure, but essentially it means that if none of the previous criteria matched, deliver the message to /dev/null, which would discard the message entirely. A more likely scenario would be to change this to something like /Users/joe/Mail/Inbox where all unfiltered mail would go.
Procmail is so powerful that these expressions are called recipes, and recipes have even been generated to discard spam. You can also rewrite parts of messages based on the content. More information on procmail can be found at www.procmail.org, and you can install it from your Linux vendor's installation medium; procmail comes with all Linux distributions.