Show Table of Contents
188.8.131.52. Recipe Examples
Procmail is an extremely flexible program, but as a result of this flexibility, composing Procmail recipes from scratch can be difficult for new users.
The best way to develop the skills to build Procmail recipe conditions stems from a strong understanding of regular expressions combined with looking at many examples built by others. A thorough explanation of regular expressions is beyond the scope of this section. The structure of Procmail recipes and useful sample Procmail recipes can be found at various places on the Internet (such as http://www.iki.fi/era/procmail/links.html). The proper use and adaptation of regular expressions can be derived by viewing these recipe examples. In addition, introductory information about basic regular expression rules can be found in the
The following simple examples demonstrate the basic structure of Procmail recipes and can provide the foundation for more intricate constructions.
A basic recipe may not even contain conditions, as is illustrated in the following example:
The first line specifies that a local lockfile is to be created but does not specify a name, so Procmail uses the destination file name and appends the value specified in the
LOCKEXTenvironment variable. No condition is specified, so every message matches this recipe and is placed in the single spool file called
new-mail.spool, located within the directory specified by the
MAILDIRenvironment variable. An MUA can then view messages in this file.
A basic recipe, such as this, can be placed at the end of all
rcfiles to direct messages to a default location.
The following example matched messages from a specific email address and throws them away.
:0 * ^From: email@example.com /dev/null
With this example, any messages sent by
firstname.lastname@example.org sent to the
/dev/nulldevice, deleting them.
Be certain that rules are working as intended before sending messages to
/dev/nullfor permanent deletion. If a recipe inadvertently catches unintended messages, and those messages disappear, it becomes difficult to troubleshoot the rule.
A better solution is to point the recipe's action to a special mailbox, which can be checked from time to time to look for false positives. Once satisfied that no messages are accidentally being matched, delete the mailbox and direct the action to send the messages to
The following recipe grabs email sent from a particular mailing list and places it in a specified folder.
:0: * ^(From|CC|To).*tux-lug tuxlug
Any messages sent from the
email@example.com list are placed in the
tuxlugmailbox automatically for the MUA. Note that the condition in this example matches the message if it has the mailing list's email address on the
Consult the many Procmail online resources available in Section 27.7, “Additional Resources” for more detailed and powerful recipes.