]>
Commit | Line | Data |
---|---|---|
71a2425e | 1 | { lib, pkgs, config, nodes, ... }: |
a929614f | 2 | { |
8415083e | 3 | config = lib.mkIf config.myServices.mail.enable { |
d2e703c5 | 4 | services.duplyBackup.profiles.mail.excludeFile = '' |
8415083e IB |
5 | + /var/lib/postfix |
6 | ''; | |
7 | secrets.keys = [ | |
8 | { | |
9 | dest = "postfix/mysql_alias_maps"; | |
10 | user = config.services.postfix.user; | |
11 | group = config.services.postfix.group; | |
12 | permissions = "0440"; | |
13 | text = '' | |
14 | # We need to specify that option to trigger ssl connection | |
15 | tls_ciphers = TLSv1.2 | |
ab8f306d IB |
16 | user = ${config.myEnv.mail.postfix.mysql.user} |
17 | password = ${config.myEnv.mail.postfix.mysql.password} | |
18 | hosts = unix:${config.myEnv.mail.postfix.mysql.socket} | |
19 | dbname = ${config.myEnv.mail.postfix.mysql.database} | |
8415083e IB |
20 | query = SELECT DISTINCT destination |
21 | FROM forwardings_merge | |
22 | WHERE | |
23 | ((regex = 1 AND '%s' REGEXP CONCAT('^',source,'$') ) OR (regex = 0 AND source = '%s')) | |
24 | AND active = 1 | |
25 | AND '%s' NOT IN | |
26 | ( | |
27 | SELECT source | |
28 | FROM forwardings_blacklisted | |
29 | WHERE source = '%s' | |
30 | ) UNION | |
31 | SELECT 'devnull@immae.eu' | |
a929614f IB |
32 | FROM forwardings_blacklisted |
33 | WHERE source = '%s' | |
8415083e IB |
34 | ''; |
35 | } | |
36 | { | |
37 | dest = "postfix/mysql_mailbox_maps"; | |
38 | user = config.services.postfix.user; | |
39 | group = config.services.postfix.group; | |
40 | permissions = "0440"; | |
41 | text = '' | |
42 | # We need to specify that option to trigger ssl connection | |
43 | tls_ciphers = TLSv1.2 | |
ab8f306d IB |
44 | user = ${config.myEnv.mail.postfix.mysql.user} |
45 | password = ${config.myEnv.mail.postfix.mysql.password} | |
46 | hosts = unix:${config.myEnv.mail.postfix.mysql.socket} | |
47 | dbname = ${config.myEnv.mail.postfix.mysql.database} | |
8415083e IB |
48 | result_format = /%d/%u |
49 | query = SELECT DISTINCT '%s' | |
50 | FROM mailboxes | |
51 | WHERE active = 1 | |
52 | AND ( | |
53 | (domain = '%d' AND user = '%u' AND regex = 0) | |
54 | OR ( | |
55 | regex = 1 | |
56 | AND '%d' REGEXP CONCAT('^',domain,'$') | |
57 | AND '%u' REGEXP CONCAT('^',user,'$') | |
58 | ) | |
a929614f | 59 | ) |
8415083e | 60 | LIMIT 1 |
a929614f | 61 | ''; |
8415083e IB |
62 | } |
63 | { | |
64 | dest = "postfix/mysql_sender_login_maps"; | |
65 | user = config.services.postfix.user; | |
66 | group = config.services.postfix.group; | |
67 | permissions = "0440"; | |
68 | text = '' | |
69 | # We need to specify that option to trigger ssl connection | |
70 | tls_ciphers = TLSv1.2 | |
ab8f306d IB |
71 | user = ${config.myEnv.mail.postfix.mysql.user} |
72 | password = ${config.myEnv.mail.postfix.mysql.password} | |
73 | hosts = unix:${config.myEnv.mail.postfix.mysql.socket} | |
74 | dbname = ${config.myEnv.mail.postfix.mysql.database} | |
8415083e IB |
75 | query = SELECT DISTINCT destination |
76 | FROM forwardings_merge | |
77 | WHERE | |
d8c20bc3 IB |
78 | ( |
79 | (regex = 1 AND CONCAT(SUBSTRING_INDEX('%u', '+', 1), '@%d') REGEXP CONCAT('^',source,'$') ) | |
80 | OR | |
81 | (regex = 0 AND source = CONCAT(SUBSTRING_INDEX('%u', '+', 1), '@%d')) | |
82 | ) | |
8415083e | 83 | AND active = 1 |
d8c20bc3 | 84 | UNION SELECT CONCAT(SUBSTRING_INDEX('%u', '+', 1), '@%d') AS destination |
8415083e IB |
85 | ''; |
86 | } | |
87a8bffd IB |
87 | { |
88 | dest = "postfix/mysql_sender_relays_maps"; | |
89 | user = config.services.postfix.user; | |
90 | group = config.services.postfix.group; | |
91 | permissions = "0440"; | |
92 | text = '' | |
93 | # We need to specify that option to trigger ssl connection | |
94 | tls_ciphers = TLSv1.2 | |
95 | user = ${config.myEnv.mail.postfix.mysql.user} | |
96 | password = ${config.myEnv.mail.postfix.mysql.password} | |
97 | hosts = unix:${config.myEnv.mail.postfix.mysql.socket} | |
98 | dbname = ${config.myEnv.mail.postfix.mysql.database} | |
99 | # INSERT INTO sender_relays | |
100 | # (`from`, owner, relay, login, password, regex, active) | |
101 | # VALUES | |
102 | # ( 'sender@otherhost.org' | |
103 | # , 'me@mail.immae.eu' | |
104 | # , '[otherhost.org]:587' | |
105 | # , 'otherhostlogin' | |
106 | # , AES_ENCRYPT('otherhostpassword', '${config.myEnv.mail.postfix.mysql.password_encrypt}') | |
107 | # , '0' | |
108 | # , '1'); | |
109 | ||
110 | query = SELECT DISTINCT `owner` | |
111 | FROM sender_relays | |
112 | WHERE | |
113 | ((regex = 1 AND '%s' REGEXP CONCAT('^',`from`,'$') ) OR (regex = 0 AND `from` = '%s')) | |
114 | AND active = 1 | |
115 | ''; | |
116 | } | |
117 | { | |
118 | dest = "postfix/mysql_sender_relays_hosts"; | |
119 | user = config.services.postfix.user; | |
120 | group = config.services.postfix.group; | |
121 | permissions = "0440"; | |
122 | text = '' | |
123 | # We need to specify that option to trigger ssl connection | |
124 | tls_ciphers = TLSv1.2 | |
125 | user = ${config.myEnv.mail.postfix.mysql.user} | |
126 | password = ${config.myEnv.mail.postfix.mysql.password} | |
127 | hosts = unix:${config.myEnv.mail.postfix.mysql.socket} | |
128 | dbname = ${config.myEnv.mail.postfix.mysql.database} | |
129 | ||
130 | query = SELECT DISTINCT relay | |
131 | FROM sender_relays | |
132 | WHERE | |
133 | ((regex = 1 AND '%s' REGEXP CONCAT('^',`from`,'$') ) OR (regex = 0 AND `from` = '%s')) | |
134 | AND active = 1 | |
135 | ''; | |
136 | } | |
137 | { | |
138 | dest = "postfix/mysql_sender_relays_creds"; | |
139 | user = config.services.postfix.user; | |
140 | group = config.services.postfix.group; | |
141 | permissions = "0440"; | |
142 | text = '' | |
143 | # We need to specify that option to trigger ssl connection | |
144 | tls_ciphers = TLSv1.2 | |
145 | user = ${config.myEnv.mail.postfix.mysql.user} | |
146 | password = ${config.myEnv.mail.postfix.mysql.password} | |
147 | hosts = unix:${config.myEnv.mail.postfix.mysql.socket} | |
148 | dbname = ${config.myEnv.mail.postfix.mysql.database} | |
149 | ||
150 | query = SELECT DISTINCT CONCAT(`login`, ':', AES_DECRYPT(`password`, '${config.myEnv.mail.postfix.mysql.password_encrypt}')) | |
151 | FROM sender_relays | |
152 | WHERE | |
153 | ((regex = 1 AND '%s' REGEXP CONCAT('^',`from`,'$') ) OR (regex = 0 AND `from` = '%s')) | |
154 | AND active = 1 | |
155 | ''; | |
156 | } | |
5b53d86f IB |
157 | { |
158 | dest = "postfix/ldap_ejabberd_users_immae_fr"; | |
159 | user = config.services.postfix.user; | |
160 | group = config.services.postfix.group; | |
161 | permissions = "0440"; | |
162 | text = '' | |
163 | server_host = ldaps://${config.myEnv.jabber.ldap.host}:636 | |
164 | search_base = ${config.myEnv.jabber.ldap.base} | |
165 | query_filter = ${config.myEnv.jabber.postfix_user_filter} | |
166 | domain = immae.fr | |
167 | bind_dn = ${config.myEnv.jabber.ldap.dn} | |
168 | bind_pw = ${config.myEnv.jabber.ldap.password} | |
169 | result_attribute = immaeXmppUid | |
170 | result_format = ejabberd@localhost | |
171 | version = 3 | |
172 | ''; | |
173 | } | |
8415083e | 174 | ]; |
a929614f | 175 | |
8415083e | 176 | networking.firewall.allowedTCPPorts = [ 25 465 587 ]; |
a929614f | 177 | |
8415083e IB |
178 | users.users."${config.services.postfix.user}".extraGroups = [ "keys" ]; |
179 | services.filesWatcher.postfix = { | |
180 | restart = true; | |
181 | paths = [ | |
182 | config.secrets.fullPaths."postfix/mysql_alias_maps" | |
183 | config.secrets.fullPaths."postfix/mysql_mailbox_maps" | |
184 | config.secrets.fullPaths."postfix/mysql_sender_login_maps" | |
5b53d86f | 185 | config.secrets.fullPaths."postfix/ldap_ejabberd_users_immae_fr" |
8415083e IB |
186 | ]; |
187 | }; | |
188 | services.postfix = { | |
2a61e9da IB |
189 | extraAliases = let |
190 | toScript = name: script: pkgs.writeScript name '' | |
191 | #! ${pkgs.stdenv.shell} | |
192 | mail=$(${pkgs.coreutils}/bin/cat -) | |
193 | output=$(echo "$mail" | ${script} 2>&1) | |
194 | ret=$? | |
195 | ||
196 | if [ "$ret" != "0" ]; then | |
197 | echo "$mail" \ | |
198 | | ${pkgs.procmail}/bin/formail -i "X-Return-Code: $ret" \ | |
199 | | /run/wrappers/bin/sendmail -i scripts_error+${name}@mail.immae.eu | |
200 | ||
201 | messageId=$(echo "$mail" | ${pkgs.procmail}/bin/formail -x "Message-Id:") | |
202 | repeat=$(echo "$mail" | ${pkgs.procmail}/bin/formail -X "From:" -X "Received:") | |
203 | ||
204 | ${pkgs.coreutils}/bin/cat <<EOF | /run/wrappers/bin/sendmail -i scripts_error+${name}@mail.immae.eu | |
205 | $repeat | |
206 | To: scripts_error+${name}@mail.immae.eu | |
207 | Subject: Log from script error | |
208 | Content-Type: text/plain; charset="UTF-8" | |
209 | Content-Transfer-Encoding: 8bit | |
210 | References:$messageId | |
211 | MIME-Version: 1.0 | |
212 | X-Return-Code: $ret | |
213 | ||
214 | Error code: $ret | |
215 | Output of message: | |
216 | -------------- | |
217 | $output | |
218 | -------------- | |
219 | EOF | |
220 | fi | |
221 | ''; | |
222 | scripts = lib.attrsets.mapAttrs (n: v: | |
223 | toScript n (pkgs.callPackage (builtins.fetchGit { url = v.src.url; ref = "master"; rev = v.src.rev; }) { scriptEnv = v.env; }) | |
71a2425e IB |
224 | ) config.myEnv.mail.scripts // { |
225 | testmail = pkgs.writeScript "testmail" '' | |
226 | #! ${pkgs.stdenv.shell} | |
227 | ${pkgs.coreutils}/bin/touch \ | |
228 | "/var/lib/naemon/checks/email/$(${pkgs.procmail}/bin/formail -x To: | ${pkgs.coreutils}/bin/tr -d ' <>')" | |
229 | ''; | |
230 | }; | |
2a61e9da | 231 | in builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList (n: v: ''${n}: "|${v}"'') scripts); |
8415083e IB |
232 | mapFiles = let |
233 | recipient_maps = let | |
234 | name = n: i: "relay_${n}_${toString i}"; | |
235 | pair = n: i: m: lib.attrsets.nameValuePair (name n i) ( | |
236 | if m.type == "hash" | |
237 | then pkgs.writeText (name n i) m.content | |
04b2ab97 | 238 | else null |
8415083e IB |
239 | ); |
240 | pairs = n: v: lib.imap1 (i: m: pair n i m) v.recipient_maps; | |
241 | in lib.attrsets.filterAttrs (k: v: v != null) ( | |
242 | lib.attrsets.listToAttrs (lib.flatten ( | |
ab8f306d | 243 | lib.attrsets.mapAttrsToList pairs config.myEnv.mail.postfix.backup_domains |
8415083e IB |
244 | )) |
245 | ); | |
246 | relay_restrictions = lib.attrsets.filterAttrs (k: v: v != null) ( | |
247 | lib.attrsets.mapAttrs' (n: v: | |
248 | lib.attrsets.nameValuePair "recipient_access_${n}" ( | |
249 | if lib.attrsets.hasAttr "relay_restrictions" v | |
250 | then pkgs.writeText "recipient_access_${n}" v.relay_restrictions | |
251 | else null | |
252 | ) | |
ab8f306d | 253 | ) config.myEnv.mail.postfix.backup_domains |
8415083e | 254 | ); |
2a61e9da | 255 | virtual_map = { |
71a2425e IB |
256 | virtual = let |
257 | cfg = config.myEnv.monitoring.email_check.eldiron; | |
258 | address = "${cfg.mail_address}@${cfg.mail_domain}"; | |
259 | in pkgs.writeText "postfix-virtual" ( | |
2a61e9da | 260 | builtins.concatStringsSep "\n" ( |
71a2425e | 261 | ["${address} testmail@localhost"] ++ |
2a61e9da | 262 | lib.attrsets.mapAttrsToList ( |
5b53d86f | 263 | n: v: lib.optionalString v.external '' |
2a61e9da IB |
264 | script_${n}@mail.immae.eu ${n}@localhost, scripts@mail.immae.eu |
265 | '' | |
ab8f306d | 266 | ) config.myEnv.mail.scripts |
2a61e9da IB |
267 | ) |
268 | ); | |
269 | }; | |
deca5e9b | 270 | sasl_access = { |
ef0a9217 IB |
271 | host_sender_login = with lib.attrsets; let |
272 | addresses = zipAttrs (lib.flatten (mapAttrsToList | |
273 | (n: v: (map (e: { "${e}" = "${n}@immae.eu"; }) v.emails)) config.myEnv.servers)); | |
274 | joined = builtins.concatStringsSep ","; | |
275 | in pkgs.writeText "host-sender-login" | |
276 | (builtins.concatStringsSep "\n" (mapAttrsToList (n: v: "${n} ${joined v}") addresses)); | |
deca5e9b | 277 | host_dummy_mailboxes = pkgs.writeText "host-virtual-mailbox" |
10e597f8 | 278 | (builtins.concatStringsSep "\n" (["immae-eu@immae.eu dummy"] ++ lib.attrsets.mapAttrsToList (n: v: "${n}@immae.eu dummy") nodes)); |
deca5e9b | 279 | }; |
8415083e | 280 | in |
deca5e9b | 281 | recipient_maps // relay_restrictions // virtual_map // sasl_access; |
8415083e IB |
282 | config = { |
283 | ### postfix module overrides | |
284 | readme_directory = "${pkgs.postfix}/share/postfix/doc"; | |
285 | smtp_tls_CAfile = lib.mkForce ""; | |
286 | smtp_tls_cert_file = lib.mkForce ""; | |
287 | smtp_tls_key_file = lib.mkForce ""; | |
a929614f | 288 | |
8415083e | 289 | message_size_limit = "1073741824"; # Don't put 0 here, it's not equivalent to "unlimited" |
2a61e9da | 290 | mailbox_size_limit = "1073741825"; # Workaround, local delivered mails should all go through scripts |
8415083e | 291 | alias_database = "\$alias_maps"; |
a929614f | 292 | |
8415083e | 293 | ### Virtual mailboxes config |
5b53d86f | 294 | virtual_alias_maps = "hash:/etc/postfix/virtual mysql:${config.secrets.fullPaths."postfix/mysql_alias_maps"} ldap:${config.secrets.fullPaths."postfix/ldap_ejabberd_users_immae_fr"}"; |
ab8f306d | 295 | virtual_mailbox_domains = config.myEnv.mail.postfix.additional_mailbox_domains |
ccb8bab4 | 296 | ++ lib.remove null (lib.flatten (map |
8415083e IB |
297 | (zone: map |
298 | (e: if e.receive | |
299 | then "${e.domain}${lib.optionalString (e.domain != "") "."}${zone.name}" | |
300 | else null | |
301 | ) | |
302 | (zone.withEmail or []) | |
a929614f | 303 | ) |
ab8f306d | 304 | config.myEnv.dns.masterZones |
ccb8bab4 | 305 | )); |
deca5e9b | 306 | virtual_mailbox_maps = "hash:/etc/postfix/host_dummy_mailboxes mysql:${config.secrets.fullPaths."postfix/mysql_mailbox_maps"}"; |
8415083e IB |
307 | dovecot_destination_recipient_limit = "1"; |
308 | virtual_transport = "dovecot"; | |
a929614f | 309 | |
8415083e | 310 | ### Relay domains |
ab8f306d | 311 | relay_domains = lib.flatten (lib.attrsets.mapAttrsToList (n: v: v.domains or []) config.myEnv.mail.postfix.backup_domains); |
8415083e IB |
312 | relay_recipient_maps = lib.flatten (lib.attrsets.mapAttrsToList (n: v: |
313 | lib.imap1 (i: m: "${m.type}:/etc/postfix/relay_${n}_${toString i}") v.recipient_maps | |
ab8f306d | 314 | ) config.myEnv.mail.postfix.backup_domains); |
8415083e | 315 | smtpd_relay_restrictions = [ |
8415083e IB |
316 | "defer_unauth_destination" |
317 | ] ++ lib.flatten (lib.attrsets.mapAttrsToList (n: v: | |
318 | if lib.attrsets.hasAttr "relay_restrictions" v | |
319 | then [ "check_recipient_access hash:/etc/postfix/recipient_access_${n}" ] | |
320 | else [] | |
ab8f306d | 321 | ) config.myEnv.mail.postfix.backup_domains); |
a929614f | 322 | |
8415083e IB |
323 | ### Additional smtpd configuration |
324 | smtpd_tls_received_header = "yes"; | |
325 | smtpd_tls_loglevel = "1"; | |
a929614f | 326 | |
8415083e IB |
327 | ### Email sending configuration |
328 | smtp_tls_security_level = "may"; | |
329 | smtp_tls_loglevel = "1"; | |
a929614f | 330 | |
8415083e | 331 | ### Force ip bind for smtp |
619e4f46 IB |
332 | smtp_bind_address = config.hostEnv.ips.main.ip4; |
333 | smtp_bind_address6 = builtins.head config.hostEnv.ips.main.ip6; | |
a929614f | 334 | |
87a8bffd IB |
335 | # Use some relays when authorized senders are not myself |
336 | smtp_sasl_mechanism_filter = "plain,login"; # GSSAPI Not correctly supported by postfix | |
337 | smtp_sasl_auth_enable = "yes"; | |
338 | smtp_sasl_password_maps = | |
339 | "mysql:${config.secrets.fullPaths."postfix/mysql_sender_relays_creds"}"; | |
340 | smtp_sasl_security_options = "noanonymous"; | |
341 | smtp_sender_dependent_authentication = "yes"; | |
342 | sender_dependent_relayhost_maps = | |
343 | "mysql:${config.secrets.fullPaths."postfix/mysql_sender_relays_hosts"}"; | |
a929614f | 344 | |
8415083e IB |
345 | ### opendkim, opendmarc, openarc milters |
346 | non_smtpd_milters = [ | |
347 | "unix:${config.myServices.mail.milters.sockets.opendkim}" | |
8415083e IB |
348 | ]; |
349 | smtpd_milters = [ | |
350 | "unix:${config.myServices.mail.milters.sockets.opendkim}" | |
8415083e | 351 | "unix:${config.myServices.mail.milters.sockets.openarc}" |
619e4f46 | 352 | "unix:${config.myServices.mail.milters.sockets.opendmarc}" |
a929614f | 353 | ]; |
5153eb54 IB |
354 | |
355 | smtp_use_tls = true; | |
356 | smtpd_use_tls = true; | |
357 | smtpd_tls_chain_files = builtins.concatStringsSep "," [ "/var/lib/acme/mail/full.pem" "/var/lib/acme/mail-rsa/full.pem" ]; | |
6ea94404 IB |
358 | |
359 | maximal_queue_lifetime = "6w"; | |
360 | bounce_queue_lifetime = "6w"; | |
a929614f | 361 | }; |
8415083e IB |
362 | enable = true; |
363 | enableSmtp = true; | |
364 | enableSubmission = true; | |
365 | submissionOptions = { | |
87a8bffd IB |
366 | # Don’t use "long form", only commas (cf |
367 | # http://www.postfix.org/master.5.html long form is not handled | |
368 | # well by the submission function) | |
8415083e IB |
369 | smtpd_tls_security_level = "encrypt"; |
370 | smtpd_sasl_auth_enable = "yes"; | |
371 | smtpd_tls_auth_only = "yes"; | |
372 | smtpd_sasl_tls_security_options = "noanonymous"; | |
373 | smtpd_sasl_type = "dovecot"; | |
374 | smtpd_sasl_path = "private/auth"; | |
375 | smtpd_reject_unlisted_recipient = "no"; | |
376 | smtpd_client_restrictions = "permit_sasl_authenticated,reject"; | |
619e4f46 | 377 | smtpd_relay_restrictions = "permit_sasl_authenticated,reject"; |
8415083e IB |
378 | # Refuse to send e-mails with a From that is not handled |
379 | smtpd_sender_restrictions = | |
380 | "reject_sender_login_mismatch,reject_unlisted_sender,permit_sasl_authenticated,reject"; | |
87a8bffd IB |
381 | smtpd_sender_login_maps = builtins.concatStringsSep "," [ |
382 | "hash:/etc/postfix/host_sender_login" | |
383 | "mysql:${config.secrets.fullPaths."postfix/mysql_sender_relays_maps"}" | |
384 | "mysql:${config.secrets.fullPaths."postfix/mysql_sender_login_maps"}" | |
385 | ]; | |
8415083e IB |
386 | smtpd_recipient_restrictions = "permit_sasl_authenticated,reject"; |
387 | milter_macro_daemon_name = "ORIGINATING"; | |
45730653 IB |
388 | smtpd_milters = builtins.concatStringsSep "," [ |
389 | # FIXME: put it back when opensmtpd is upgraded and able to | |
390 | # rewrite the from header | |
391 | #"unix:/run/milter_verify_from/verify_from.sock" | |
392 | "unix:${config.myServices.mail.milters.sockets.opendkim}" | |
393 | ]; | |
8415083e | 394 | }; |
8415083e IB |
395 | destination = ["localhost"]; |
396 | # This needs to reverse DNS | |
619e4f46 | 397 | hostname = config.hostEnv.fqdn; |
8415083e | 398 | setSendmail = true; |
8415083e IB |
399 | recipientDelimiter = "+"; |
400 | masterConfig = { | |
401 | submissions = { | |
402 | type = "inet"; | |
403 | private = false; | |
404 | command = "smtpd"; | |
405 | args = ["-o" "smtpd_tls_wrappermode=yes" ] ++ (let | |
406 | mkKeyVal = opt: val: [ "-o" (opt + "=" + val) ]; | |
407 | in lib.concatLists (lib.mapAttrsToList mkKeyVal config.services.postfix.submissionOptions) | |
408 | ); | |
409 | }; | |
410 | dovecot = { | |
411 | type = "unix"; | |
412 | privileged = true; | |
413 | chroot = false; | |
414 | command = "pipe"; | |
415 | args = let | |
416 | # rspamd could be used as a milter, but then it cannot apply | |
417 | # its checks "per user" (milter is not yet dispatched to | |
418 | # users), so we wrap dovecot-lda inside rspamc per recipient | |
419 | # here. | |
dc6d3af9 IB |
420 | rspamc_dovecot = pkgs.writeScriptBin "rspamc_dovecot" '' |
421 | #! ${pkgs.stdenv.shell} | |
422 | sender="$1" | |
423 | original_recipient="$2" | |
424 | user="$3" | |
425 | ||
426 | ${pkgs.coreutils}/bin/cat - | \ | |
427 | (${pkgs.rspamd}/bin/rspamc -h ${config.myServices.mail.rspamd.sockets.worker-controller} -c bayes -d "$user" --mime || true) | \ | |
428 | ${pkgs.dovecot}/libexec/dovecot/dovecot-lda -f "$sender" -a "$original_recipient" -d "$user" | |
429 | ''; | |
8415083e IB |
430 | in [ |
431 | "flags=DRhu" "user=vhost:vhost" | |
dc6d3af9 | 432 | "argv=${rspamc_dovecot}/bin/rspamc_dovecot \${sender} \${original_recipient} \${user}@\${nexthop}" |
8415083e IB |
433 | ]; |
434 | }; | |
435 | }; | |
a929614f | 436 | }; |
5400b9b6 | 437 | security.acme.certs."mail" = { |
8415083e IB |
438 | postRun = '' |
439 | systemctl restart postfix.service | |
440 | ''; | |
441 | extraDomains = { | |
514f9ec3 IB |
442 | "smtp.immae.eu" = null; |
443 | }; | |
444 | }; | |
445 | security.acme.certs."mail-rsa" = { | |
446 | postRun = '' | |
447 | systemctl restart postfix.service | |
448 | ''; | |
449 | extraDomains = { | |
8415083e IB |
450 | "smtp.immae.eu" = null; |
451 | }; | |
a929614f | 452 | }; |
71a2425e IB |
453 | system.activationScripts.testmail = { |
454 | deps = [ "users" ]; | |
455 | text = let | |
456 | allCfg = config.myEnv.monitoring.email_check; | |
457 | cfg = allCfg.eldiron; | |
458 | reverseTargets = builtins.attrNames (lib.attrsets.filterAttrs (k: v: builtins.elem "eldiron" v.targets) allCfg); | |
459 | to_email = cfg': host': | |
460 | let sep = if lib.strings.hasInfix "+" cfg'.mail_address then "_" else "+"; | |
461 | in "${cfg'.mail_address}${sep}${host'}@${cfg'.mail_domain}"; | |
462 | mails_to_receive = builtins.concatStringsSep " " (map (to_email cfg) reverseTargets); | |
463 | in '' | |
464 | install -m 0555 -o nobody -g nogroup -d /var/lib/naemon/checks/email | |
465 | for f in ${mails_to_receive}; do | |
466 | if [ ! -f /var/lib/naemon/checks/email/$f ]; then | |
467 | install -m 0644 -o nobody -g nogroup /dev/null -T /var/lib/naemon/checks/email/$f | |
468 | touch -m -d @0 /var/lib/naemon/checks/email/$f | |
469 | fi | |
470 | done | |
471 | ''; | |
472 | }; | |
a929614f IB |
473 | }; |
474 | } |