Getting SpamAssassin, MailDrop, VPopmail and qmail to play friendly

November 20th, 2002

Once upon a time, I posted a message to the vchkpw mailing list, asking about mail filtering and vpopmail. At the time, I was trying to get procmail to work, because in a previous life, I'd used it with some success to filter spam.

As you can read in the message above, it's a fiddly thing to do. Making your own spam-filtering rules all the time is a pain too. What I ended up using was a combination of maildrop, SpamAssassin and a patch for vpopmail. Since I've had a surprising number of people mail me and ask what I did to solve the problem, here is an extended version of my now-stock reply.

Please bear in mind that this solution was cobbled together from pieces of other people's solutions, and (most importantly) YOUR MILEAGE MAY VARY. This may delete all your mail. It doesn't do that for me.


I now use Maildrop, qmail, vpopmail and SpamAssassin on my own box with some success.

It allows me to have per-user mail filtering (aside from Spam - procmail-style stuff), and control which domains have spam-filtering too. The only missing thing is a per-user preference for SA, although I think that might be doable.

You'll need the 'seekable' patch for vpopmail, and a little extra config. In the following, I have vpopmail installed in /var/qmail/vpopmail...

You can get the seekable patch for recent vpopmail versions from thesafebox.com. According to them, version 5.37 and above already have the patch applied - those are development-only versions currently.

This setup works for me using SpamAssassin 2.20 and 2.43. If you just want filtering, but you like spam, then the mailfilter file can be changed pretty easily to accomodate your perversion.

First, do a standard install of vpopmail (with the seekable patch applied), qmail, maildrop etc, and verify it works as expected. Do the SpamAssassin install too (which doesn't actually set it up to work, just install the software).

For domains that you want to filter, make the .qmail-default in ~vpopmail/domains/bozo.com contain:

| maildrop mailfilter
create a file called 'mailfilter' in the same directory, containing:
VPOP="| /var/qmail/vpopmail/bin/vdelivermail '' bounce-no-mailbox"
VHOME=`/var/qmail/vpopmail/bin/vuserinfo -d $EXT@$HOST`

if ( $SIZE < 262144 )
{
exception {
	xfilter "/usr/local/bin/spamc -f -u $EXT@$HOST"
}
}

if (/^X-Spam-Flag: *YES/)
{
# try filtering it using user-defined rules
exception {
	include $VHOME/Maildir/.mailfilter
}
# then try delivering it to a Spam folder
exception {
	# to "$VPOP"
	to "$VHOME/Maildir/.Spam/"
}
# ah well, I guess they'll just have to live with disappointment
exception {
	to "$VPOP"
}
}
else
{
exception {
	include $VHOME/Maildir/.mailfilter
}
exception {
	to "$VPOP"
}
}
(you may need to change the path for SpamAssassin's spamc in this)

What this does is pass any 'small' mails through SpamAssassin, which may add extra headers if it believes the mail is spam. If the header does contain those flags, after spamc has taken a look then it will pass it through the user's own mail filter rules (in the user's Maildir), then try and deliver it to a Maildir folder called .Spam if it is still undelivered, and finally just dump it into their mailbox. This gives a good degree of flexibility. I use IMAP4, so putting it it a .Spam Maildir means I don't download it at all, but can still see it in my client (sqwebmail would work the same way, too).

If the mail isn't spammish, then it just gets delivered, passing through the user's mailfilter rules, if any.

This seems pretty good to me, and hasn't lost any mails to date that I'm aware of, nor blocked any non-spam.I get the spam filtering I wanted, and still get to have procmail-like rules if I want them - I found that without spam-filtering, I didn't have too many rules - just a few mailing list filing things.


Copyright 1994-2005, by Howard Jones. howie@thingy.com