Simply put procmail is a mail delivery agent (MDA). It gets handed over complete messages from a mail transfer agent (MTA) and delivers those according to rules. Note the input usually comes from the MTA but can be a
another process, a
mailbox or maildir as well as
any other convoluted scheme. Also note "delivery" means stuffing messages in local mailboxes or maildirs but any preprocessing like handing it off to an
AV scanner, changing subject or driving arbitrary scripts is possible. Because procmail can see the whole message these rules (called "recipes") can act on
any aspect of a message including
headers that are invisible to the mail user agent (MUA), visible headers like the
sender,
lists of addresses,
recipient, subject and whatnot.
* In general experimenting can lead to
interesting results and mucking with mailspools and procmail isn't the exception. Working with copies of mailspools, delivering to test addresses and using test mailboxes makes sense. Also enable
debug settings.
Let's try delivering email messages from a copy mailspool to a local users test maildirs:
Code:
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin
SHELL=/bin/sh
# "VERBOSE=on" for debugging.
VERBOSE=on
# Default delivery option
DROPPRIVS=yes
# As much logging as possible
LOGABSTRACT=all
# Mailbox to deliver to if not filtered
DEFAULT=/var/TEST/procmail.mbx
# Logfile to read back in case of troubleshooting
LOGFILE=/var/TEST/procmail.log
# Deliver to MAILDIR (notice slash at end of path) for recipient "postmaster"
:0:
* ^To:.*postmaster
/var/TEST/spool/imap/postmaster/MAILDIR/
# Deliver to MAILDIR for recipient "Administrator" who can be in the
# "hostname.doma.in", "doma.in" or "localhost" domain:
:0:
* ^To:.*Administrator@(([-a-z0-9]+\.)*doma\.in|localhost)
/var/TEST/spool/imap/administrator/MAILDIR/
# =========================================================================
# Last rule: mailbox for unfiltered email
:0:
$DEFAULT
# ==========================================================================
# End of Recipes
How to use this. In /var/TEST/spool/ create "${USERNAME}/MAILDIR/" subdirectories for all usernames you want to test delivery with and set user access accordingly. Save above recipe as /var/TEST/procmail.rc and create a recipe for each user you created a test maildir for. Run ''cat /var/spool/mail/spoolfilename | formail -s | procmail -m /var/TEST/procmail.rc 2>&1 | tee /var/TEST/procmail.tee'. Read back /var/TEST/procmail.log in case of errors and check /var/TEST/procmail.mbx for undeliverables.