More Mail Filtering with procmail
Welcome to the fourth and final installment of our look at administering electronic mail. Last month, we began talking about procmail, a powerful general purpose mail-filtering facility, and its ability to sort (and possibly reject) incoming messages based on any criteria you desire. This month we’re going to look at some more advanced uses of procmail, such as identifying spam messages and scanning incoming mail for viruses.
Wednesday, August 15th, 2001
Welcome to the fourth and final installment of our look at administering electronic mail. Last month, we began talking about procmail, a powerful general purpose mail-filtering facility, and its ability to sort (and possibly reject) incoming messages based on any criteria you desire. This month we’re going to look at some more advanced uses of procmail, such as identifying spam messages and scanning incoming mail for viruses.
Using procmail to Discard Spam
In order for procmail to successfully identify spam messages, you must be able to describe the characteristics of the messages you want to treat as spam and then write recipes accordingly.
Let’s take a look at several recipes that may be useful as models of handling spam. They happen to come from my own .procmailrc file, and so are applied only to my mail. As an administrator, you can choose to deal with spam at several levels: through the transport agent (e.g., checking against blacklists), at the system level, and/or on a per-user basis. In the case of procmail-based filtering, anti-spam recipes can be used in a system-wide procmailrc file or made available to users wanting to filter their own mail.
The following recipe is useful at the beginning of any procmail configuration file, as it formats mail headers into a predictable format:
# Make sure there’s a space after header names :0fwh |formail -z
The next two recipes provide simple examples to one approach to handling spam: