nixos-config/hosts/falkenstein/modules/mail/dovecot2.nix

124 lines
3.1 KiB
Nix
Raw Normal View History

2024-03-12 17:07:33 +01:00
{ config, pkgs, lib, ... }:
let
hostname = "mail.${config.networking.domain}";
in
{
networking.firewall.allowedTCPPorts = [
993
4190
];
services = {
dovecot2 = {
enable = true;
enableImap = true;
enableQuota = false;
enableLmtp = true;
2024-05-20 12:25:13 +02:00
mailLocation = "maildir:/var/mail/%n";
2024-05-23 15:44:49 +02:00
sslServerCert = "/var/lib/caddy/certificates/acme-v02.api.letsencrypt.org-directory/${hostname}/${hostname}.crt";
sslServerKey = "/var/lib/caddy/certificates/acme-v02.api.letsencrypt.org-directory/${hostname}/${hostname}.key";
2024-03-12 17:07:33 +01:00
protocols = [ "imap" "sieve" ];
mailPlugins = {
globally.enable = [ "listescape" ];
perProtocol = {
imap = {
enable = [ "imap_sieve" "imap_filter_sieve" ];
};
lmtp = {
enable = [ "sieve" ];
};
};
};
mailboxes = {
Spam = {
auto = "create";
specialUse = "Junk";
};
Sent = {
auto = "create";
specialUse = "Sent";
};
Drafts = {
auto = "create";
specialUse = "Drafts";
};
Trash = {
auto = "create";
specialUse = "Trash";
};
Archive = {
auto = "no";
specialUse = "Archive";
};
};
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 {
driver = passwd
args = blocking=no
}
service auth {
unix_listener /var/lib/postfix/auth {
group = postfix
mode = 0660
user = postfix
}
}
service managesieve-login {
inet_listener sieve {
port = 4190
}
service_count = 1
}
namespace inbox {
separator = /
inbox = yes
}
service lmtp {
unix_listener dovecot-lmtp {
group = postfix
mode = 0600
user = postfix
}
client_limit = 1
}
2024-05-20 12:25:13 +02:00
plugin {
sieve = file:/var/sieve/%u;active=/var/sieve/%u.sieve
}
2024-03-12 17:07:33 +01:00
'';
};
};
}