1 { lib, pkgs, config, ... }:
3 sieve_bin = pkgs.runCommand "sieve_bin" {
4 buildInputs = [ pkgs.makeWrapper ];
6 cp -a ${./sieve_bin} $out
10 wrapProgram "$i" --prefix PATH : ${lib.makeBinPath [ pkgs.coreutils ]}
15 config = lib.mkIf config.myServices.mail.enable {
16 systemd.services.dovecot2.serviceConfig.Slice = "mail.slice";
17 services.duplyBackup.profiles.mail.excludeFile = ''
23 dest = "dovecot/ldap";
24 user = config.services.dovecot2.user;
25 group = config.services.dovecot2.group;
28 hosts = ${config.myEnv.mail.dovecot.ldap.host}
31 dn = ${config.myEnv.mail.dovecot.ldap.dn}
32 dnpass = ${config.myEnv.mail.dovecot.ldap.password}
38 base = ${config.myEnv.mail.dovecot.ldap.base}
41 pass_filter = ${config.myEnv.mail.dovecot.ldap.filter}
42 pass_attrs = ${config.myEnv.mail.dovecot.ldap.pass_attrs}
44 user_attrs = ${config.myEnv.mail.dovecot.ldap.user_attrs}
45 user_filter = ${config.myEnv.mail.dovecot.ldap.filter}
46 iterate_attrs = ${config.myEnv.mail.dovecot.ldap.iterate_attrs}
47 iterate_filter = ${config.myEnv.mail.dovecot.ldap.iterate_filter}
54 uid = config.ids.uids.vhost;
56 users.groups.vhost.gid = config.ids.gids.vhost;
58 # https://blog.zeninc.net/index.php?post/2018/04/01/Un-annuaire-pour-les-gouverner-tous.......
65 protocols = [ "sieve" ];
67 pkgs.dovecot_pigeonhole
68 pkgs.dovecot_fts-xapian
72 createMailUser = false;
74 Trash = { auto = "subscribe"; specialUse = "Trash"; };
75 Junk = { auto = "subscribe"; specialUse = "Junk"; };
76 Sent = { auto = "subscribe"; specialUse = "Sent"; };
77 Drafts = { auto = "subscribe"; specialUse = "Drafts"; };
79 mailLocation = "mbox:~/Mail:INBOX=~/Mail/Inbox:INDEX=~/.imap";
80 sslServerCert = "/var/lib/acme/mail/fullchain.pem";
81 sslServerKey = "/var/lib/acme/mail/key.pem";
82 sslCACert = "/var/lib/acme/mail/fullchain.pem";
83 extraConfig = builtins.concatStringsSep "\n" [
84 # For printer which doesn’t support elliptic curve
86 ssl_alt_cert = </var/lib/acme/mail-rsa/fullchain.pem
87 ssl_alt_key = </var/lib/acme/mail-rsa/key.pem
91 postmaster_address = postmaster@immae.eu
92 mail_attribute_dict = file:%h/dovecot-attributes
93 imap_idle_notify_interval = 20 mins
104 mail_plugins = $mail_plugins acl
106 acl = vfile:${pkgs.writeText "dovecot-acl" ''
109 acl_globals_only = yes
115 # needs to be bigger than any mailbox size
116 default_vsz_limit = 2GB
117 mail_plugins = $mail_plugins fts fts_xapian
119 plugin = fts fts_xapian
121 fts_xapian = partial=2 full=20
123 fts_autoindex_exclude = \Junk
124 fts_autoindex_exclude2 = \Trash
125 fts_autoindex_exclude3 = Virtual/*
130 # https://docs.iredmail.org/dovecot.imapsieve.html
132 # imap_sieve plugin added below
135 sieve_plugins = sieve_imapsieve sieve_extprograms
136 imapsieve_url = sieve://127.0.0.1:4190
138 sieve_before = file:${./sieve_scripts}/backup.sieve;bindir=/var/lib/vhost/.sieve_bin
140 # From elsewhere to Junk folder
141 imapsieve_mailbox1_name = Junk
142 imapsieve_mailbox1_causes = COPY APPEND
143 imapsieve_mailbox1_before = file:${./sieve_scripts}/report_spam.sieve;bindir=/var/lib/vhost/.imapsieve_bin
145 # From Junk folder to elsewhere
146 imapsieve_mailbox2_name = *
147 imapsieve_mailbox2_from = Junk
148 imapsieve_mailbox2_causes = COPY
149 imapsieve_mailbox2_before = file:${./sieve_scripts}/report_ham.sieve;bindir=/var/lib/vhost/.imapsieve_bin
151 # From anywhere to NoJunk folder
152 imapsieve_mailbox3_name = NoJunk
153 imapsieve_mailbox3_causes = COPY APPEND
154 imapsieve_mailbox3_before = file:${./sieve_scripts}/report_ham.sieve;bindir=/var/lib/vhost/.imapsieve_bin
156 sieve_pipe_bin_dir = ${sieve_bin}
158 sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.environment
166 inet_listener imaps {
172 inet_listener pop3s {
180 unix_listener auth-userdb {
182 unix_listener ${config.services.postfix.config.queue_directory}/private/auth {
186 service auth-worker {
193 unix_listener stats-reader {
198 unix_listener stats-writer {
208 first_valid_uid = ${toString config.ids.uids.vhost}
209 disable_plaintext_auth = yes
212 args = ${config.secrets.fullPaths."dovecot/ldap"}
216 args = ${config.secrets.fullPaths."dovecot/ldap"}
222 mail_plugins = $mail_plugins zlib
232 sieve = file:~/sieve;bindir=~/.sieve-bin;active=~/.dovecot.sieve
234 service managesieve-login {
236 service managesieve {
242 mail_plugins = $mail_plugins virtual
245 location = virtual:~/Virtual
249 # Protocol specific configuration
250 # Needs to come last if there are mail_plugins entries
253 mail_plugins = $mail_plugins imap_sieve imap_acl
256 mail_plugins = $mail_plugins sieve
261 networking.firewall.allowedTCPPorts = [ 110 143 993 995 4190 ];
262 system.activationScripts.dovecot = {
265 install -m 0755 -o vhost -g vhost -d /var/lib/vhost
269 services.cron.systemCronJobs = let
270 cron_script = pkgs.writeScriptBin "cleanup-imap-folders" ''
271 ${pkgs.dovecot}/bin/doveadm expunge -A MAILBOX "Backup/*" NOT FLAGGED BEFORE 8w 2>&1 > /dev/null | grep -v "Mailbox doesn't exist:" | grep -v "Info: Opening DB"
272 ${pkgs.dovecot}/bin/doveadm expunge -A MAILBOX Junk SEEN NOT FLAGGED BEFORE 4w 2>&1 > /dev/null | grep -v "Mailbox doesn't exist:" | grep -v "Info: Opening DB"
273 ${pkgs.dovecot}/bin/doveadm expunge -A MAILBOX Trash NOT FLAGGED BEFORE 4w 2>&1 > /dev/null | grep -v "Mailbox doesn't exist:" | grep -v "Info: Opening DB"
277 "0 2 * * * root ${cron_script}/bin/cleanup-imap-folders"
279 security.acme.certs."mail-rsa" = {
281 systemctl restart dovecot2.service
284 "imap.immae.eu" = null;
285 "pop3.immae.eu" = null;
288 security.acme.certs."mail" = {
290 systemctl restart dovecot2.service
293 "imap.immae.eu" = null;
294 "pop3.immae.eu" = null;