Procmail »
ICS uses Procmail as its mail processing utility. Procmail can be used to filter incoming mail for indivual users allowing them to create rule or conditions to process incoming mail, which is a feature available in most modern E-mail clients.
Contents
- Documentation
- Archiving Mail
- Procmail recipes are:
- Typical commands used in .maildelivery shown as recipes in a .procmailrc.
- Logging of Delivered Mail
- For delivering mail as MH format
- Testing your new .procmailrc recipes
Documentation:
Procmail is a module on the ICS Solaris systems. Man pages are titledprocmail, procemailrcandprocmailex(list of examples for processing mail). The man pages are a very good place to get information.
% module load procmail % man procmailex
Users should take time to convert their .maildelivery to a .procmailrc, because only a subset of the .maildelivery commands are currently supported by "slocal". We have included information below which may help in that process. Below are links to On-line resources including FAQ’s and some examples of procmail recipes for refile, forward, destroy and logging. Please contact helpdesk@ics.uci.edu if you need further assistance.Documentation available on the web:
http://www.procmail.org/ Procmail’s home page.
http://pm-doc.sourceforge.net/ Procmail Documentation ProjectInteresting and Useful Links
- a searchable archive of the procmail mailing list
- Era Eriksson's Procmail Mini-FAQ *** Examples below are from here…
- Peter Hartzler's SmartList FAQ
- Jari Aalto's Procmail resources
- Nancy McGough's Procmail Quick Start page at it's primary server or from a mirror.
- Timo Salmi's procmail tips and recipes *** Well done page
- Philip's TODO list
Archiving Mail
We recommend that you backup incoming mail when testing you new .procmailrc recipes with the following at the top of the .procmailrc file. Alternative testing method discuss below.
#backup of mail to a file called backup
:0c
backup
Procmail recipes are:
A line starting with ':' (colon) marks the beginning of a recipe. It has the following format:
:0 [flags] [ : [locallockfile] ]
<zero or more conditions (one per line)>
<exactly one action line>
Conditions start with a leading ' * ' (asterik), everything after that character is passed on to the internal egrep literally, except for leading and trailing whitespace. These regular expressions are completely compatible to the normal egrep(1) extended regular expressions. See also Extended regular expressions.
Conditions are anded; if there are no conditions the result will be true by default.
For Flags please see the procmailrc man page.
Comments
A word beginning with # and all the following characters up to a NEWLINE are ignored. This does not apply to condition lines, which cannot be commented.
Typical commands used in .maildelivery shown as recipes in a .procmailrc.
Refile:
#.maildelivery example
From scooby | A "/opt/local/lib/rcvmail/rcvstore +scooby"
#.procmailrc equivalent
:0: # Deliver to a file, let Procmail figure out how to lock it
* ^From.*scooby
scooby
Destroy:
#.maildelivery examples
From scooby destroy A
subject "{Possible Virus" destroy A
#.procmailrc equivalents
:0: # Deliver to a file, let Procmail figure out how to lock it
* ^From.*scooby
/dev/null
:0: # Deliver to a file, let Procmail figure out how to lock it
* ^X-MailScanner: Virus Found
/dev/null
More than one action on a message "clone" it with the :c flag.
# forward a copy to Don
:0c
! gillette@hedgehogs.com
# Then, we stash it in a folder
:0:
copied-to-don
Forward a message to many addresses?
In the simple case, just add more addresses to the action line:
:0
* ^Subject: result from cgi-bin/www-feedback$
! first@one.com second@two.net third@three.org
If you have a largish list of recipients, you might prefer to store the addresses in an external file you can edit without mucking with your Procmail filters:
# The file $MAILDIR/addresses.txt contains the recipients,
# one per line
:0
* ^Subject: result from cgi-bin/www-feedback$
! `cat addresses.txt`
# ^ Make sure those ^ are backticks, BTW (ASCII 96)
Logging of Delivered Mail
by editting you .procmailrc file and adding
LOGFILE=/path to file/mail.loga log will be created for each message delivered to the account and it will contain the `From ' and `Subject:' fields of the header, what folder it finally went to and how long (in bytes).
For delivering mail as MH format
This is a one-message-per-file format, where a directory forms the folder and the files in it are messages (the only exceptions are control and cache files used by certain MUAs). The file names are numbers (not necessarily in sequence), or numbers preceded by commas. The files with names starting with commas correspond to deleted messages.
Procmail can deliver to MH directories but doesn't know how to update the associated control and cache files. For that reason, some people prefer to pipe messages to the MH rcvstore program instead of delivering straight to an MH folder.
Used by the Rand MH system and derivatives.
#Example recipe
:0 :
* B ?? spam
| rcvstore +spamfold
Testing your new .procmailrc recipes
Here's an alternate rc file you can use as a skeleton for interactive experiments. It will tell Procmail to use a harmless subdirectory under the /tmp directory for all messages you feed it, instead of dumping messages amid your real mail (so you can safely run a bunch of contrived or dangerous tests and not screw up your inbox) display all log messages on standard error instead of in a log file give you a chance to play with advanced features of Procmail you'd never dare to try in your regular .procmailrc without testing them first :-) Do note that an interactive Procmail gets a different environment and possibly runs on a different machine than the Procmail in your .forward, though.
TMPDIR=/tmp/$USER
MAILDIR=$TMPDIR/procmail.out
DEFAULT=$MAILDIR/$USER
VERBOSE=yeah
SHELL=/bin/sh
:0
* ? test -d $TMPDIR || mkdir $TMPDIR
* ? test -d $MAILDIR || mkdir $MAILDIR
{ }
:0E
{
# Bail out if either directory didn't exist and couldn't be
# created
EXITCODE=127
HOST
}
# ... your experimental recipes here
With this recipe, you can use Procmail directly from the command line, typing in experimental messages as you go along, or feeding it a message on standard input, like this:
procmail -m experiments.rc <test.msg
(assuming you had saved the above example rc file in experiments.rc and have a test message for it in the file test.mbox). The -m option is rather vaguely documented; it will arrange with additional safety nets by disabling the default delivery and treating file names as relative to the current directory (as opposed to your home directory, which makes sense when invoking Procmail from a .forward or similar).
(Incidentally, testing Procmail from the command line like this is much more convenient than sending yourself a test message and waiting for Sendmail to deliver it to you. It also frees you from having to put diagnostic logging in your regular .procmailrc, or having to put verbose logging in your regular log file.