#!/bin/bash # SpamAssassin Setup Spam to Junk folder. Should be called after the main SpamAssassin install part completes or mapped to an optional button to install. Personally think this should be a default part of the SpamAssassin installation. echo 'backup configs'; cp /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf-bak_$(date '+%Y-%m-%d_%H_%M:%S'); cp /etc/postfix/master.cf /etc/postfix/master.cf-bak_$(date '+%Y-%m-%d_%H_%M:%S'); cp /etc/postfix/main.cf /etc/postfix/main.cf-bak_$(date '+%Y-%m-%d_%H_%M:%S'); cp /etc/dovecot/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext-bak_$(date '+%Y-%m-%d_%H_%M:%S') echo 'Setting up spamassassin and sieve to deliver spam to Junk folder by default' echo 'Fix protocols' sed -i 's/^protocols =.*/protocols = imap pop3 lmtp sieve/g' /etc/dovecot/dovecot.conf sed -i "s|^user_query.*|user_query = SELECT '5000' as uid, '5000' as gid, '/home/vmail/%d/%n' as home,mail FROM e_users WHERE email='%u';|g" /etc/dovecot/dovecot-sql.conf.ext if [ "$OS" = "NAME=\"Ubuntu\"" ];then if [ "$UBUNTUVERSION" = "VERSION_ID=\"18.04\"" ];then apt-get install -y dovecot-managesieved dovecot-sieve dovecot-lmtpd net-tools pflogsumm elif [ "$UBUNTUVERSION" = "VERSION_ID=\"20.04\"" ];then apt-get install -y libmysqlclient-dev sed -e '/deb/ s/^#*/#/' -i /etc/apt/sources.list.d/dovecot.list apt install -y dovecot-lmtpd dovecot-managesieved dovecot-sieve net-tools pflogsumm fi elif [ "$CENTOSVERSION" = "VERSION_ID=\"7\"" ];then yum install -y nano net-tools dovecot-pigeonhole postfix-perl-scripts elif [ "$CENTOSVERSION" = "VERSION_ID=\"8\"" ];then rpm -Uvh http://mirror.ghettoforge.net/distributions/gf/el/8/gf/x86_64/gf-release-8-11.gf.el8.noarch.rpm dnf --enablerepo=gf-plus upgrade -y dovecot23* dnf --enablerepo=gf-plus install -y dovecot23-pigeonhole dnf install -y net-tools postfix-perl-scripts elif [ "$CLNVERSION" = "ID=\"cloudlinux\"" ];then yum install -y nano net-tools dovecot-pigeonhole postfix-perl-scripts fi # Create Sieve files mkdir -p /etc/dovecot/sieve/global touch /var/log/{dovecot-lda-errors.log,dovecot-lda.log} touch /var/log/{dovecot-sieve-errors.log,dovecot-sieve.log} touch /var/log/{dovecot-lmtp-errors.log,dovecot-lmtp.log} touch /etc/dovecot/sieve/default.sieve chown vmail: -R /etc/dovecot/sieve chown vmail:mail /var/log/dovecot-* echo 'Create Sieve Default spam to Junk rule' cat >> /etc/dovecot/sieve/default.sieve <> /etc/dovecot/dovecot.conf <