From 35920eda0c085eb59af3ad9592d9099e9feb5ba8 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Mon, 22 Jul 2024 18:54:23 +0100 Subject: [PATCH 1/3] feat: this should put an automatic bcc on outgoing mail as well as a corrosponding filter to put it in teh right inboxes Relates to #84 --- applications/email.nix | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/applications/email.nix b/applications/email.nix index 8b74703..e47a7ae 100644 --- a/applications/email.nix +++ b/applications/email.nix @@ -114,6 +114,21 @@ with lib; let stop; } else { fileinto :create "''${1}"; + stop; + } + } + } + if allof ( + address :localpart ["From"] ["${toString create_config_to}"], + address :domain ["From"] "skynet.ie" + ){ + if address :matches ["From"] "*@skynet.ie" { + if header :is "X-Spam" "Yes" { + fileinto :create "''${1}.Junk"; + stop; + } else { + fileinto :create "''${1}"; + stop; } } } @@ -465,6 +480,39 @@ in { before = configFile; }; + # This is to add a bcc to outgoing mail + # this then interacts with teh filters to put it in the right folder + # we can directly add to the postfix service here + services.postfix = let + # mostly copied from the upstream mailserver config/functions + mappedFile = name: "hash:/var/lib/postfix/conf/${name}"; + + sender_bcc_maps_file = let + content = lookupTableToString create_skynet_service_bcc; + in + builtins.toFile "sender_bcc_maps" content; + + lookupTableToString = attrs: let + valueToString = value: lib.concatStringsSep ", " value; + in + lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value: "${name} ${valueToString value}") attrs); + + # convert the mailboxes config to something that can be used here + create_skynet_email_bcc = mailbox: { + name = "${mailbox}@skynet.ie"; + value = ["${mailbox}@skynet.ie"]; + }; + create_skynet_service_bcc = builtins.listToAttrs (map (mailbox: (create_skynet_email_bcc mailbox.account)) service_mailboxes); + in { + mapFiles."sender_bcc_maps" = sender_bcc_maps_file; + + config = { + sender_bcc_maps = [ + (mappedFile "sender_bcc_maps") + ]; + }; + }; + # tune the spam filter /* services.rspamd.extraConfig = '' -- 2.46.1 From 9c7d08c153f7960ee3643cc3d95ce4166015ca9d Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Mon, 22 Jul 2024 18:57:31 +0100 Subject: [PATCH 2/3] fix: slight bit of formatting and a renaming Closes #84 --- applications/email.nix | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/applications/email.nix b/applications/email.nix index e47a7ae..bd03f77 100644 --- a/applications/email.nix +++ b/applications/email.nix @@ -92,7 +92,7 @@ with lib; let } ]; - configFile = + sieveConfigFile = # https://doc.dovecot.org/configuration_manual/sieve/examples/#plus-addressed-mail-filtering pkgs.writeText "basic_sieve" '' @@ -105,32 +105,32 @@ with lib; let # this should be close to teh last step if allof ( - address :localpart ["To"] ["${toString create_config_to}"], - address :domain ["To"] "skynet.ie" - ){ - if address :matches ["To"] "*@skynet.ie" { - if header :is "X-Spam" "Yes" { - fileinto :create "''${1}.Junk"; - stop; - } else { - fileinto :create "''${1}"; - stop; - } + address :localpart ["To"] ["${toString create_config_to}"], + address :domain ["To"] "skynet.ie" + ){ + if address :matches ["To"] "*@skynet.ie" { + if header :is "X-Spam" "Yes" { + fileinto :create "''${1}.Junk"; + stop; + } else { + fileinto :create "''${1}"; + stop; } + } } if allof ( - address :localpart ["From"] ["${toString create_config_to}"], - address :domain ["From"] "skynet.ie" - ){ - if address :matches ["From"] "*@skynet.ie" { - if header :is "X-Spam" "Yes" { - fileinto :create "''${1}.Junk"; - stop; - } else { - fileinto :create "''${1}"; - stop; - } + address :localpart ["From"] ["${toString create_config_to}"], + address :domain ["From"] "skynet.ie" + ){ + if address :matches ["From"] "*@skynet.ie" { + if header :is "X-Spam" "Yes" { + fileinto :create "''${1}.Junk"; + stop; + } else { + fileinto :create "''${1}"; + stop; } + } } ''; in { @@ -477,7 +477,7 @@ in { }; services.dovecot2.sieve.scripts = { - before = configFile; + before = sieveConfigFile; }; # This is to add a bcc to outgoing mail -- 2.46.1 From 4f87e56d639f467a55e1a044bcde4641de8c13d0 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Wed, 24 Jul 2024 20:47:58 +0100 Subject: [PATCH 3/3] fix: include cc's for incoming mail --- applications/email.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/applications/email.nix b/applications/email.nix index bd03f77..003580b 100644 --- a/applications/email.nix +++ b/applications/email.nix @@ -105,10 +105,10 @@ with lib; let # this should be close to teh last step if allof ( - address :localpart ["To"] ["${toString create_config_to}"], - address :domain ["To"] "skynet.ie" + address :localpart ["To", "Cc"] ["${toString create_config_to}"], + address :domain ["To", "Cc"] "skynet.ie" ){ - if address :matches ["To"] "*@skynet.ie" { + if address :matches ["To", "Cc"] "*@skynet.ie" { if header :is "X-Spam" "Yes" { fileinto :create "''${1}.Junk"; stop; -- 2.46.1