Maildrop + Postfix

Our server runs Postfix as MTA: it’s a very powerful mail server, highly configurable, and extremely efficient when used in combination with amavis, spamassassin, mysql, cyrus-sasl and courier-imap.

Spamassassin is really THE indispensable tool in today’s internet environment, where about 80% of e-mails are spams!

Before using spamassassin, I simply couldn’t dissociate abusive e-mails from real ones (of course, words like viagra or pe*is elongation in the subject were clear hints 😉 ). Then, once spamassassin has been put in place (through the use of amavis), detected spams were marked with “***SPAM***” in the subject. It was then simply a matter of setting a rule in Thunderbird in order to get rid of those fu***in spam e-mails.

But still, a problem remains when using a webmail: spam e-mails were simply displayed in the Inbox folder, which really irritated me in the end. So I looked for a solution to automatically sort e-mail at reception time… That’s where maildrop appears!

Maildrop is normally delivered with the courier MTA, but as we are using Postfix, we had to emerge it:

# emerge maildrop -va

Some postfix adaptation is needed so that it uses maildrop to deliver the mail instead of the postfix/virtual process (when using virtual users of course). Add or adapt the following in /etc/postfix/main.cf

virtual_transport = maildrop
maildrop_destination_recipient_limit = 1
mailbox_command = /usr/bin/maildrop

Then make sure to have a line like the following in /etc/postfix/master.cf (of course, the user vmail has to exist on your system):

maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/bin/maildrop -w 90 -d ${user}@${nexthop} \
${user} ${nexthop} ${sender}

All mail users being stored in a database, simply replace the “virtual:” in the destination field of the transport table by “maildrop:” for the domains you want to serve using maildrop. The others will simply continue to perform as before.

The last thing to do is to create either a /etc/maildroprc or a ~/.mailfilter file (or both of course). The former defines rules to be applied to all accounts, while the latter does the same but only for the accounts that belongs to a specific user. Here is what such a file may look like to automatically move detected spam to a Spam folder (and create it if necessary):

`test -d $DEFAULT`
if( $RETURNCODE == 1 )
{
`/usr/bin/mkdir -p $DEFAULT`
`/usr/bin/rmdir $DEFAULT`
`/usr/bin/maildirmake $DEFAULT`
}
if ((/^X-Spam-Status: YES/))
{
`test -d $DEFAULT/.Spam`
if( $RETURNCODE == 1 )
{
`/usr/bin/maildirmake $DEFAULT/.Spam`
`echo "INBOX.Spam" >> $DEFAULT/courierimapsubscribed`
}
to "$DEFAULT/.Spam/"
}

Make sure the permission on that file is 600, and that the file is owned by that specific user.

Those steps have made the internet a better and safer place to live with 😉

Comments are closed.