diff --git a/include/bin/spam-learn.sh b/include/bin/spam-learn.sh new file mode 100644 index 0000000..ef1346f --- /dev/null +++ b/include/bin/spam-learn.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +set -e + +POSTMASTER="${1}" + +# for testing script +#POSTMASTER=postmaster@example.org + +HAM_REPORT='' + +SPAM_REPORT='' + +for i in /srv/mail/* ; do + if [ -d "$i" ]; then + + HAM_REPORT=$(printf "$HAM_REPORT\n\nMailbox: $i\n $(sa-learn --ham --showdots --no-sync $i/mail/cur)\n") + + SPAM_REPORT=$(printf "$SPAM_REPORT\n\nMailbox: $i\n $(sa-learn --spam --showdots --no-sync $i/mail/Spam/cur)\n") + + fi +done + + +if [ "0$POST_MASTER_EMAIL" != "0" ]; then + +cat << EOF | /usr/lib/dovecot/dovecot-lda -d "${POST_MASTER_EMAIL}" -o "plugin/quota=maildir:User quota:noenforcing" +Auto-Submitted: auto-generated +Date: $(date +'%a, %-d %b %Y %H:%M:%S %z') +To: ${POST_MASTER_EMAIL} +From: Mail Server +Subject: Spam Learning Report $(date +%Y-%m-%d-%H:%M-%Z) + +Command: /bin/spam-learn.sh + + +****************** Ham Scan ****************** +$HAM_REPORT + + + +****************** Spam Scan ****************** + +$SPAM_REPORT + +EOF + +fi diff --git a/include/etc/cron.d/sa-learn b/include/etc/cron.d/sa-learn new file mode 100644 index 0000000..8f181ec --- /dev/null +++ b/include/etc/cron.d/sa-learn @@ -0,0 +1,6 @@ +# +# SpamAssassin Bayes learning from mailboxes +# +# m h dom mon dow user command +30 0,3,6,9,12,15,18,21 * * * root /bin/spam-learn.sh 2>&1 +