Currently I'm using Exim to deliver mails via dovecot-lda into Dovecot mailboxes. I'd like to add spam filtering, but I don't want to reject false-positives in Exim, and I want to train the bayesian filter from the client.

So: How do I configure a spamd such that spam lands in a Junk folder, and when the user finds spam in their Inbox, or ham in their Junk, they move it to the correct box which trains the spamd.

I have found dovecot-antispam but I'm not sure about its quality, it only seems to support dspam (and crm114, which is dead, last release August 2009).


You don't have to do anything special to spamd. I'm not terribly familiar with Exim's MDA, so hopefully someone can write an Answer specific to it. When your mail delivery agent runs, it should sent the e-mail through spamc -u $USERNAME (modify the variable as necessary). Then take a look at the headers. If "X-Spame-Status: Yes" exists, then deliver the mail to a sub-folder of the user's Maildir.

I use maildrop for my MDA. Configuration (in /usr/local/etc/maildroprc) is:

if ($LOGNAME ne "")
        xfilter "spamc -u $LOGNAME"
} else {
        xfilter "spamc -u $USER"

if ( /^X-Spam-Status: Yes/ )
        `test -d $DEFAULT/.Junk`
        if( $RETURNCODE == 1 )
                `maildirmake -f Junk $DEFAULT`
                to "$DEFAULT/.Junk"

As for the Bayesian learning, I wrote a script that cron calls every 20 minutes:

foreach cuser (`ls /home`)
        if ( -d $cuser/Maildir) then
                sa-learn --dbpath /home/$cuser/.spamassassin --spam /home/$cuser/Maildir/.Junk

And I follow that up with the following line to delete Junk that's older than 2 weeks. You don't need to clean it out, but most people never will by themselves:

find /usr/home/*/Maildir/.Junk/*/ -ctime +2w -type f -delete
  • Cool, I feared it would be less Unix-y. I just had to change my Exim pipe from command = dovecot-lda… to command = spamc -e dovecot-lda… and use Sieve in Dovecot to drop it into the correct box. – pascal Oct 4 '12 at 17:14
  • From the spamc man page: "Note that there is a very slight chance mail will be lost here, because if the fork-and-exec fails there's no place to put the mail message". You can avoid this problem by having Exim launch spamc instead; this is done with the transport_filter option on your transport. You may also want to use the --no-safe-fallback, so that Exim defers delivery, keeping the message on the queue for later, in the event that spamd can't process the message. – Sam Morris Aug 4 '13 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.