Debian, spamassasin amavis use Bayes and roundcube markasjunk2 / Antispam with Sieve

Discussion in 'Tips/Tricks/Mods' started by ztk.me, Jul 19, 2018.

  1. ztk.me

    ztk.me ISPConfig Developer ISPConfig Developer

    More or less a copy of https://docs.iredmail.org/store.spamassassin.bayes.in.sql.html
    It suggests creating a seperate user+database, which is fine but not key part of this howto today.

    note your ispconfig username/password when using the cat command on this code block
    Code:
    cd /tmp
    http://svn.apache.org/repos/asf/spamassassin/tags/spamassassin_release_3_4_1/sql/bayes_mysql.sql
    cat /etc/postfix/mysql-virtual_domains.cf
    mysql dbispconfig < bayes_mysql.sql
    
    edit /etc/mail/spamassassin/local.cf



    should work now
    todo: ispconfig integration using user prefs if enough interest because... rspamd will hit soon
     
    Last edited: Jul 20, 2018
  2. ztk.me

    ztk.me ISPConfig Developer ISPConfig Developer

    https://wiki2.dovecot.org/HowTo/AntispamWithSieve
    I assume you have incron like described in
    https://www.howtoforge.com/communit...l-port-8080-with-lets-encrypt-free-ssl.75554/

    Code:
    apt-get install dovecot-sieve
    cd /etc/dovecot
    mkdir sieve
    cd sieve
    
    create the following files within the new sieve directory

    report-ham.sieve
    Code:
    require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
    if environment :matches "imap.mailbox" "*" {
      set "mailbox" "${1}";
    }
    if string "${mailbox}" "Trash" {
      stop;
    }
    if environment :matches "imap.user" "*" {
      set "username" "${1}";
    }
    pipe :copy "sa-learn-ham.sh" [ "${username}" ];
    
    report-spam.sieve
    Code:
    require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
    if environment :matches "imap.user" "*" {
      set "username" "${1}";
    }
    pipe :copy "sa-learn-spam.sh" [ "${username}" ];
    
    sa-learn-ham.sh
    Code:
    #!/bin/sh
    # you can also use tcp/ip here, consult spamc(1)
    exec /usr/bin/sa-learn -u ${1} --ham
    #exec /usr/bin/spamc -u ${1} -L ham -C report
    
    sa-learn-spam.sh
    Code:
    #!/bin/sh
    # you can also use tcp/ip here, consult spamc(1)
    exec /usr/bin/sa-learn -u ${1} --spam
    #exec /usr/bin/spamc -u ${1} -L spam -C report
    
    Code:
    cd /etc/dovecot
    chgrp vmail -R
    
    update dovecot config with the following script, can be reused in case of rewritten config files

    /usr/local/bin/updatedovecotconf.sh
    Code:
    #!/bin/sh
    dovecot_conf=`cat /etc/dovecot/dovecot.conf`
    if [[ $dovecot_conf != *"imap_quota imap_sieve"* ]]; then
        sed -i 's/quota imap_quota/quota imap_quota imap_sieve/' /etc/dovecot/dovecot.conf
    cat <<EOT >> /etc/dovecot/dovecot.conf
    plugin {
      sieve_plugins = sieve_imapsieve sieve_extprograms
    
      sieve_global = /etc/dovecot/sieve
    
    
      # From elsewhere to Spam folder
      imapsieve_mailbox1_name = Junk
      imapsieve_mailbox1_causes = COPY
      imapsieve_mailbox1_before = file:/etc/dovecot/sieve/report-spam.sieve
    
      # From Spam folder to elsewhere
      imapsieve_mailbox2_name = *
      imapsieve_mailbox2_from = Junk
      imapsieve_mailbox2_causes = COPY
      imapsieve_mailbox2_before = file:/etc/dovecot/sieve/report-ham.sieve
    
      sieve_pipe_bin_dir = /etc/dovecot/sieve
    
      sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.environment
    }
    service incron restart
    fi
    EOT
    
    make it run on dovecot.conf changes
    Code:
    echo "/etc/dovecot/dovecot.conf IN_MODIFY /bin/bash /usr/local/bin/updatedovecotconf.sh" >> /var/spool/incron/root
    

    Everytime an IMAP user moves stuff to special purpose Junk folder or out of it, the database gets trained :)

    if you move high volumes, it would be better to use spamc/spamd ... but that's out of scope on this
     
    Last edited: Jul 20, 2018
  3. ztk.me

    ztk.me ISPConfig Developer ISPConfig Developer

    always
    Code:
    cd /var/lib/roundcube/plugins/markasjunk2
    cp config.inc.php.dist config.inc.php
    
    enable plugin in /etc/roundcube/config.inc.php by adding
    ,"markasjunk"

    if you do not use AntispamWithSieve

    edit /var/lib/roundcube/plugins/markasjunk2/config.inc.php
    Code:
    $config['markasjunk2_learning_driver'] = 'cmd_learn';
    $config['markasjunk2_spam_mbox'] = "Junk";
    $config['markasjunk2_move_spam'] = true;
    $config['markasjunk2_move_ham'] = true;
    $config['markasjunk2_spam_cmd'] = 'sa-learn --spam --username=vmail %f';
    $config['markasjunk2_ham_cmd'] = 'sa-learn --ham --username=vmail %f';
    
    if you do use AntispamWithSieve

    edit /var/lib/roundcube/plugins/markasjunk2/config.inc.php
    Code:
    $config['markasjunk2_learning_driver'] = null;
    $config['markasjunk2_spam_mbox'] = "Junk";
    $config['markasjunk2_move_spam'] = true;
    $config['markasjunk2_move_ham'] = true;
    $config['markasjunk2_spam_cmd'] = '';
    $config['markasjunk2_ham_cmd'] = ';
    
     
    Jesse Norell likes this.

Share This Page