Dovecot Antispam-Plugin


With the Antispam plugin from Dovecot, new spam mails can be pushed by hand into their own IMAP folder.
Mails that are moved to this folder, spamassassin learns as spam mails. If a mail is moved from this folder (for example to the INBOX because it is not spam), spamassassin learns that it is HAM (good mail). I am using a separate SPAM folder and not the IMAP folder Junk, where spam mails can be moved through ISPConfig.

Since the learning of spam always affects all users, you should be careful, even if other mailboxes are hosted on the server. Then it is recommended to use a separate folder (for example, SPAM).

I use Debian Jessie with ISPConfig 3.1.2:

Install the plugin using apt-get:
apt-get install dovecot-antispam

Configure the plugin in /etc/dovecot/dovecot.conf:

1. extend mail_plugins

    mail_plugins = notify replication quota antispam

2. Depending on the version of ISPConfig, protocol imap must be adusted:

    protocol imap {

      mail_plugins = imap_quota antispam

    }

3. Configure the plugin:

    plugin {

      antispam_verbose_debug = 0
      antispam_backend = pipe
      antispam_spam = SPAM
      antispam_pipe_program_spam_arg = –spam
      antispam_pipe_program_notspam_arg = –ham
      antispam_pipe_program = /usr/bin/sa-learn-pipe.sh

    }

4. Create /usr/bin/sa-learn-pipe.sh:

    #!/bin/bash
    pid=$$
    {
    echo “$(date) ${pid}-start ($*) /tmp/sendmail-msg-$$.txt”
    # set -x
    # id -a
    # env
    # cat > /tmp/sendmail-msg-${pid}.txt
    /usr/bin/sa-learn “$@” /tmp/sendmail-msg-${pid}.txt
    echo “$(date) $$-end rc=$?”
    } >/tmp/antispam.${pid}.log 2>&1
    cat /tmp/antispam.${pid}.log >>/tmp/sa-learn-pipe.log
    rm -f /tmp/antispam.${pid}.log /tmp/sendmail-msg-${pid}.txt
    true
    exit 0

and set the permissions:

    chmod 755 /usr/bin/sa-learn-pipe.sh
    chown vmail.vmail /usr/bin/sa-learn-pipe.sh

5. optional: Define namespace in /etc/dovecot/dovecot.conf:

    namespace inbox {

      inbox = yes
      mailbox SPAM {

        auto = subscribe # autocreate Spam and autosubscribe

      }

    }

    Or use the folder explicitly for junk:

    namespace inbox {

      inbox = yes
      mailbox SPAM {

        auto = subscribe # autocreate Spam and autosubscribe
        special_use = \Junk

      }

    }

6. restart Dovecot

To subscribe the folder to all IMAP accounts, you can use doveadm:
doveadm mailbox subscribe -A SPAM

Leave a comment

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

I confirm