Procmail Recipes - intro

A procmail recipe is a rule (or set of rules) that 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, especially if you opened your account before 2005, 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 path and the right folder type.

This page is not intended as a comprehensive guide to procmail, but only as a quick and dirty overlook at some of the things you should consider.

Here is an example, with explanation, of a very simple procmail recipe.

:0Recipe start. Flags, if any, come after the 0. You may also have a colon.
* ^From:.* Conditions, one per line; each beginning with an asterisk.
$DEFAULT Disposition of the message

All recipes start :0.
Each condition starts with an asterisk. Conditions are ANDed.
The disposition of the message can be the name of the folder to which it should be saved or something that should be done to it.
The recipe above just saves any message that includes a header line that begins From: and then includes staff@panix.comsomewhere in that line. (Note that, as written, the condition matches and (both, to my knowledge, hypothetical).)

You can add conditions, but remember that if you add conditions within a single recipe you are ANDing them: All of the conditions must be met for the recipe to match. The easiest (but not the best) way to OR conditions is to make a separate recipe for each.

The "disposition" is what happens if all of the conditions of the recipe are satisfied. If you want to forward mail to another address, the disposition line would look like this

Procmail recipes for Maildir (IMAP/POP) folders

If you want to save all (or most) of your mail to messages you can access via IMAP (including webmail), you should set the procmail variable maildir to $HOME/.maildir/. Any folder (other than your inbox) needs to have a name that begins with a dot and ends with a slash (/). For example:

* ^From.*postmaster

Procmail recipes for mbox folders

If you want to save messages to folders in your home directory space in mbox format, you should specify the subdirectory you want (usually "mail" or "Mail") and be sure notto put a slash after the foldername:

* ^From.*postmaster

You may notice that there is a colon at the end of the first line of this recipe. The colon locks the folder while mail is being delivered.

Procmail index

Last Modified:Thursday, 21-Apr-2022 11:05:53 EDT
© Copyright 2006-2021 Public Access Networks Corporation