diff --git a/hosts/falkenstein-1/modules/mail/default.nix b/hosts/falkenstein-1/modules/mail/default.nix index 88d7cd4..0c245bf 100644 --- a/hosts/falkenstein-1/modules/mail/default.nix +++ b/hosts/falkenstein-1/modules/mail/default.nix @@ -41,6 +41,18 @@ in ''; mode = "0555"; }; + "dovecot/sieve/report-spam.sieve" = { + source = ./report-spam.sieve; + user = "dovecot2"; + group = "dovecot2"; + mode = "0544"; + }; + "dovecot/sieve/report-ham.sieve" = { + source = ./report-ham.sieve; + user = "dovecot2"; + group = "dovecot2"; + mode = "0544"; + }; }; services = { @@ -176,13 +188,14 @@ in # Spam: From elsewhere to Spam folder or flag changed in Spam folder imapsieve_mailbox1_name = Spam imapsieve_mailbox1_causes = COPY APPEND FLAG - imapsieve_mailbox1_before = file:/var/lib/dovecot/imap_sieve/report-spam.sieve + imapsieve_mailbox1_before = file:/etc/dovecot/sieve/report-spam.sieve - # Ham: From Spam folder to elsewhere + # From Junk folder to elsewhere imapsieve_mailbox2_name = * imapsieve_mailbox2_from = Spam imapsieve_mailbox2_causes = COPY - imapsieve_mailbox1_before = file:/var/lib/dovecot/imap_sieve/report-ham.sieve + imapsieve_mailbox2_before = file:/etc/dovecot/sieve/report-ham.sieve + } ''; }; diff --git a/hosts/falkenstein-1/modules/mail/report-ham.sieve b/hosts/falkenstein-1/modules/mail/report-ham.sieve new file mode 100644 index 0000000..a9d30cf --- /dev/null +++ b/hosts/falkenstein-1/modules/mail/report-ham.sieve @@ -0,0 +1,15 @@ +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}" ]; diff --git a/hosts/falkenstein-1/modules/mail/report-spam.sieve b/hosts/falkenstein-1/modules/mail/report-spam.sieve new file mode 100644 index 0000000..4024b7a --- /dev/null +++ b/hosts/falkenstein-1/modules/mail/report-spam.sieve @@ -0,0 +1,7 @@ +require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"]; + +if environment :matches "imap.user" "*" { + set "username" "${1}"; +} + +pipe :copy "sa-learn-spam.sh" [ "${username}" ]; \ No newline at end of file