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 services.duplyBackup.profiles.mail.excludeFile = ''
22 dest = "dovecot/ldap";
23 user = config.services.dovecot2.user;
24 group = config.services.dovecot2.group;
27 hosts = ${config.myEnv.mail.dovecot.ldap.host}
30 dn = ${config.myEnv.mail.dovecot.ldap.dn}
31 dnpass = ${config.myEnv.mail.dovecot.ldap.password}
37 base = ${config.myEnv.mail.dovecot.ldap.base}
40 pass_filter = ${config.myEnv.mail.dovecot.ldap.filter}
41 pass_attrs = ${config.myEnv.mail.dovecot.ldap.pass_attrs}
43 user_attrs = ${config.myEnv.mail.dovecot.ldap.user_attrs}
44 user_filter = ${config.myEnv.mail.dovecot.ldap.filter}
45 iterate_attrs = ${config.myEnv.mail.dovecot.ldap.iterate_attrs}
46 iterate_filter = ${config.myEnv.mail.dovecot.ldap.iterate_filter}
53 uid = config.ids.uids.vhost;
55 users.groups.vhost.gid = config.ids.gids.vhost;
57 # https://blog.zeninc.net/index.php?post/2018/04/01/Un-annuaire-pour-les-gouverner-tous.......
64 protocols = [ "sieve" ];
66 pkgs.dovecot_pigeonhole
67 pkgs.dovecot_fts-xapian
71 createMailUser = false;
73 { name = "Trash"; auto = "subscribe"; specialUse = "Trash"; }
74 { name = "Junk"; auto = "subscribe"; specialUse = "Junk"; }
75 { name = "Sent"; auto = "subscribe"; specialUse = "Sent"; }
76 { name = "Drafts"; auto = "subscribe"; specialUse = "Drafts"; }
78 mailLocation = "mbox:~/Mail:INBOX=~/Mail/Inbox:INDEX=~/.imap";
79 sslServerCert = "/var/lib/acme/mail/fullchain.pem";
80 sslServerKey = "/var/lib/acme/mail/key.pem";
81 sslCACert = "/var/lib/acme/mail/fullchain.pem";
82 extraConfig = builtins.concatStringsSep "\n" [
83 # For printer which doesn’t support elliptic curve
85 ssl_alt_cert = </var/lib/acme/mail-rsa/fullchain.pem
86 ssl_alt_key = </var/lib/acme/mail-rsa/key.pem
90 postmaster_address = postmaster@immae.eu
91 mail_attribute_dict = file:%h/dovecot-attributes
92 imap_idle_notify_interval = 20 mins
103 mail_plugins = $mail_plugins acl
105 acl = vfile:${pkgs.writeText "dovecot-acl" ''
108 acl_globals_only = yes
114 # needs to be bigger than any mailbox size
115 default_vsz_limit = 2GB
116 mail_plugins = $mail_plugins fts fts_xapian
118 plugin = fts fts_xapian
120 fts_xapian = partial=2 full=20
122 fts_autoindex_exclude = \Junk
123 fts_autoindex_exclude2 = \Trash
124 fts_autoindex_exclude3 = Virtual/*
129 # https://docs.iredmail.org/dovecot.imapsieve.html
131 # imap_sieve plugin added below
134 sieve_plugins = sieve_imapsieve sieve_extprograms
135 imapsieve_url = sieve://127.0.0.1:4190
137 sieve_before = file:${./sieve_scripts}/backup.sieve;bindir=/var/lib/vhost/.sieve_bin
139 # From elsewhere to Junk folder
140 imapsieve_mailbox1_name = Junk
141 imapsieve_mailbox1_causes = COPY APPEND
142 imapsieve_mailbox1_before = file:${./sieve_scripts}/report_spam.sieve;bindir=/var/lib/vhost/.imapsieve_bin
144 # From Junk folder to elsewhere
145 imapsieve_mailbox2_name = *
146 imapsieve_mailbox2_from = Junk
147 imapsieve_mailbox2_causes = COPY
148 imapsieve_mailbox2_before = file:${./sieve_scripts}/report_ham.sieve;bindir=/var/lib/vhost/.imapsieve_bin
150 # From anywhere to NoJunk folder
151 imapsieve_mailbox3_name = NoJunk
152 imapsieve_mailbox3_causes = COPY APPEND
153 imapsieve_mailbox3_before = file:${./sieve_scripts}/report_ham.sieve;bindir=/var/lib/vhost/.imapsieve_bin
155 sieve_pipe_bin_dir = ${sieve_bin}
157 sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.environment
165 inet_listener imaps {
171 inet_listener pop3s {
179 unix_listener auth-userdb {
181 unix_listener ${config.services.postfix.config.queue_directory}/private/auth {
185 service auth-worker {
192 unix_listener stats-reader {
197 unix_listener stats-writer {
207 first_valid_uid = ${toString config.ids.uids.vhost}
208 disable_plaintext_auth = yes
211 args = ${config.secrets.fullPaths."dovecot/ldap"}
215 args = ${config.secrets.fullPaths."dovecot/ldap"}
221 mail_plugins = $mail_plugins zlib
231 sieve = file:~/sieve;bindir=~/.sieve-bin;active=~/.dovecot.sieve
233 service managesieve-login {
235 service managesieve {
241 mail_plugins = $mail_plugins virtual
244 location = virtual:~/Virtual
248 # Protocol specific configuration
249 # Needs to come last if there are mail_plugins entries
252 mail_plugins = $mail_plugins imap_sieve imap_acl
255 mail_plugins = $mail_plugins sieve
260 networking.firewall.allowedTCPPorts = [ 110 143 993 995 4190 ];
261 system.activationScripts.dovecot = {
264 install -m 0755 -o vhost -g vhost -d /var/lib/vhost
268 services.cron.systemCronJobs = let
269 cron_script = pkgs.writeScriptBin "cleanup-imap-folders" ''
270 ${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"
271 ${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"
272 ${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"
276 "0 2 * * * root ${cron_script}/bin/cleanup-imap-folders"
278 security.acme.certs."mail-rsa" = {
280 systemctl restart dovecot2.service
283 "imap.immae.eu" = null;
284 "pop3.immae.eu" = null;
287 security.acme.certs."mail" = {
289 systemctl restart dovecot2.service
292 "imap.immae.eu" = null;
293 "pop3.immae.eu" = null;