Training Spamassassin from within Apple Mail

Inspired by a blog post from Adrian Sutton and the comments beneath it I am now documenting how I train Spamassassin from within Apple Mail.
The setup is fairly straight forward but implies that you at least have a working Spamassassin instance running somewhere and know your way around UNIX a little bit. So I’m just going to explain the rough details to get you going.

  1. Switch on the bayes database for SA. On my Debian box this is done via putting the line use_bayes 1 in the file /etc/spamassassin/local.cf. After that restart SA (eg. /etc/init.d/spamassassin restart)
  2. Let SA put all your Junk Messages in the folder “Junk” in your IMAP Account
  3. Let Apple Mail put all your Junk Messages in the folger “Junk” in your IMAP Account
  4. Install a little Cronjob to have SA learn Spam from your Junk folder and Ham (=not Spam) from your Inbox. The following is my script:
    echo "----learn spam----"
    sa-learn --spam /var/opt/vmail/no-panic.at/flo/Maildir/.Junk/*
    echo "----learn ham----"
    sa-learn --ham /var/opt/vmail/no-panic.at/flo/Maildir/*

    Note: those are just 4 lines, the blog just wrapps the two ‘sa-learn’ lines because of limited horizontal space. Of course you have to change the path to the real location of your ‘Junk’ folder.
  5. Last thing to do is installing the cronjob. Mine looks like this:
    0 */4 * * * /path_to_your/script > /dev/null 2>&1

Actually my setup involves learning from 4 different user accounts, who all use Apple Mail just to get more Ham- & Spam-volume faster.
I hope this is helpfull to you. It works perfectly on my server for over a month now.

3 comments

  1. hi there…
    question about your script.
    won’t “sa-learn –ham /var/opt/vmail/no-panic.at/flo/Maildir/*” re-learn all your mail in .junk as ham?? .junk is a subfolder of Maildir and therefore will be treated as ham and not spam…correct?

  2. Hi,
    good question!
    I couldn’t find any information in the ‘sa-learn’ manpage if it runs recursively or not but considering your comment, an easy work-around would be just letting it learn ham first and then spam from the subfolder. This way we’d be on the safe side in any way.
    What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.