Procmail recipes for mbox folders

A procmail recipe checks each message for the characteristic(s) that you specify and then disposes of the message accordingly.
Folder types
Before you tell procmail how to dispose of your email, you have to know where you want it to go, and that includes the type of folder you're using.

Folders that are accessible from webmail are in a format called Maildir++. (Yes, it's confusing. There's the procmail variable MAILDIR, there's the Maildir++ folder type, and there's your .maildir directory, or, more accurately, the symbolic link in your home directory to your mail on the server.)
The folders that you may have used with Elm, Mutt, Pine, and certain other Unix shell mail readers are in mbox format.

Each folder in mbox format is a single file. Messages are separated internally by the string "From " at the beginning of a line. Each Maildir++ folder is actually a directory, or, more accurately, a directory subtree. Each message is a separate file. You have to be careful to specify the right type of folder, and to make sure you get the path the way you want.


Recipes for mbox folders
If you have MAILDIR set to $HOME/mail, the following recipe will save any message with "Testing" in the Subject: line to $HOME/mail/testing:

:0:
* ^Subject:.*\<testing
testing

You will note that matching upper and lower case isn't important. This recipe will not match mail with "contesting" or "protesting" in the subject line because of the \<, which marks the beginning of a word boundary.

If you have MAILDIR set to $HOME/.maildir, you can still save mail to $HOME/mail/testing this way:
:0:
* ^Subject:.*\<testing
$HOME/mail/testing

Note that there is a colon after the zero on the first line of each of these recipes. That tells procmail to lock the folder so that it won't become corrupted if more than one message arrives at once.


Recipes for Maildir folders
If you have MAILDIR set to $HOME/.maildir, the following recipe will save any message with "Testing" in the Subject: line to a folder that shows up from webmail or IMAP as "testing":
:0
* ^Subject:.*\<testing
.testing/

Note that the folder name begins with a dot (which is necessary so that the folder is visible to the IMAP server) and ends with a slash (which is necessary to tell procmail that it's saving to the maildir++ format).

If you have MAILDIR set to $HOME/mail, you can still save mail to $HOME/.maildir/.testing this way:
:0
* ^Subject:.*\<testing
$HOME/.maildir/.testing/

Again, note that the foldername has to begin with a dot and end with a slash.

Note that there is no colon after the zero on the first line of each of these recipes. As each message is a distinct file, there is no need for a lock.

You will note that matching upper and lower case isn't important. This recipe will not match mail with "contesting" or "protesting" in the subject line because of the \<, which marks the beginning of a word boundary.


Additional Resources

Procmail is a very powerful program with a lot of features. The Panix help desk can provide support only for some basic features. The Panix user community includes a number of extremely knowledgable procmail users who are most generous with their expertise. You can generally find them in the panix.questions newsgroup.

Meantime, here is a list of resources to help you get familiar with procmail, from basic tutorial-level to advanced tricks.


The man pages.
Procmail has several useful man pages. Check out
man procmail
Technical details.
man procmailrc
How the procmailrc file works.
man procmailsc
Using Procmail's scoring
man procmailex
Examples - probably the most useful of all.
Mail Filtering with Procmail: A Tutorial
Ian Soboroff's (of Univ. of Maryland Baltimore County) excellent getting-started essay. Thanks to his clarity, and the fact that UMBC uses basically the same set of paths as Panix, we can find nothing of substance to add.
Timo's Tips
In FAQ format, lots of answers and yet more links to other useful material.
Procmail Quick Start
This page, copyright Nancy McGough & Infinite Ink, contains lots of details and many helpful links.
The Official Procmail Web Site
For the truly fascinated or obsessive Procmail devotee, here's where you can find more tutorials, mailing lists for Procmail discussion or general mail-filter theory, tips and tricks for creative Procmail recipe tweaking, release notes, feature request and bugfix lists, or even the latest source code to install Procmail on your Linux box at home.


Last Modified:Wednesday, 30-Jan-2013 12:14:10 EST
© Copyright 2006-2011 Public Access Networks Corporation