Which bayes db will be used?

Hi there,

we use UCS / Kopano with the hole spamassassin/amavis system.
Also installed is the kopano-spamd deamon, which does nothing else to export mails to the spam folder!?
And this spam folder should be read from sa-learn - so far so good.

But the spam / ham learning appears to not working.

“sa-learn” is then running via cron as root and therfore there was created the directory /root/.spamassassin with “bayes_seen” and “bayes_toks” files.
For Info: the kopano User has no home dir configured in /etc/passwd (kopano:x:998:998:Kopano Groupware Suite:/dev/null:/sbin/nologin), so i cant run sa-learn as user kopano.

So my question is:

  1. How does kopano-spamd read the “junk mail folder” of all users?
  2. How does kopano-spamd detect false positive mails?
  3. Is my configuration correct (run sa-learn from cron as root)

Jan

Hi @Jan,

  1. and 2. can be answered with the documentation https://documentation.kopano.io/kopanocore_administrator_manual/special_kc_configurations.html#configuring-kopano-spamd-for-automatic-spam-ham-learning

I cannot say anything about 3, though as I am not familiar how Amavis works in UCS. But there is a wrapper for it named /usr/sbin/univention-sa-learn I would imagine that it is preferable to use over the raw sa-learn.

The integration package for Kopano is also open source and the source code is available at https://stash.z-hub.io/projects/K4U/repos/kopano4ucs/browse, I’m sure that some people will be happy if you want to contribute your changes once you’ve got it running.

Hello Mr. Bartels,

thx for your quick answer. The relevant part of /usr/sbin/univention-sa-learn is that:

SA_LEARN="/usr/bin/sa-learn"

if [ ! -f /var/lib/amavis/.spamassassin/bayes_toks ]; then
	touch /var/lib/amavis/.spamassassin/bayes_toks
	chown amavis:amavis /var/lib/amavis/.spamassassin/bayes_toks
	chmod 600 /var/lib/amavis/.spamassassin/bayes_toks
fi

# learing from spam folder Spam
# learing from ham folder Ham

find /var/spool/dovecot/private/ \( -wholename \*/\*/Maildir/.Spam \) \
	-exec $SA_LEARN --dbpath /var/lib/amavis/.spamassassin --spam {} \;

find /var/spool/dovecot/private/ -wholename \*/\*/Maildir/.Ham \
	-exec $SA_LEARN --dbpath /var/lib/amavis/.spamassassin --ham {} \;

It looks like that this is not working with kopano. And changing this file is not neccessary because it will be overwritten in future updates.
But here you can see, that this script is using /var/lib/amavis/.spamassassin/bayes_toks as datebase files.
Should i symlink my root/.spamassassin/ files to /var/lib/amavis/.spamassassin

Jan

I would rather recommend to write an own wrapper, like the following (untested):

#!/bin/bash
SA_LEARN="/usr/bin/sa-learn"

if [ ! -f /var/lib/amavis/.spamassassin/bayes_toks ]; then
	touch /var/lib/amavis/.spamassassin/bayes_toks
	chown amavis:amavis /var/lib/amavis/.spamassassin/bayes_toks
	chmod 600 /var/lib/amavis/.spamassassin/bayes_toks
fi

# learing from spam folder Spam
# learing from ham folder Ham

find /var/lib/kopano/spamd/spam \
	-exec $SA_LEARN --dbpath /var/lib/amavis/.spamassassin --spam {} \;

find /var/lib/kopano/spamd/ham \
	-exec $SA_LEARN --dbpath /var/lib/amavis/.spamassassin --ham {} \;

Although I am not sure about running that as root.

I use the script for spamd.cfg and inotify-spamlearn.cfg

#!/bin/bash

SA_LEARN=$(type -p sa-learn)

if [ ! -f /var/lib/amavis/.spamassassin/bayes_toks ]; then
    touch /var/lib/amavis/.spamassassin/bayes_toks
    chown amavis:amavis /var/lib/amavis/.spamassassin/bayes_toks
    chmod 600 /var/lib/amavis/.spamassassin/bayes_toks
fi

# learing from spam folder Spam
# learing from ham folder Ham
dospam(){
    echo -n "spam:" |tee -a /tmp/jnspam.log
    find /var/lib/kopano/spamd/spam \
        -exec sudo -u amavis $SA_LEARN --dbpath /var/lib/amavis/.spamassassin --spam {} \; |tee -a /tmp/jnspam.log
}
doham(){
    echo -n " ham:" |tee -a /tmp/jnspam.log
    find /var/lib/kopano/spamd/ham \
        -exec sudo -u amavis $SA_LEARN --dbpath /var/lib/amavis/.spamassassin --ham {} \; |tee -a /tmp/jnspam.log
}

case $1 in
    spam|s)
        dospam
    ;;
    ham|h)
        doham
    ;;
    *)
        echo "you can also start with parameters [spam|ham]"
        dospam
        doham
    ;;
esac

but nothing is written to my tmp log. At this point i am wondering about log information in /var/log/kopano/spamd.log because the logging in /etc/kopano/spamd.cfg was disabled. I had change now the log level to 6 and enabled logging. After restart the service i see this:

2018-10-25 15:54:54,943 - spamd - INFO - cannot open config file %s running with defaults 2018-10-25 15:54:54,943 - spamd - INFO - starting spamd

and after a while

2018-10-25 15:55:05,008 - spamd - ERROR - Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/kopano/log.py", line 89, in log_exc try: yield File "/usr/lib/python2.7/dist-packages/kopano/service.py", line 181, in start _daemonize(self.main, options=self.options, log=self.log, config=self.config, service=self) File "/usr/lib/python2.7/dist-packages/kopano/service.py", line 112, in _daemonize stderr=sys.stderr, File "/usr/lib/python2.7/dist-packages/kopano/daemon/daemon.py", line 352, in __enter__ self.open() File "/usr/lib/python2.7/dist-packages/kopano/daemon/daemon.py", line 344, in open self.pidfile.__enter__() File "/usr/lib/python2.7/dist-packages/kopano/lockfile.py", line 228, in __enter__ self.acquire() File "/usr/lib/python2.7/dist-packages/kopano/daemon/pidlockfile.py", line 109, in acquire super(TimeoutPIDLockFile, self).acquire(timeout, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/kopano/daemon/pidlockfile.py", line 59, in acquire super(PIDLockFile, self).acquire(*args, **kwargs) File "/usr/lib/python2.7/dist-packages/kopano/lockfile.py", line 266, in acquire raise LockTimeout LockTimeout
What ist with the first Part “cannot open config file %s” and with the second one, after a spam, mail arrives the system?

And second: kopano-spamd has a “learncmdspam” and “learncmdham” option. So for what do i need “inotify-spamlearn” like described in https://documentation.kopano.io/kopanocore_administrator_manual/special_kc_configurations.html#configuring-kopano-spamd-for-automatic-spam-ham-learning

Jan

If you want to use the linked inotify-spamd script then you don’t need your wrapper and can simply add --dbpath /var/lib/amavis/.spamassassin in https://github.com/bkram/inotify-spamlearn/blob/master/inotify-spamlearn.cfg#L9 and https://github.com/bkram/inotify-spamlearn/blob/master/inotify-spamlearn.cfg#L11

would need to do some more test with that and don’t have the time at the moment. If you have a subscription I would recommend to open up a case with our support.

OK, i have open a support ticket for the last part of the kopano problem.
But you haven’t answer the question, for what do i need both?

And second: kopano-spamd has a “learncmdspam” and “learncmdham” option. So for what do i need “inotify-spamlearn” like described in[https://documentation.kopano.io/kopanocore_administrator_manual/special_kc_configurations.html#configuring-kopano-spamd-for-automatic-spam-ham-learning ](https://documentation.kopano.io/kopanocore_administrator_manual/special_kc_configurations.html#configuring-kopano-spamd-for-automatic-spam-ham-learning)

This has likely nothing to do with the wrapper script.

Jan

there are no such options in the configuration: https://stash.kopano.io/projects/KC/repos/kopanocore/browse/installer/linux/spamd.cfg

Im wondering about your statement, because it was the default file from with this options:

cat spamd.cfg 
##############################################################
# SPAMD SERVICE SETTINGS

# run as specific user
#run_as_user         = kopano

# run as specific group
#run_as_group        = kopano

# control pid file
pid_file            =   /var/run/kopano/spamd.pid

# run server in this path (when not using the -F switch)
#running_path = /var/lib/kopano

##############################################################
# LOG SETTINGS

# Logging method (syslog, file)
log_method          =   file

# Loglevel (0(none), 1(crit), 2(err), 3(warn), 4(notice), 5(info), 6(debug))
#log_level           =   3

# Logfile for log_method = file, use '-' for stderr
log_file            =   /var/log/kopano/spamd.log

# Log timestamp - prefix each log line with timestamp in 'file' logging mode
log_timestamp       =   1

###############################################################
# SPAMD Specific settings

learncmdspam = /usr/bin/sudo -u amavis /usr/bin/sa-learn --spam
learncmdham = /usr/bin/sudo -u amavis /usr/bin/sa-learn --ham
spamfolder = LearnSpam
hamfolder = LearnHam

So take this as a bug report and change the option in the default (debian) repros.
OK… so i remove this options from the config file an awaiting the response from the support Ticket.

Jan

It seems you are confusing the bundled spamd with https://kb.kopano.io/display/WIKI/Kopano-spamd. the latter indeed has this option.

Hi,

omg … so… i dont need /etc/kopano/spamd.cfg if i use the repro package kopano-spamd?

Jan

only if you want to override one of the defaults (like a different log location)

Mastodon