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 = ''