diff --git a/dovecot/20-imap.conf b/dovecot/20-imap.conf new file mode 100644 index 0000000..2a87e7b --- /dev/null +++ b/dovecot/20-imap.conf @@ -0,0 +1,3 @@ +protocol imap { + mail_plugins = $mail_plugins imap_sieve +} \ No newline at end of file diff --git a/dovecot/90-plugin.conf b/dovecot/90-plugin.conf new file mode 100644 index 0000000..d5e5dc8 --- /dev/null +++ b/dovecot/90-plugin.conf @@ -0,0 +1,18 @@ +plugin { + sieve_plugins = sieve_imapsieve sieve_extprograms + + # From elsewhere to Spam folder or flag changed in Spam folder + imapsieve_mailbox1_name = Junk + imapsieve_mailbox1_causes = COPY FLAG + imapsieve_mailbox1_before = file:/usr/local/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:/usr/local/etc/dovecot/sieve/report-ham.sieve + + sieve_pipe_bin_dir = /private/bin + + sieve_global_extensions = +vnd.dovecot.pipe +} \ No newline at end of file diff --git a/dovecot/report-ham.sieve b/dovecot/report-ham.sieve new file mode 100644 index 0000000..fff1e1c --- /dev/null +++ b/dovecot/report-ham.sieve @@ -0,0 +1,11 @@ +require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"]; + +if environment :matches "imap.mailbox" "*" { + set "mailbox" "${1}"; +} + +if string "${mailbox}" [ "Trash", "train_ham", "train_prob", "train_spam" ] { + stop; +} + +pipe :copy "sa-learn-ham.sh"; \ No newline at end of file diff --git a/dovecot/report-spam.sieve b/dovecot/report-spam.sieve new file mode 100644 index 0000000..885d375 --- /dev/null +++ b/dovecot/report-spam.sieve @@ -0,0 +1,13 @@ +require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "imap4flags"]; + +if environment :is "imap.cause" "COPY" { + pipe :copy "sa-learn-spam.sh"; +} + +# Catch replied or forwarded spam +elsif anyof (allof (hasflag "\\Answered", + environment :contains "imap.changedflags" "\\Answered"), + allof (hasflag "$Forwarded", + environment :contains "imap.changedflags" "$Forwarded")) { + pipe :copy "sa-learn-spam.sh"; +} \ No newline at end of file