From fca6acab5c01ce5e507603c8b639bf21089154a9 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Mon, 6 Mar 2017 17:53:33 +0100 Subject: [PATCH] Spam learning by moving to/from junkmail --- .../etc/dovecot/dovecot.conf/70pluginImapSieve | 52 ++++++++++++++++++++++ root/usr/libexec/dovecot/learn-ham.sh | 1 + root/usr/libexec/dovecot/learn-spam.sh | 1 + root/usr/libexec/dovecot/sieve/report-ham.sieve | 8 ++++ root/usr/libexec/dovecot/sieve/report-spam.sieve | 2 + 5 files changed, 64 insertions(+) create mode 100644 root/etc/e-smith/templates/etc/dovecot/dovecot.conf/70pluginImapSieve create mode 100644 root/usr/libexec/dovecot/learn-ham.sh create mode 100644 root/usr/libexec/dovecot/learn-spam.sh create mode 100644 root/usr/libexec/dovecot/sieve/report-ham.sieve create mode 100644 root/usr/libexec/dovecot/sieve/report-spam.sieve diff --git a/root/etc/e-smith/templates/etc/dovecot/dovecot.conf/70pluginImapSieve b/root/etc/e-smith/templates/etc/dovecot/dovecot.conf/70pluginImapSieve new file mode 100644 index 0000000..ea30834 --- /dev/null +++ b/root/etc/e-smith/templates/etc/dovecot/dovecot.conf/70pluginImapSieve @@ -0,0 +1,52 @@ +{ +# If we have imap_sieve plugin, enable it +if (( -e '/usr/lib64/dovecot/lib95_imap_sieve_plugin.so' || -e '/usr/lib/dovecot/lib95_imap_sieve_plugin.so') && + ($spamassassin{'UseBayes'} || 'disabled') =~ m/^1|on|yes|enabled$/){ + push @imap_plugins, 'imap_sieve'; + my $index = 1; + $OUT.= <<'_EOF'; + +plugin { + sieve_plugins = sieve_imapsieve sieve_extprograms + sieve_execute_bin_dir = /usr/libexec/dovecot + sieve_pipe_bin_dir = /usr/libexec/dovecot + sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.execute + +_EOF + + if (($dovecot{'LearnSpam'} || 'enabled') =~ m/^1|on|yes|enabled$/){ + $OUT.= <<"_EOF"; + # Copy from anywhere to junkmail + imapsieve_mailbox$index\_name = junkmail + imapsieve_mailbox$index\_causes = COPY + imapsieve_mailbox$index\_before = file:/usr/libexec/dovecot/sieve/report-spam.sieve +_EOF + $index++; + $OUT.= <<"_EOF"; + imapsieve_mailbox$index\_name = Junk + imapsieve_mailbox$index\_causes = COPY + imapsieve_mailbox$index\_before = file:/usr/libexec/dovecot/sieve/report-spam.sieve +_EOF + $index++; + } + if (($dovecot{'LearnHam'} || 'enabled') =~ m/^1|on|yes|enabled$/){ + $OUT.= <<"_EOF"; + # Copy from junkmail to anywhere + imapsieve_mailbox$index\_name = * + imapsieve_mailbox$index\_from = junkmail + imapsieve_mailbox$index\_causes = COPY + imapsieve_mailbox$index\_before = file:/usr/libexec/dovecot/sieve/report-ham.sieve +_EOF + $index++; + $OUT.= <<"_EOF"; + imapsieve_mailbox$index\_name = * + imapsieve_mailbox$index\_from = Junk + imapsieve_mailbox$index\_causes = COPY + imapsieve_mailbox$index\_before = file:/usr/libexec/dovecot/sieve/report-ham.sieve +_EOF + $index++; + } + + $OUT .= '}'; +} +} diff --git a/root/usr/libexec/dovecot/learn-ham.sh b/root/usr/libexec/dovecot/learn-ham.sh new file mode 100644 index 0000000..4c2f75b --- /dev/null +++ b/root/usr/libexec/dovecot/learn-ham.sh @@ -0,0 +1 @@ +exec /usr/bin/spamc -L ham diff --git a/root/usr/libexec/dovecot/learn-spam.sh b/root/usr/libexec/dovecot/learn-spam.sh new file mode 100644 index 0000000..21f3370 --- /dev/null +++ b/root/usr/libexec/dovecot/learn-spam.sh @@ -0,0 +1 @@ +exec /usr/bin/spamc -L spam diff --git a/root/usr/libexec/dovecot/sieve/report-ham.sieve b/root/usr/libexec/dovecot/sieve/report-ham.sieve new file mode 100644 index 0000000..0fc1747 --- /dev/null +++ b/root/usr/libexec/dovecot/sieve/report-ham.sieve @@ -0,0 +1,8 @@ +require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"]; +if environment :matches "imap.mailbox" "*" { + set "mailbox" "${1}"; +} +if string "${mailbox}" "Trash" { + stop; +} +pipe :copy "learn-ham.sh"; diff --git a/root/usr/libexec/dovecot/sieve/report-spam.sieve b/root/usr/libexec/dovecot/sieve/report-spam.sieve new file mode 100644 index 0000000..80d3da5 --- /dev/null +++ b/root/usr/libexec/dovecot/sieve/report-spam.sieve @@ -0,0 +1,2 @@ +require ["vnd.dovecot.pipe", "copy"]; +pipe :copy "learn-spam.sh";