summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Eiche <lewo@abesis.fr>2021-07-23 22:57:39 +0200
committerlewo <lewo@abesis.fr>2021-08-06 16:21:03 +0000
commit72748d7b6d706ca17817389952a3a7d9185b0d5c (patch)
treea72cee9be8a0778b6c3b3b4b7806d4b09bf742d8
parent42db23553d433646398ca08e9c61071d01d3350f (diff)
Use the Junk mailbox name defined in the mailboxes attrsfix-junk
Previously, the static Junk mailbox was used in sieve script to move spam messages. This patch gets the Junk mailbox defined in the dovecot mailboxes attribute instead. Fixes #224
-rw-r--r--mail-server/dovecot.nix19
1 files changed, 16 insertions, 3 deletions
diff --git a/mail-server/dovecot.nix b/mail-server/dovecot.nix
index 3781bbd..bc947ae 100644
--- a/mail-server/dovecot.nix
+++ b/mail-server/dovecot.nix
@@ -85,9 +85,22 @@ let
chmod 600 ${passwdFile}
'';
+
+ junkMailboxes = builtins.attrNames (lib.filterAttrs (n: v: v ? "specialUse" && v.specialUse == "Junk") cfg.mailboxes);
+ junkMailboxNumber = builtins.length junkMailboxes;
+ # The assertion garantees there is exactly one Junk mailbox.
+ junkMailboxName = if junkMailboxNumber == 1 then builtins.elemAt junkMailboxes 0 else "";
+
in
{
config = with cfg; lib.mkIf enable {
+ assertions = [
+ {
+ assertion = junkMailboxNumber == 1;
+ message = "nixos-mailserver requires exactly one dovecot mailbox with the 'special use' flag set to 'Junk' (${builtins.toString junkMailboxNumber} have been found)";
+ }
+ ];
+
services.dovecot2 = {
enable = true;
enableImap = enableImap || enableImapSsl;
@@ -109,7 +122,7 @@ in
require "fileinto";
if header :is "X-Spam" "Yes" {
- fileinto "Junk";
+ fileinto "${junkMailboxName}";
stop;
}
'';
@@ -229,13 +242,13 @@ in
sieve_default_name = default
# From elsewhere to Spam folder
- imapsieve_mailbox1_name = Junk
+ imapsieve_mailbox1_name = ${junkMailboxName}
imapsieve_mailbox1_causes = COPY
imapsieve_mailbox1_before = file:${stateDir}/imap_sieve/report-spam.sieve
# From Spam folder to elsewhere
imapsieve_mailbox2_name = *
- imapsieve_mailbox2_from = Junk
+ imapsieve_mailbox2_from = ${junkMailboxName}
imapsieve_mailbox2_causes = COPY
imapsieve_mailbox2_before = file:${stateDir}/imap_sieve/report-ham.sieve