Archive:Docs/Drafts/AdministrationGuide/Servers/MailServer/Procmail

From FedoraProject

Jump to: navigation, search

Once the email is accepted by an MTA (eg sendmail) and identified as deliverable to local mailbox the message is passed to MDA (by default - procmail) which is responsible for appending it to users' mailboxes.

there are two types of mailboxes: mbox - the old school, saves all messages in one file (it is Fedora default). there are some opinions that mbox works poorer with larger mailboxes.

maildir - every message is saved in individual file. there is an opinion that maildir works slower when accessed through IMAP protocols.

Systemwide config file for procmail is /etc/procmailrc (might need to create one, if missing). On default one doesn't have to do anything for procmail to do its job. However two typical causes of custom procmail configuration are:

  • use of Spamassassin : Spamassassin needs to be called by procmail, for that following needs to be included in procmailrc:
:0 fw
* < 128000
| /usr/bin/spamc

above instructs procmail to divert all messages less then 128kb to Spamassassin for spam identification. You might want to include larger or smaller size criteria depending on strength of your box and intensity of spam. usually spammers avoid larger messages and Spamassassin being perl-based is somewhat of resource hog.

Spamassassin only identifies email as spam, it is procmail again that needs to handle the spam-identified message according to messaging rules as discussed in next section.

  • custom messaging rules. The advantage of using procmail for message processing is that any rule is executed at the server, not client. for instance
:0:
* ^X-Spam-Status: Yes
$HOME/mail/Junk

:0:
* ^From.*annoy\.com
$HOME/mail/Junk

we have two separate messaging rules in above.

first checks whether message contains earmark from Spamassassin. If positive, instead of default (delivery to your Inbox) the message in delivered in separate folder - Junk.

second rule checks if email has been From: certain domain, in which case it is also diverted to Junk folder instead of default Inbox.

singe messaging rule consists of: first line :0: instructs procmail to pass message to a certain test and listen back to result. next line specifies the test, regular expressions can be used here. finally the third line describes the action if the test positive, often you indicate the delivery destination to a separate folder.

bring above options together and you get typical File:Docs Drafts AdministrationGuide Servers MailServer Procmail procmailrc .

if one prefers to have maildir format instead of mbox, procmailrc can do that:

DEFAULT=$HOME/Maildir/
MAILDIR=$HOME/Maildir/

above will cause procmail to deliver to user's home folder in maildir format. by default delivery is to individual mbox format in /var/spool/mail

in general procmail automatically creates any folders it needs for delivery if one doesn't exist.

finally beyond systemwide procmailrc config every user can define individual rules, which need to be placed into ~/.procmailrc file. Individual files have exactly the same syntax as systemwide file above. again, any rule will be executed by mailserver (that is by procmail, while delivering email), before the client. there is some overlap between .procmailrc and .forward files for some rules can equally validly be included in both.