25.16 Procmail Recipes

REVIEW We now start specifying recipes to handle email. A recipe generally contains a pattern to identify the email messages to which the actions of the recipe are to be applied. Generally, the first recipe that matches an email will process that email and then terminate the procmail processing of that message. Carbon Copy all Email

For the especially cautious, or for when setting up procmail and testing it, you may want to keep a copy of every email that comes through. The first recipe might then be:

:0 c:
.incoming.`date +%Y.%m`/

All recipes are introduced with the :0. This can be followed by flags to control how the recipe works. The c flag above indicates that the email message is to be processed further by this specific recipe, but also a copy is to be pushed through to the remainder of the recipes within the .procmailrc file. The final : indicates that while procmail is processing the email message with this recipe, the recipe should be locked (so that no other procmail can write to the specified file at the same time).

After introducing the recipe with the :0 line, the next line in the above example is the action to be performed. In this case a file name is specified, beginning with a full stop and calling on the operating system to provide a current year and month string (e.g. 2006.01). Forwarding Email

We can specify exactly which emails we wish a recipe to apply to. We do this for a recipe which will forward email on to another user, as well as keeping a copy for ourselves:

:0 c
* ^From.*abc.com
! abcmail@togaware.com

Lines beginning with * allow us to identify email messages to which the recipe should apply. This example forwards any email from particular users (any email from anyone with an email address that has the string abc.com in it), onto another user (abcuser@togaware.com). You can have a comma separated list of email addresses on to which the email should be forwarded.

With this recipe the recipe introduction uses the c flag to pass the email message on to following recipes as a carbon copy. Also, there is no trailing colon, so we are not requesting a lockfile for this recipe—in this case we don’t need to use a lockfile because two instances of procmail will not interfere with each other when the action is to send the email on to someone else. Other Examples

A sample .procmailrc:

  * ^Resent-Sender.*debian-devel-request@lists.debian.org

  * ^Resent-Sender.*debian-user-request@lists.debian.org

The :0 begins a recipe. The following : ensures the mail file is locked. A line beginning with * begins a condition. You can have multiple conditions within a recipe. The condition ^Resent-Sender.*debian-devel-request@lists.debian.org captures email sent to the debian-devel mailing list. This matches messages that include Resent-Sender: debian-devel-request@lists.debian.org in their header. The final line of a recipe is the mailbox into which procmail will send the mail.

Your donation will support ongoing development and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0.