From 82aa8774d9d7392d82f8d4d15c4bb5910e6493e7 Mon Sep 17 00:00:00 2001 From: Rouven Seifert Date: Sun, 11 Feb 2024 19:57:42 +0100 Subject: [PATCH] mail: use nix native sieve options --- hosts/falkenstein/modules/mail/default.nix | 77 ++++++++----------- .../falkenstein/modules/mail/report-ham.sieve | 2 +- .../modules/mail/report-spam.sieve | 2 +- 3 files changed, 33 insertions(+), 48 deletions(-) diff --git a/hosts/falkenstein/modules/mail/default.nix b/hosts/falkenstein/modules/mail/default.nix index 54302df..dcbcb4e 100644 --- a/hosts/falkenstein/modules/mail/default.nix +++ b/hosts/falkenstein/modules/mail/default.nix @@ -1,4 +1,4 @@ -{ config, pkgs, ... }: +{ config, pkgs, lib, ... }: let domain = config.networking.domain; @@ -28,34 +28,6 @@ in description = "Rouven Seifert"; isNormalUser = true; }; - environment.etc = { - "dovecot/sieve-pipe/sa-learn-spam.sh" = { - text = '' - #!/bin/sh - ${pkgs.rspamd}/bin/rspamc learn_spam - ''; - mode = "0555"; - }; - "dovecot/sieve-pipe/sa-learn-ham.sh" = { - text = '' - #!/bin/sh - ${pkgs.rspamd}/bin/rspamc learn_ham - ''; - 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 = { postfix = { @@ -153,6 +125,36 @@ in modules = [ pkgs.dovecot_pigeonhole ]; + sieve = { + # just pot something in here to prevent empty strings + extensions = [ "notify" ]; + # globalExtensions = [ "+vnd.dovecot.pipe" ]; + pipeBins = map lib.getExe [ + (pkgs.writeShellScriptBin "learn-ham.sh" "exec ${pkgs.rspamd}/bin/rspamc learn_ham") + (pkgs.writeShellScriptBin "learn-spam.sh" "exec ${pkgs.rspamd}/bin/rspamc learn_spam") + ]; + plugins = [ + "sieve_imapsieve" + "sieve_extprograms" + ]; + }; + imapsieve.mailbox = [ + { + # Spam: From elsewhere to Spam folder or flag changed in Spam folder + name = "Spam"; + causes = [ "COPY" "APPEND" "FLAG" ]; + before = ./report-spam.sieve; + + } + { + # From Junk folder to elsewhere + name = "*"; + from = "Spam"; + causes = [ "COPY" ]; + before = ./report-ham.sieve; + } + ]; + extraConfig = '' auth_username_format = %Ln userdb { @@ -185,23 +187,6 @@ in } client_limit = 1 } - plugin { - sieve_plugins = sieve_imapsieve sieve_extprograms - sieve_global_extensions = +vnd.dovecot.pipe - sieve_pipe_bin_dir = /etc/dovecot/sieve-pipe - - # 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:/etc/dovecot/sieve/report-spam.sieve - - # From Junk folder to elsewhere - imapsieve_mailbox2_name = * - imapsieve_mailbox2_from = Spam - imapsieve_mailbox2_causes = COPY - imapsieve_mailbox2_before = file:/etc/dovecot/sieve/report-ham.sieve - - } ''; }; diff --git a/hosts/falkenstein/modules/mail/report-ham.sieve b/hosts/falkenstein/modules/mail/report-ham.sieve index a9d30cf..6217a90 100644 --- a/hosts/falkenstein/modules/mail/report-ham.sieve +++ b/hosts/falkenstein/modules/mail/report-ham.sieve @@ -12,4 +12,4 @@ if environment :matches "imap.user" "*" { set "username" "${1}"; } -pipe :copy "sa-learn-ham.sh" [ "${username}" ]; +pipe :copy "learn-ham.sh" [ "${username}" ]; diff --git a/hosts/falkenstein/modules/mail/report-spam.sieve b/hosts/falkenstein/modules/mail/report-spam.sieve index 4024b7a..9d4c74b 100644 --- a/hosts/falkenstein/modules/mail/report-spam.sieve +++ b/hosts/falkenstein/modules/mail/report-spam.sieve @@ -4,4 +4,4 @@ if environment :matches "imap.user" "*" { set "username" "${1}"; } -pipe :copy "sa-learn-spam.sh" [ "${username}" ]; \ No newline at end of file +pipe :copy "learn-spam.sh" [ "${username}" ];