Posts Tagged maildrop

Postfix Maildrop Spam Folder

Filtering spam in Postfix is pretty simple.  There’s some advanced techniques you can use, but simply setting up Spamassassin will suit many people.  One downside is seeing all the ***** SPAM ***** mails in your inbox.  It took a while to come up with a solution, but the best fit so far has been implementing Maildrop to automatically move those files to a Junk folder.  Here’s the steps to set this up on a Debian 5.0 system with Postfix and Spamassassin.

First, setup your /etc/maildroprc file:

# commands and variables for making the mail directories

# make the user's mail directory if it doesn't exist
`test -e $MAILDIR`
if ($RETURNCODE != 0)
`$mkdir -p $MAILDIR`
`$rmdir $MAILDIR`
`$maildirmake $MAILDIR`

# make the .Junk folder if it doesn't exist
`test -d $_JUNK_DEST`
if ($RETURNCODE != 0 )
`$maildirmake $_JUNK_DEST`
#auto subscribe. the following works for courier-imap
`echo INBOX.Junk >> $MAILDIR/courierimapsubscribed`

# If the Spam-Flag is set, move the mail to the Junk folder
if (/^X-Spam-Flag:.*YES/)
exception {
to $DEFAULT/.Junk/

The comments clearly state what’s going on there.

Once that’s setup, you will go into your /etc/postfix/ and make sure the

maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}

is not commented out.

Next you will have to set the /usr/bin/maildrop file setuid root. This is so maildrop can interact with authdaemon and the mail folders.

#chmod +s /usr/bin/maildrop

Then you have to add this to your /etc/postfix/ file:

virtual_transport = maildrop
maildrop_destination_recipient_limit = 1

If there is another virtual_transport line, be sure to comment that out first.

Last, set the permissions on the authdaemon so that maildrop can access it.

chown vmail /var/run/courier/authdaemon

And that’s all. Nice and simple way to handle all that Junk mail.

, , ,