Procmail should be invoked automatically over the .forward file mechanism as soon as mail arrives. Alternatively, when installed by a system administrator (and in the standard Red Hat Linux configuration), it can be invoked from within the mailer immediately. When invoked, it first sets some environment variables to default values, reads the mail message from stdin until an EOF, separates the body from the header, and then, if no command line arguments are present, it starts to look for a file named $HOME/.procmailrc. According to the processing recipes in this file, the mail message that just arrived gets distributed into the right folder (and more). If no rcfile is found, or processing of the rcfile falls off the end, procmail will store the mail in the default system mailbox.
Examples:
:0: # Deliver to a file, let Procmail figure out how to lock it
* ^From scooby
scooby
:0 # Forwarding; no locking required
* ^TO_dogbert
! bofh@dilbert.com
:0:snoopy.lock # Explicitly name a file to use as a lock
* ^Subject:.*snoopy
| $HOME/bin/woodstock-enhancer.pl >>snoopy.mbox
Using formail:
:0c
* ^TO_sales@pizzazz\.tm\>
* ! ^X-Loop: sales@mundane\.domain\.net
| formail -k -X "From:" -X "Subject:" \
-I "To: sales@mundane.domain.net" -X "To:" \
-I "X-Loop: sales@mundane.domain.net" -X "X-Loop:" \
| $SENDMAIL $SENDMAILFLAGS -t
Grouping actions:
:0
* common-condition
{
:0fbw
* perhaps an additional condition on this one, even
| sed -e 's/definately/definitely/g' -e 's/seperate/separate/g'
:0c:
* perhaps an additional condition on this one, too
action1
:0
! action2
}
Environment:
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
}
Filed under: conf, tool Tagged: mail, nix, sysadmin
