1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2024-11-22 02:17:26 +00:00
mailinabox/scripts/spamassassin.sh

62 lines
2.4 KiB
Bash
Raw Normal View History

# Spam filtering with spamassassin via spampd
#############################################
2013-08-23 15:59:28 +00:00
# spampd sits between postfix and dovecot. It takes mail from postfix
# over the LMTP protocol, runs spamassassin on it, and then passes the
# message over LMTP to dovecot for local delivery.
# In order to move spam automatically into the Spam folder we use the dovecot sieve
# plugin. The tools/mail.py tool creates the necessary sieve script for each mail
# user when the mail user is created.
# Install packages.
2013-08-31 14:46:25 +00:00
apt-get -q -y install spampd dovecot-sieve dovecot-antispam
2013-08-23 15:59:28 +00:00
# Hook into postfix. Replace dovecot with spampd as the mail delivery agent.
tools/editconf.py /etc/postfix/main.cf virtual_transport=lmtp:[127.0.0.1]:10025
# Pass messages on to docevot on port 10026.
# This is actually the default setting but we don't want to lose track of it.
2013-08-23 15:59:28 +00:00
tools/editconf.py /etc/default/spampd DESTPORT=10026
# Enable the sieve plugin which let's us set a script that automatically moves
# spam into the user's Spam mail filter.
2013-08-23 15:59:28 +00:00
# (Note: Be careful if we want to use multiple plugins later.)
sudo sed -i "s/#mail_plugins = .*/mail_plugins = \$mail_plugins sieve/" /etc/dovecot/conf.d/20-lmtp.conf
# Enable the antispam plugin to detect when a message moves between folders so we can
# pass it to sa-learn for training. (Be careful if we use multiple plugins later.)
sudo sed -i "s/#mail_plugins = .*/mail_plugins = \$mail_plugins antispam/" /etc/dovecot/conf.d/20-imap.conf
# When mail is moved in or out of the dovecot Spam folder, re-train using this script
# that sends the mail to spamassassin.
2013-08-23 15:59:28 +00:00
# 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
rm -f /tmp/sendmail-msg-\$\$.txt
exit 0
EOF
chmod a+x /usr/bin/sa-learn-pipe.sh
# Configure the antispam plugin to call sa-learn-pipe.sh.
2013-08-23 15:59:28 +00:00
cat > /etc/dovecot/conf.d/99-local-spampd.conf << EOF;
plugin {
antispam_backend = pipe
antispam_spam_pattern_ignorecase = SPAM
antispam_allow_append_to_spam = yes
2013-08-31 23:45:08 +00:00
antispam_pipe_program_spam_args = /usr/bin/sa-learn-pipe.sh;--spam
antispam_pipe_program_notspam_args = /usr/bin/sa-learn-pipe.sh;--ham
2013-08-23 15:59:28 +00:00
antispam_pipe_program = /bin/bash
}
EOF
# Initial training?
# sa-learn --ham storage/mail/mailboxes/*/*/cur/
# sa-learn --spam storage/mail/mailboxes/*/*/.Spam/cur/
# Kick services.
2013-08-23 15:59:28 +00:00
sudo service spampd restart
sudo service dovecot restart