Processing Mail with Procmail
Cameron Laird's dope page

The Absolute Uber Nfo

Using Pine and Procmail to filter e-mail

The Idea

Primary reasons for using procmail: 1) you get too much mail 2) you get spam. This document will be concerned only with reason #1 and using procmail to sort incoming mail into folders other than the primary inbox. For information on specialized spam-reduction functions of procmail, see some of the links above or do a web search. Further expounding on reason #1, procmail is especially useful in organizing large volumes of mail from different mailing lists so as to free up one's inbox for truly personal messages. The premise of this guide is the use of Pine as your primary e-mail program, but applies as well to the use of Windows and Mac programs like MS Outlook, Eudora and Netscape Messenger. In fact, since the first version of this document, I have switched mail clients twice. Once from Pine to IMAP versions of Outlook and again to Netscape Messenger after Outlook deleted my inbox twice. (For more information on implementing IMAP -- much better than POP -- see the forthcoming guide.)

Three-point Platform

Every decent plan has a three-point platform and so does filtering e-mail. - set up procmail to actually do the gruntwork of filtering incoming messages. - configure Pine to acknowledge the work that procmail has done so that it displays your new inboxes - you can apply your filters to your existing inbox -- otherwise they only filter incoming mail, but not mail you already have.

Step One: Procmail

Before you dive into the world of mail filtering in UNIX, know that you will be required to use some Perl-like programming statements. If this bothers you, get over it or use some wimpy program like Eudora to do it for you. Procmail is preferable to Eudora-like programs because it acts on incoming messages as soon as they hit the server, not when Eudora happens to download messages.

1) create a ".procmail" directory from your home directory, type

mkdir .procmail

In this directory you will place a file. In this file will be the filtering instructions for procmail. An example of a few lines from the file are:

* ^TObsa-list

This sends all messages addressed to bsa-list to a file called "bsa-in."

An example filename for these instructions would be "rc.maillists" Click here to see a complete procmail instruction file to be placed in your .procmail directory. Feel free to use mine and modify it

More on procmail

In addition to creating the .procmail directory and placing the instruction file in it, you must edit the procmail configuration file in your home directory called ".procmailrc" by typing

pico .procmailrc

Feel free to view or downloadit. Here is what it looks like:

#Set on when debugging

#Replace "mail" with your mail directory

#Directory for storing procmail log and rc files


The '#' sign denotes a comment. Note the last line. If you name your instruction file something other than "rc.maillists", you must change the reference to it in the .procmailrc file.

Step Two: Pine

Ok, so you have set procmail to filter messages and put them in files in your mail directory (i.e. bsa-in, tech-in). The task is now to have Pine read these files into what it calls "incoming folders," thus creating more inboxes. Using my example rc.maillists file above (click here to view it again), you will see that messages are going to two files: tech-in and bsa-in. If you did not know, files in the mail folder are read as folders in Pine. So half the job is done. You have messages being filtered into folders, but not inboxes.

1) inside Pine

In Pine, you need to add regular folders with the same names as those listed in the rc.maillists file. So just add bsa-in and tech-in to your folder list.

2) .pinerc

The next thing to be done is to have Pine recognize these folders as inboxes. From your home directory, type:

pico .pinerc

You should scroll down to the incoming messages section which begins with "incoming-folders=" You need to add values after this first giving it the name of the inbox you want it to appear as, followed by the file in the mail folder that procmail sends messages to. See this portion of my .pinerc file to get the gist.

Warnings, Cautions


always backup your inbox file before applying procmail rules. you can do this by copying the ".inbox" file in your home directory to "inbox.bak" or some similarly appropriate name.