Home > Unix > Per virtual user sa-learn training

Per virtual user sa-learn training

December 17th, 2008 Leave a comment Go to comments


I use a LDA that use Virtual User, and store email in /some/path/mail/<domaine.tld>/<user>/, this is a quite standard way to do.
I also use spamassassin but wanted to have a per user bayes database and configuration. It’s still simple with spamc/spamd by running spamd -c --virtual-config-dir=/some/path/to/spamassassin/%d/%l ... and invoking spamc from you MTA with spamc -u ${recipient} -f -e /path/to/your/LDA so that i have user preference in /some/path/saconf/<domaine.tld>/<user>/.
Now I would like to provide 2 imap folder to users, LearnSpam and LearnHam so that they could train their bayes database.
Here the problem start, especially if you are not using one of the latest spamassassin version.

The bad way

What sa-learn command will you run to take care of LearnSpam and LearnHam folders ? sa-lean has an –username option, you may want to use that but this is not intended to be use in this case, it’s to be used when bayes database are stored in an SQL database instead of file (this is correctly documented in latest SA version). So don’t try sa-learn --username=<user>@<domaine.tld> --spam /some/path/mail/<domaine.tld>/<user>/.INBOX.LearnSpam/cur/* it will not work. Imagine how this can work ? it can’t, how sa-learn could convert <user>@<domaine.tld> to /some/path/saconf/<domaine.tld>/<user>/ ?

The good way

So the right command to use is sa-learn -p /some/path/saconf/<domaine.tld>/<user>/user_prefs --spam /some/path/mail/<domaine.tld>/<user>/.INBOX.LearnSpam/cur/* Using the -D (debug) option could be very helpfull to check if it’s work correctly, you must see dbg: bayes: tie-ing to DB file R/O /some/path/saconf/<domaine.tld>/<user>/bayes_toks

Categories: Unix Tags:
  1. February 3rd, 2010 at 06:31 | #1

    Just an addendum as this behavior might be new since 2008, not sure but now spamd requires an additional parameter –nouser-config otherwise it simply ignores the –virtual-config-dir arg.

    Had me scratching my head for a good hour.

  2. Jeb
    February 3rd, 2010 at 07:54 | #2

    @Aaron Tate
    That’s strange, still working as describe for me.

  3. Andrew
    April 2nd, 2012 at 14:09 | #3


    Please, specify full command line options for spamd.
    I got this errors:

    Apr 2 08:54:10 imap1 spamd[26905]: plugin: eval failed: bayes: (in learn) locker: safe_lock: cannot create tmp lockfile /var/lib/spamassassin/ox/%d/%u/bayes.lock.imap1.ox.nctest.net.26905 for /var/lib/spamassassin/%d/%u/bayes.lock: No such file or directory

    My spamd options –

    SPAMDOPTIONS=” -u dovecot -d -c -m5 -H –nouser-config –allow-tell –cf=’bayes_path /var/lib/spamassassin/%d/%u/bayes’ -A

  1. No trackbacks yet.