From b5bb12d0d2a8acf59c782b24d0c246cf7a3bb191 Mon Sep 17 00:00:00 2001 From: jmar71n Date: Sat, 20 Sep 2014 16:07:30 +0100 Subject: [PATCH 1/3] enable site-wide bayesian filtering Create directory in $STORAGE_ROOT for bayes database. Added --username arg to sa-learn as the user mail does not have permission to edit files in $STORAGE_ROOT. There is probably a better solution to this... --- setup/spamassassin.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/setup/spamassassin.sh b/setup/spamassassin.sh index bad777dd..72a538d8 100644 --- a/setup/spamassassin.sh +++ b/setup/spamassassin.sh @@ -35,7 +35,7 @@ sudo sed -i "s/#mail_plugins = .*/mail_plugins = \$mail_plugins antispam/" /etc/ # from http://wiki2.dovecot.org/Plugins/Antispam cat > /usr/bin/sa-learn-pipe.sh << EOF; cat<&0 >> /tmp/sendmail-msg-\$\$.txt -/usr/bin/sa-learn \$* /tmp/sendmail-msg-\$\$.txt > /dev/null +/usr/bin/sa-learn \$* /tmp/sendmail-msg-\$\$.txt --username user-data > /dev/null rm -f /tmp/sendmail-msg-\$\$.txt exit 0 EOF @@ -53,6 +53,15 @@ plugin { } EOF +# Configure spamassassin to use site-wide bayesian filtering +source /etc/mailinabox.conf # get global vars + +mkdir -p $STORAGE_ROOT/mail/spamassassin +chown -R mail:mail $STORAGE_ROOT/mail/spamassassin +chmod -R 775 $STORAGE_ROOT/mail/spamassassin + +tools/editconf.py /etc/spamassassin/local.cf -s bayes_path=$STORAGE_ROOT/mail/spamassassin/bayes + # Initial training? # sa-learn --ham storage/mail/mailboxes/*/*/cur/ # sa-learn --spam storage/mail/mailboxes/*/*/.Spam/cur/ From d06bfa6c1bc672ad97fdfeca17857942e81a9386 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Sat, 27 Sep 2014 16:16:15 +0000 Subject: [PATCH 2/3] tweak the site-wide bayesian spam filtering config --- setup/spamassassin.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) mode change 100644 => 100755 setup/spamassassin.sh diff --git a/setup/spamassassin.sh b/setup/spamassassin.sh old mode 100644 new mode 100755 index 72a538d8..a5c83266 --- a/setup/spamassassin.sh +++ b/setup/spamassassin.sh @@ -1,3 +1,4 @@ +#!/bin/bash # Spam filtering with spamassassin via spampd ############################################# @@ -9,6 +10,7 @@ # plugin. The tools/mail.py tool creates the necessary sieve script for each mail # user when the mail user is created. +source /etc/mailinabox.conf # get global vars source setup/functions.sh # load our functions # Install packages. @@ -35,7 +37,7 @@ sudo sed -i "s/#mail_plugins = .*/mail_plugins = \$mail_plugins antispam/" /etc/ # from http://wiki2.dovecot.org/Plugins/Antispam cat > /usr/bin/sa-learn-pipe.sh << EOF; cat<&0 >> /tmp/sendmail-msg-\$\$.txt -/usr/bin/sa-learn \$* /tmp/sendmail-msg-\$\$.txt --username user-data > /dev/null +/usr/bin/sa-learn \$* /tmp/sendmail-msg-\$\$.txt > /dev/null rm -f /tmp/sendmail-msg-\$\$.txt exit 0 EOF @@ -53,14 +55,14 @@ plugin { } EOF -# Configure spamassassin to use site-wide bayesian filtering -source /etc/mailinabox.conf # get global vars +# Tell spamassassin where to load and store site-wide bayesean filtering data. mkdir -p $STORAGE_ROOT/mail/spamassassin chown -R mail:mail $STORAGE_ROOT/mail/spamassassin chmod -R 775 $STORAGE_ROOT/mail/spamassassin -tools/editconf.py /etc/spamassassin/local.cf -s bayes_path=$STORAGE_ROOT/mail/spamassassin/bayes +tools/editconf.py /etc/spamassassin/local.cf -s \ + bayes_path=$STORAGE_ROOT/mail/spamassassin/bayes # Initial training? # sa-learn --ham storage/mail/mailboxes/*/*/cur/ From 6dd6353d4187f2e5768d4201774b57772514eea8 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Sat, 27 Sep 2014 16:06:11 +0000 Subject: [PATCH 3/3] move sa-learn-pipe.sh from /usr to /usr/local --- setup/spamassassin.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/setup/spamassassin.sh b/setup/spamassassin.sh index a5c83266..0545e198 100755 --- a/setup/spamassassin.sh +++ b/setup/spamassassin.sh @@ -35,13 +35,14 @@ sudo sed -i "s/#mail_plugins = .*/mail_plugins = \$mail_plugins antispam/" /etc/ # When mail is moved in or out of the Dovecot Spam folder, re-train using this script # that sends the mail to spamassassin. # from http://wiki2.dovecot.org/Plugins/Antispam -cat > /usr/bin/sa-learn-pipe.sh << EOF; +rm -f /usr/bin/sa-learn-pipe.sh # legacy location +cat > /usr/local/bin/sa-learn-pipe.sh << EOF; cat<&0 >> /tmp/sendmail-msg-\$\$.txt /usr/bin/sa-learn \$* /tmp/sendmail-msg-\$\$.txt > /dev/null rm -f /tmp/sendmail-msg-\$\$.txt exit 0 EOF -chmod a+x /usr/bin/sa-learn-pipe.sh +chmod a+x /usr/local/bin/sa-learn-pipe.sh # Configure the antispam plugin to call sa-learn-pipe.sh. cat > /etc/dovecot/conf.d/99-local-spampd.conf << EOF; @@ -49,8 +50,8 @@ plugin { antispam_backend = pipe antispam_spam_pattern_ignorecase = SPAM antispam_allow_append_to_spam = yes - antispam_pipe_program_spam_args = /usr/bin/sa-learn-pipe.sh;--spam - antispam_pipe_program_notspam_args = /usr/bin/sa-learn-pipe.sh;--ham + antispam_pipe_program_spam_args = /usr/local/bin/sa-learn-pipe.sh;--spam + antispam_pipe_program_notspam_args = /usr/local/bin/sa-learn-pipe.sh;--ham antispam_pipe_program = /bin/bash } EOF