set] MATH DEPT Computer News, Volume 28

How to create an e-mail filter via a .procmailrc file

Do you get twenty to thirty e-mail messages per day about the NSF VIGRE program like I do? I describe here various ways you can filter messages like these so that they can be dispensed with in a timely and efficient manner.

You will create a file named .procmailrc in your home directory. Click HERE to see what my hypothetical .procmailrc looks like. I will explain what the lines do and how you can modify them to suit your needs. (To see my actual .procmailrc, type more ~bell/.procmailrc from any math.purdue.edu machine.)

To begin, let's consider what the lines at the top of the file do:

# LOGFILE=$MAILDIR/from.procmail

The first two lines are standard and you'll probably want to leave them alone. (The cyber savy like Clarence Wilkerson might use the nmh program to process their mail. They'll know what to add here for that. Click HERE to see Clarence's .procmailrc file.)

The line


explains that I keep my e-mail folders in a directory called Mail in my home directory. I use the e-mail program called elm and that's where elm puts mail folders. If you use pine, you'll want to change this line to


because pine puts mail folders in a directory called mail with a small "m".

If you use Netscape mail, you'll need to figure out where Netscape stores your mail folders. Older versions of Netscape used $HOME/nsmail, but newer versions might use something as odd as $HOME/.mozilla/bell/upz7ekg9.slt/Mail

If you use plain old Berkeley mail, you really ought to switch to pine today. See my pine tutorial for a quick lesson on how to use pine.

The next line

# LOGFILE=$MAILDIR/from.procmail

is commented out. If you delete the # and the blank space at the beginning of the line, a file named from.procmail will be created in the mail directory that you specified above telling you everything that your procmail filter has done lately. You might do this for awhile until you gain confidence that the system really works. (The from.procmail file can get rather large and you'll want to delete it from time to time.)

Ok, now for the fun part. Let's start with the block of lines

* ^Subject:.*VIGRE

This block causes the procmail program to scan the header of each of my incoming mail messages for the word vigre in the Subject line. The scan is not case sensitive, so vigre, VIGRE, and Vigre (and even a VIgrE from David Drasin) will cause a match. If a match is found, the mail message will get sent to a mail folder called vigrestuff in my Mail directory. (If the file does not exist, it will be created the first time a vigre subject is encountered.) I will never see these messages in my mail inbox, but later, at my conveniece, I can start elm and open my Mail/vigrestuff mail folder and dispense with the messages all in one place.

The lines

* ^Subject:.*Wicked Screensaver

send any e-mail with a Subject line that matches "Wicked Screensaver" to oblivion (which is "/dev/null" in computer lingo). You'll never see these messages and you'll never know you got them (unless you are keeping that logfile we mentioned above). You can replace the :0: line in blocks that send to /dev/null by a mere :0 but I don't want to explain that here.

The lines

* ^Subject:.*mortgage

send any message with the word "mortgage" in the Subject line to a mail forlder named trash. Every now and then I look through the trash folder and trash it.

I am particularly offended by messages that suggest that we might like to increase the size of our VIGRE program. The next block will send these messages to /dev/null.

:0 BH:
* ^Subject:.*VIGRE
* size

The :0 BH: on the first line tells procmail to scan both the Header and the Body of the e-mail. (Of course, it is important to put this block above the block that sends vigre messages to my vigrestuff folder.)

It is important to have those blank lines between blocks. You'd be surprised to learn that the second colon in the :0: command causes a "lockfile" to be created. I learned most of what I know about procmailrc's by pouring over this elegant and well crafted .procmailrc of one of our former system admininstrators.

It happens from time to time that a spam message with a distinctive subject line sneaks by alligate en masse (because the alligate settings need to be set at a rather low level so that important messages about, say, degenerate pseudodifferential operators, can get through to us). For example, I got a whole bunch of messages with subject line {subj190107} the other day. I could have added the lines

* ^Subject:.*subj190107

to my .procmailrc that day and sent that stuff to my Mail/trash folder so I could delete it all in one sitting later. When the flow of that particular spam stopped, I would delete those lines from my .procmailrc.

Fiddling with a procmailrc to post-filter spam is probably for advanced useres only. A computer savy graduate student I know pointed out to me that a safer, and perhaps more useful way to post-filter spam, is to use an e-mail client with an adaptive spam filter such as Mozilla Thunderbird. The satisfied user told me

After "teaching" it what spam is for about a week, it filters out well over 90% of my post-filter spam, and I have yet to have a real message filtered out. When new trends come up in spam that start to circumvent the filter, I just mark the intruders as spam, and Thunderbird "learns" to filter out the new ones as well.

To learn much more about the nitty gritty details of the procmailrc, and to see more examples, type

man procmailrc
man procmail

to see our man pages about procmail, and go to


to learn more than you could ever hope to want to know.

Back to the Network News Index Page

Back to the MATH 2000 HOME PAGE