Disclaimer don't get the wrong idea about what you've found here

What appears below are my personal notes I wish were part of my long-term memory but don't always seem to fit. I strive for accuracy and clarity and appreciate feedback. If applying any of this information anywhere, confirm for youself the correctness of your work as what you see below might very well be, albeit unintentionally, incorrect or misleading. These notes are here as an easy reference for myself.

Information worthy of a more formal presentation will appear elsewhere than this "Scratch" area. - ksb


KSB's procmail notes

Table of Contents

References

Overview

Once procmail is set up, when a piece of mail arrives for you, sendmail looks in your ~/.forward file and pipes the incoming mail to procmail (step 5), procmail reads your ~/.procmailrc file (step 3) to find your recipes file (step 2). The recipes file (based on the very strange syntax that is unique to procmail) tells procmail what to do with each piece of mail.

In this example there is only one rule which says: "place all mail with 'me@example.com' in any of the To or CC fields into a mail folder called 'memail'". Mail that doesn't match any rules in your recipes file 'falls through' and goes to your inbox.

You, of course, don't need to filter email in this way. I prefer it over having filter rules in the client as they live in just one place (on the server) and won't differ from client to client. None of this will work of course unless you are using IMAP and have access to your account on mail server's filesystem.

1) Create your ~/.pm/ dir

  $ mkdir ~/.pm/

This is the place where your recipes and log files will live.

2) Create your recipes file

Create a ~/.pm/recipes file with all your procmail recipes which are the instructions on what procmail should do with each incoming mail. This is the hard part as procmail has it's own language for defining recipes, here is a simple example:

:0:
* ^TO_me@example.com
memail

Procmail recipes can become far more complicated than this.

2) Create your ~/.procmailrc file

Make the following a ~/.procmailrc file:

#Replace `mail' with your mail directory (Pine uses mail, Elm uses Mail)
MAILDIR=$HOME/mail
DEFAULT=/var/mail/$LOGNAME

#Directory for storing procmail log and rc files
PMDIR=$HOME/.pm

LOGFILE=$PMDIR/log
INCLUDERC=$PMDIR/recipes

4) Create your mail folders

Create the mail folder 'memail' and get your mail reader know that it is a mail folder. You may want to get your mailers to check it new mail periodically. (In Mozilla I create a mail.check_all_imap_folders_for_new preference (in the about:config page) and set it to true) which will make Mozilla mail checkk all IMAP folder for new mail.

5) Create your ~/.forward file

Make the following your ~/.forward file:
"|procmail"

When using sendmail, you probably don't need to specify a path to procmail because sendmail will only use it's own 'safe' version of procmail anyway. I believe that it might be possible for sendmail to not even look at ~/.forward files and go simply with the existance of a ~/.procmailrc file for using procmail, so a ~/.forward may not even be necessary.

Using mailstat to read procmail log file

The mailstat command is used to read your procmail log file. The following command will list in a table the result of each rule in you recipes file and rotate your current ~/.pm/log file to ~/.pm/log.old:

  $ mailstat -l ~/.pm/log

Keith S. Beattie is responsible for this document, located at http://dst.lbl.gov/~ksb/Scratch/procmail.html, which is subject to LBNL's Privacy & Security Notice, Copyright Status and Disclaimers.

Last Modified: Monday, 25-Feb-2013 16:57:57 PST