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 myServices.chatonsProperties.services.email = {
17 file.datetime = "2022-08-22T01:00:00";
19 name = "E-mail account";
20 description = "Compte e-mail avec configuration imap et smtp/pop3";
21 logo = "https://www.dovecot.org/wp-content/uploads/2021/09/favicon.ico";
22 website = "https://mail.immae.eu/";
24 status.description = "OK";
25 registration."" = ["MEMBER" "CLIENT"];
26 registration.load = "OPEN";
27 install.type = "PACKAGE";
31 website = "https://www.dovecot.org/";
32 license.url = "https://github.com/dovecot/core/blob/main/COPYING";
33 license.name = "MIT and LGPLv2.1 Licenses";
34 version = pkgs.dovecot.version;
35 source.url = "https://github.com/dovecot/core";
36 modules = ["roundcube" "rainloop"] ++ map (a: a.pname) config.services.dovecot2.modules;
39 systemd.services.dovecot2.serviceConfig.Slice = "mail.slice";
40 secrets.keys."dovecot/ldap" = {
41 user = config.services.dovecot2.user;
42 group = config.services.dovecot2.group;
45 hosts = ${config.myEnv.mail.dovecot.ldap.host}
48 dn = ${config.myEnv.mail.dovecot.ldap.dn}
49 dnpass = ${config.myEnv.mail.dovecot.ldap.password}
55 base = ${config.myEnv.mail.dovecot.ldap.base}
58 pass_filter = ${config.myEnv.mail.dovecot.ldap.filter}
59 pass_attrs = ${config.myEnv.mail.dovecot.ldap.pass_attrs}
61 user_attrs = ${config.myEnv.mail.dovecot.ldap.user_attrs}
62 user_filter = ${config.myEnv.mail.dovecot.ldap.filter}
63 iterate_attrs = ${config.myEnv.mail.dovecot.ldap.iterate_attrs}
64 iterate_filter = ${config.myEnv.mail.dovecot.ldap.iterate_filter}
70 uid = config.ids.uids.vhost;
72 users.groups.vhost.gid = config.ids.gids.vhost;
73 users.users."${config.services.dovecot2.user}".extraGroups = [ "acme" ];
75 # https://blog.zeninc.net/index.php?post/2018/04/01/Un-annuaire-pour-les-gouverner-tous.......
82 protocols = [ "sieve" ];
84 pkgs.dovecot_pigeonhole
85 pkgs.dovecot_fts_xapian
89 createMailUser = false;
91 Trash = { auto = "subscribe"; specialUse = "Trash"; };
92 Junk = { auto = "subscribe"; specialUse = "Junk"; };
93 Sent = { auto = "subscribe"; specialUse = "Sent"; };
94 Drafts = { auto = "subscribe"; specialUse = "Drafts"; };
96 mailLocation = "mbox:~/Mail:INBOX=~/Mail/Inbox:INDEX=~/.imap";
97 sslServerCert = "/etc/dovecot/fullchain.pem";
98 sslServerKey = "/var/lib/acme/mail/key.pem";
99 sslCACert = "/etc/dovecot/fullchain.pem";
100 extraConfig = builtins.concatStringsSep "\n" [
101 # For printer which doesn’t support elliptic curve
103 ssl_alt_cert = </etc/dovecot/fullchain-rsa.pem
104 ssl_alt_key = </var/lib/acme/mail-rsa/key.pem
108 postmaster_address = postmaster@immae.eu
109 mail_attribute_dict = file:%h/dovecot-attributes
110 imap_idle_notify_interval = 20 mins
121 mail_plugins = $mail_plugins acl
123 acl = vfile:${pkgs.writeText "dovecot-acl" ''
126 acl_globals_only = yes
132 # needs to be bigger than any mailbox size
133 default_vsz_limit = 2GB
134 mail_plugins = $mail_plugins fts fts_xapian
136 plugin = fts fts_xapian
138 fts_xapian = partial=2 full=20
140 fts_autoindex_exclude = \Junk
141 fts_autoindex_exclude2 = \Trash
142 fts_autoindex_exclude3 = Virtual/*
147 # https://docs.iredmail.org/dovecot.imapsieve.html
149 # imap_sieve plugin added below
152 sieve_plugins = sieve_imapsieve sieve_extprograms
153 imapsieve_url = sieve://127.0.0.1:4190
155 sieve_before = file:${./sieve_scripts}/backup.sieve;bindir=/var/lib/vhost/.sieve_bin
157 # From elsewhere to Junk folder
158 imapsieve_mailbox1_name = Junk
159 imapsieve_mailbox1_causes = COPY APPEND
160 imapsieve_mailbox1_before = file:${./sieve_scripts}/report_spam.sieve;bindir=/var/lib/vhost/.imapsieve_bin
162 # From Junk folder to elsewhere
163 imapsieve_mailbox2_name = *
164 imapsieve_mailbox2_from = Junk
165 imapsieve_mailbox2_causes = COPY
166 imapsieve_mailbox2_before = file:${./sieve_scripts}/report_ham.sieve;bindir=/var/lib/vhost/.imapsieve_bin
168 # From anywhere to NoJunk folder
169 imapsieve_mailbox3_name = NoJunk
170 imapsieve_mailbox3_causes = COPY APPEND
171 imapsieve_mailbox3_before = file:${./sieve_scripts}/report_ham.sieve;bindir=/var/lib/vhost/.imapsieve_bin
173 sieve_pipe_bin_dir = ${sieve_bin}
175 sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.environment
183 inet_listener imaps {
189 inet_listener pop3s {
197 unix_listener auth-userdb {
199 unix_listener ${config.services.postfix.config.queue_directory}/private/auth {
203 service auth-worker {
210 unix_listener stats-reader {
215 unix_listener stats-writer {
225 first_valid_uid = ${toString config.ids.uids.vhost}
226 disable_plaintext_auth = yes
229 args = ${config.secrets.fullPaths."dovecot/ldap"}
233 args = ${config.secrets.fullPaths."dovecot/ldap"}
239 mail_plugins = $mail_plugins zlib
249 sieve = file:~/sieve;bindir=~/.sieve-bin;active=~/.dovecot.sieve
251 service managesieve-login {
253 service managesieve {
259 mail_plugins = $mail_plugins virtual
262 location = virtual:~/Virtual
266 # Protocol specific configuration
267 # Needs to come last if there are mail_plugins entries
270 mail_plugins = $mail_plugins imap_sieve imap_acl
273 mail_plugins = $mail_plugins sieve
278 networking.firewall.allowedTCPPorts = [ 110 143 993 995 4190 ];
279 system.activationScripts.dovecot = {
282 install -m 0755 -o vhost -g vhost -d /var/lib/vhost
286 services.cron.systemCronJobs = let
287 cron_script = pkgs.writeScriptBin "cleanup-imap-folders" ''
288 ${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"
289 ${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"
290 ${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"
294 "0 2 * * * root ${cron_script}/bin/cleanup-imap-folders"
296 security.acme.certs."mail-rsa" = {
298 systemctl restart dovecot2.service
300 extraDomainNames = [ "imap.immae.eu" "pop3.immae.eu" ];
302 security.acme.certs."mail" = {
304 systemctl restart dovecot2.service
306 extraDomainNames = [ "imap.immae.eu" "pop3.immae.eu" ];