Posts Tagged spam filtering

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
maildirmake=/usr/bin/maildirmake
mkdir=/bin/mkdir
rmdir=/bin/rmdir
MAILDIR=$DEFAULT

# 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
JUNK_FOLDER=.Junk
_JUNK_DEST=$MAILDIR/$JUNK_FOLDER/
`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/master.cf 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/main.cf 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.

, , ,

9 Comments