services: Fix typo in (gnu services mail) exports.
[jackhill/guix/guix.git] / gnu / services / mail.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Andy Wingo <wingo@igalia.com>
3 ;;; Copyright © 2017, 2018 Clément Lassieur <clement@lassieur.org>
4 ;;; Copyright © 2017 Carlo Zancanaro <carlo@zancanaro.id.au>
5 ;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
6 ;;;
7 ;;; This file is part of GNU Guix.
8 ;;;
9 ;;; GNU Guix is free software; you can redistribute it and/or modify it
10 ;;; under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 3 of the License, or (at
12 ;;; your option) any later version.
13 ;;;
14 ;;; GNU Guix is distributed in the hope that it will be useful, but
15 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
18 ;;;
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 ;;;
22 ;;; Some of the help text was taken from the default dovecot.conf files.
23
24 (define-module (gnu services mail)
25 #:use-module (gnu services)
26 #:use-module (gnu services base)
27 #:use-module (gnu services configuration)
28 #:use-module (gnu services shepherd)
29 #:use-module (gnu system pam)
30 #:use-module (gnu system shadow)
31 #:use-module (gnu packages mail)
32 #:use-module (gnu packages admin)
33 #:use-module (gnu packages tls)
34 #:use-module (guix records)
35 #:use-module (guix packages)
36 #:use-module (guix gexp)
37 #:use-module (ice-9 match)
38 #:use-module (ice-9 format)
39 #:use-module (srfi srfi-1)
40 #:export (dovecot-service
41 dovecot-service-type
42 dovecot-configuration
43 opaque-dovecot-configuration
44
45 dict-configuration
46 passdb-configuration
47 userdb-configuration
48 unix-listener-configuration
49 fifo-listener-configuration
50 inet-listener-configuration
51 service-configuration
52 protocol-configuration
53 plugin-configuration
54 mailbox-configuration
55 namespace-configuration
56
57 opensmtpd-configuration
58 opensmtpd-configuration?
59 opensmtpd-service-type
60 %default-opensmtpd-config-file
61
62 mail-aliases-service-type
63
64 exim-configuration
65 exim-configuration?
66 exim-service-type
67 %default-exim-config-file
68
69 imap4d-configuration
70 imap4d-configuration?
71 imap4d-service-type
72 %default-imap4d-config-file))
73
74 ;;; Commentary:
75 ;;;
76 ;;; This module provides service definitions for the Dovecot POP3 and IMAP
77 ;;; mail server.
78 ;;;
79 ;;; Code:
80
81 (define (uglify-field-name field-name)
82 (let ((str (symbol->string field-name)))
83 (string-join (string-split (if (string-suffix? "?" str)
84 (substring str 0 (1- (string-length str)))
85 str)
86 #\-)
87 "_")))
88
89 (define (serialize-field field-name val)
90 (format #t "~a=~a\n" (uglify-field-name field-name) val))
91
92 (define (serialize-string field-name val)
93 (serialize-field field-name val))
94
95 (define (space-separated-string-list? val)
96 (and (list? val)
97 (and-map (lambda (x)
98 (and (string? x) (not (string-index x #\space))))
99 val)))
100 (define (serialize-space-separated-string-list field-name val)
101 (serialize-field field-name (string-join val " ")))
102
103 (define (comma-separated-string-list? val)
104 (and (list? val)
105 (and-map (lambda (x)
106 (and (string? x) (not (string-index x #\,))))
107 val)))
108 (define (serialize-comma-separated-string-list field-name val)
109 (serialize-field field-name (string-join val ",")))
110
111 (define (file-name? val)
112 (and (string? val)
113 (string-prefix? "/" val)))
114 (define (serialize-file-name field-name val)
115 (serialize-string field-name val))
116
117 (define (colon-separated-file-name-list? val)
118 (and (list? val)
119 ;; Trailing slashes not needed and not
120 (and-map file-name? val)))
121 (define (serialize-colon-separated-file-name-list field-name val)
122 (serialize-field field-name (string-join val ":")))
123
124 (define (serialize-boolean field-name val)
125 (serialize-string field-name (if val "yes" "no")))
126
127 (define (non-negative-integer? val)
128 (and (exact-integer? val) (not (negative? val))))
129 (define (serialize-non-negative-integer field-name val)
130 (serialize-field field-name val))
131
132 (define (hours? val) (non-negative-integer? val))
133 (define (serialize-hours field-name val)
134 (serialize-field field-name (format #f "~a hours" val)))
135
136 (define (free-form-fields? val)
137 (match val
138 (() #t)
139 ((((? symbol?) . (? string)) . val) (free-form-fields? val))
140 (_ #f)))
141 (define (serialize-free-form-fields field-name val)
142 (for-each (match-lambda ((k . v) (serialize-field k v))) val))
143
144 (define (free-form-args? val)
145 (match val
146 (() #t)
147 ((((? symbol?) . (? string)) . val) (free-form-args? val))
148 (_ #f)))
149 (define (serialize-free-form-args field-name val)
150 (serialize-field field-name
151 (string-join
152 (map (match-lambda ((k . v) (format #t "~a=~a" k v))) val)
153 " ")))
154
155 (define-configuration dict-configuration
156 (entries
157 (free-form-fields '())
158 "A list of key-value pairs that this dict should hold."))
159
160 (define (serialize-dict-configuration field-name val)
161 (format #t "dict {\n")
162 (serialize-configuration val dict-configuration-fields)
163 (format #t "}\n"))
164
165 (define-configuration passdb-configuration
166 (driver
167 (string "pam")
168 "The driver that the passdb should use. Valid values include
169 @samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
170 @samp{static}.")
171 (args
172 (space-separated-string-list '())
173 "Space separated list of arguments to the passdb driver."))
174
175 (define (serialize-passdb-configuration field-name val)
176 (format #t "passdb {\n")
177 (serialize-configuration val passdb-configuration-fields)
178 (format #t "}\n"))
179 (define (passdb-configuration-list? val)
180 (and (list? val) (and-map passdb-configuration? val)))
181 (define (serialize-passdb-configuration-list field-name val)
182 (for-each (lambda (val) (serialize-passdb-configuration field-name val)) val))
183
184 (define-configuration userdb-configuration
185 (driver
186 (string "passwd")
187 "The driver that the userdb should use. Valid values include
188 @samp{passwd} and @samp{static}.")
189 (args
190 (space-separated-string-list '())
191 "Space separated list of arguments to the userdb driver.")
192 (override-fields
193 (free-form-args '())
194 "Override fields from passwd."))
195
196 (define (serialize-userdb-configuration field-name val)
197 (format #t "userdb {\n")
198 (serialize-configuration val userdb-configuration-fields)
199 (format #t "}\n"))
200 (define (userdb-configuration-list? val)
201 (and (list? val) (and-map userdb-configuration? val)))
202 (define (serialize-userdb-configuration-list field-name val)
203 (for-each (lambda (val) (serialize-userdb-configuration field-name val)) val))
204
205 (define-configuration unix-listener-configuration
206 (path
207 (string (configuration-missing-field 'unix-listener 'path))
208 "Path to the file, relative to @code{base-dir} field. This is also used as
209 the section name.")
210 (mode
211 (string "0600")
212 "The access mode for the socket.")
213 (user
214 (string "")
215 "The user to own the the socket.")
216 (group
217 (string "")
218 "The group to own the socket."))
219
220 (define (serialize-unix-listener-configuration field-name val)
221 (format #t "unix_listener ~a {\n" (unix-listener-configuration-path val))
222 (serialize-configuration val (cdr unix-listener-configuration-fields))
223 (format #t "}\n"))
224
225 (define-configuration fifo-listener-configuration
226 (path
227 (string (configuration-missing-field 'fifo-listener 'path))
228 "Path to the file, relative to @code{base-dir} field. This is also used as
229 the section name.")
230 (mode
231 (string "0600")
232 "The access mode for the socket.")
233 (user
234 (string "")
235 "The user to own the the socket.")
236 (group
237 (string "")
238 "The group to own the socket."))
239
240 (define (serialize-fifo-listener-configuration field-name val)
241 (format #t "fifo_listener ~a {\n" (fifo-listener-configuration-path val))
242 (serialize-configuration val (cdr fifo-listener-configuration-fields))
243 (format #t "}\n"))
244
245 (define-configuration inet-listener-configuration
246 (protocol
247 (string (configuration-missing-field 'inet-listener 'protocol))
248 "The protocol to listen for.")
249 (address
250 (string "")
251 "The address on which to listen, or empty for all addresses.")
252 (port
253 (non-negative-integer
254 (configuration-missing-field 'inet-listener 'port))
255 "The port on which to listen.")
256 (ssl?
257 (boolean #t)
258 "Whether to use SSL for this service; @samp{yes}, @samp{no}, or
259 @samp{required}."))
260
261 (define (serialize-inet-listener-configuration field-name val)
262 (format #t "inet_listener ~a {\n" (inet-listener-configuration-protocol val))
263 (serialize-configuration val (cdr inet-listener-configuration-fields))
264 (format #t "}\n"))
265
266 (define (listener-configuration? val)
267 (or (unix-listener-configuration? val)
268 (fifo-listener-configuration? val)
269 (inet-listener-configuration? val)))
270 (define (serialize-listener-configuration field-name val)
271 (cond
272 ((unix-listener-configuration? val)
273 (serialize-unix-listener-configuration field-name val))
274 ((fifo-listener-configuration? val)
275 (serialize-fifo-listener-configuration field-name val))
276 ((inet-listener-configuration? val)
277 (serialize-inet-listener-configuration field-name val))
278 (else (configuration-field-error field-name val))))
279 (define (listener-configuration-list? val)
280 (and (list? val) (and-map listener-configuration? val)))
281 (define (serialize-listener-configuration-list field-name val)
282 (for-each (lambda (val)
283 (serialize-listener-configuration field-name val))
284 val))
285
286 (define-configuration service-configuration
287 (kind
288 (string (configuration-missing-field 'service 'kind))
289 "The service kind. Valid values include @code{director},
290 @code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
291 @code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
292 @code{tcpwrap}, @code{quota-warning}, or anything else.")
293 (listeners
294 (listener-configuration-list '())
295 "Listeners for the service. A listener is either an
296 @code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
297 an @code{inet-listener-configuration}.")
298 (client-limit
299 (non-negative-integer 0)
300 "Maximum number of simultaneous client connections per process. Once this
301 number of connections is received, the next incoming connection will prompt
302 Dovecot to spawn another process. If set to 0, @code{default-client-limit} is
303 used instead.")
304 (service-count
305 (non-negative-integer 1)
306 "Number of connections to handle before starting a new process.
307 Typically the only useful values are 0 (unlimited) or 1. 1 is more
308 secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.")
309 (process-limit
310 (non-negative-integer 0)
311 "Maximum number of processes that can exist for this service. If set to 0,
312 @code{default-process-limit} is used instead.")
313 (process-min-avail
314 (non-negative-integer 0)
315 "Number of processes to always keep waiting for more connections.")
316 ;; FIXME: Need to be able to take the default for this value from other
317 ;; parts of the config.
318 (vsz-limit
319 (non-negative-integer #e256e6)
320 "If you set @samp{service-count 0}, you probably need to grow
321 this."))
322
323 (define (serialize-service-configuration field-name val)
324 (format #t "service ~a {\n" (service-configuration-kind val))
325 (serialize-configuration val (cdr service-configuration-fields))
326 (format #t "}\n"))
327 (define (service-configuration-list? val)
328 (and (list? val) (and-map service-configuration? val)))
329 (define (serialize-service-configuration-list field-name val)
330 (for-each (lambda (val)
331 (serialize-service-configuration field-name val))
332 val))
333
334 (define-configuration protocol-configuration
335 (name
336 (string (configuration-missing-field 'protocol 'name))
337 "The name of the protocol.")
338 (auth-socket-path
339 (string "/var/run/dovecot/auth-userdb")
340 "UNIX socket path to master authentication server to find users.
341 This is used by imap (for shared users) and lda.")
342 (mail-plugins
343 (space-separated-string-list '("$mail_plugins"))
344 "Space separated list of plugins to load.")
345 (mail-max-userip-connections
346 (non-negative-integer 10)
347 "Maximum number of IMAP connections allowed for a user from each IP
348 address. NOTE: The username is compared case-sensitively."))
349
350 (define (serialize-protocol-configuration field-name val)
351 (format #t "protocol ~a {\n" (protocol-configuration-name val))
352 (serialize-configuration val (cdr protocol-configuration-fields))
353 (format #t "}\n"))
354 (define (protocol-configuration-list? val)
355 (and (list? val) (and-map protocol-configuration? val)))
356 (define (serialize-protocol-configuration-list field-name val)
357 (serialize-field 'protocols
358 (string-join (map protocol-configuration-name val) " "))
359 (for-each (lambda (val)
360 (serialize-protocol-configuration field-name val))
361 val))
362
363 (define-configuration plugin-configuration
364 (entries
365 (free-form-fields '())
366 "A list of key-value pairs that this dict should hold."))
367
368 (define (serialize-plugin-configuration field-name val)
369 (format #t "plugin {\n")
370 (serialize-configuration val plugin-configuration-fields)
371 (format #t "}\n"))
372
373 (define-configuration mailbox-configuration
374 (name
375 (string (error "mailbox name is required"))
376 "Name for this mailbox.")
377
378 (auto
379 (string "no")
380 "@samp{create} will automatically create this mailbox.
381 @samp{subscribe} will both create and subscribe to the mailbox.")
382
383 (special-use
384 (space-separated-string-list '())
385 "List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
386 Valid values are @code{\\All}, @code{\\Archive}, @code{\\Drafts},
387 @code{\\Flagged}, @code{\\Junk}, @code{\\Sent}, and @code{\\Trash}."))
388
389 (define (serialize-mailbox-configuration field-name val)
390 (format #t "mailbox \"~a\" {\n" (mailbox-configuration-name val))
391 (serialize-configuration val (cdr mailbox-configuration-fields))
392 (format #t "}\n"))
393 (define (mailbox-configuration-list? val)
394 (and (list? val) (and-map mailbox-configuration? val)))
395 (define (serialize-mailbox-configuration-list field-name val)
396 (for-each (lambda (val)
397 (serialize-mailbox-configuration field-name val))
398 val))
399
400 (define-configuration namespace-configuration
401 (name
402 (string (error "namespace name is required"))
403 "Name for this namespace.")
404
405 (type
406 (string "private")
407 "Namespace type: @samp{private}, @samp{shared} or @samp{public}.")
408
409 (separator
410 (string "")
411 "Hierarchy separator to use. You should use the same separator for
412 all namespaces or some clients get confused. @samp{/} is usually a good
413 one. The default however depends on the underlying mail storage
414 format.")
415
416 (prefix
417 (string "")
418 "Prefix required to access this namespace. This needs to be
419 different for all namespaces. For example @samp{Public/}.")
420
421 (location
422 (string "")
423 "Physical location of the mailbox. This is in same format as
424 mail_location, which is also the default for it.")
425
426 (inbox?
427 (boolean #f)
428 "There can be only one INBOX, and this setting defines which
429 namespace has it.")
430
431 (hidden?
432 (boolean #f)
433 "If namespace is hidden, it's not advertised to clients via NAMESPACE
434 extension. You'll most likely also want to set @samp{list? #f}. This is mostly
435 useful when converting from another server with different namespaces
436 which you want to deprecate but still keep working. For example you can
437 create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
438 and @samp{mail/}.")
439
440 (list?
441 (boolean #t)
442 "Show the mailboxes under this namespace with LIST command. This
443 makes the namespace visible for clients that don't support NAMESPACE
444 extension. The special @code{children} value lists child mailboxes, but
445 hides the namespace prefix.")
446
447 (subscriptions?
448 (boolean #t)
449 "Namespace handles its own subscriptions. If set to @code{#f}, the
450 parent namespace handles them. The empty prefix should always have this
451 as @code{#t}.)")
452
453 (mailboxes
454 (mailbox-configuration-list '())
455 "List of predefined mailboxes in this namespace."))
456
457 (define (serialize-namespace-configuration field-name val)
458 (format #t "namespace ~a {\n" (namespace-configuration-name val))
459 (serialize-configuration val (cdr namespace-configuration-fields))
460 (format #t "}\n"))
461 (define (list-of-namespace-configuration? val)
462 (and (list? val) (and-map namespace-configuration? val)))
463 (define (serialize-list-of-namespace-configuration field-name val)
464 (for-each (lambda (val)
465 (serialize-namespace-configuration field-name val))
466 val))
467
468 (define-configuration dovecot-configuration
469 (dovecot
470 (package dovecot)
471 "The dovecot package.")
472
473 (listen
474 (comma-separated-string-list '("*" "::"))
475 "A list of IPs or hosts where to listen in for connections. @samp{*}
476 listens in all IPv4 interfaces, @samp{::} listens in all IPv6
477 interfaces. If you want to specify non-default ports or anything more
478 complex, customize the address and port fields of the
479 @samp{inet-listener} of the specific services you are interested in.")
480
481 (protocols
482 (protocol-configuration-list
483 (list (protocol-configuration
484 (name "imap"))))
485 "List of protocols we want to serve. Available protocols include
486 @samp{imap}, @samp{pop3}, and @samp{lmtp}.")
487
488 (services
489 (service-configuration-list
490 (list
491 (service-configuration
492 (kind "imap-login")
493 (client-limit 0)
494 (process-limit 0)
495 (listeners
496 (list
497 (inet-listener-configuration (protocol "imap") (port 143) (ssl? #f))
498 (inet-listener-configuration (protocol "imaps") (port 993) (ssl? #t)))))
499 (service-configuration
500 (kind "pop3-login")
501 (listeners
502 (list
503 (inet-listener-configuration (protocol "pop3") (port 110) (ssl? #f))
504 (inet-listener-configuration (protocol "pop3s") (port 995) (ssl? #t)))))
505 (service-configuration
506 (kind "lmtp")
507 (client-limit 1)
508 (process-limit 0)
509 (listeners
510 (list (unix-listener-configuration (path "lmtp") (mode "0666")))))
511 (service-configuration
512 (kind "imap")
513 (client-limit 1)
514 (process-limit 1024))
515 (service-configuration
516 (kind "pop3")
517 (client-limit 1)
518 (process-limit 1024))
519 (service-configuration
520 (kind "auth")
521 (service-count 0)
522 (client-limit 0)
523 (process-limit 1)
524 (listeners
525 (list (unix-listener-configuration (path "auth-userdb")))))
526 (service-configuration
527 (kind "auth-worker")
528 (client-limit 1)
529 (process-limit 0))
530 (service-configuration
531 (kind "dict")
532 (client-limit 1)
533 (process-limit 0)
534 (listeners (list (unix-listener-configuration (path "dict")))))))
535 "List of services to enable. Available services include @samp{imap},
536 @samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
537 @samp{lmtp}.")
538
539 (dict
540 (dict-configuration (dict-configuration))
541 "Dict configuration, as created by the @code{dict-configuration}
542 constructor.")
543
544 (passdbs
545 (passdb-configuration-list (list (passdb-configuration (driver "pam"))))
546 "List of passdb configurations, each one created by the
547 @code{passdb-configuration} constructor.")
548
549 (userdbs
550 (userdb-configuration-list (list (userdb-configuration (driver "passwd"))))
551 "List of userdb configurations, each one created by the
552 @code{userdb-configuration} constructor.")
553
554 (plugin-configuration
555 (plugin-configuration (plugin-configuration))
556 "Plug-in configuration, created by the @code{plugin-configuration}
557 constructor.")
558
559 (namespaces
560 (list-of-namespace-configuration
561 (list
562 (namespace-configuration
563 (name "inbox")
564 (prefix "")
565 (inbox? #t)
566 (mailboxes
567 (list
568 (mailbox-configuration (name "Drafts") (special-use '("\\Drafts")))
569 (mailbox-configuration (name "Junk") (special-use '("\\Junk")))
570 (mailbox-configuration (name "Trash") (special-use '("\\Trash")))
571 (mailbox-configuration (name "Sent") (special-use '("\\Sent")))
572 (mailbox-configuration (name "Sent Messages") (special-use '("\\Sent")))
573 (mailbox-configuration (name "Drafts") (special-use '("\\Drafts"))))))))
574 "List of namespaces. Each item in the list is created by the
575 @code{namespace-configuration} constructor.")
576
577 (base-dir
578 (file-name "/var/run/dovecot/")
579 "Base directory where to store runtime data.")
580
581 (login-greeting
582 (string "Dovecot ready.")
583 "Greeting message for clients.")
584
585 (login-trusted-networks
586 (space-separated-string-list '())
587 "List of trusted network ranges. Connections from these IPs are
588 allowed to override their IP addresses and ports (for logging and for
589 authentication checks). @samp{disable-plaintext-auth} is also ignored
590 for these networks. Typically you'd specify your IMAP proxy servers
591 here.")
592
593 (login-access-sockets
594 (space-separated-string-list '())
595 "List of login access check sockets (e.g. tcpwrap).")
596
597 (verbose-proctitle?
598 (boolean #f)
599 "Show more verbose process titles (in ps). Currently shows user name
600 and IP address. Useful for seeing who are actually using the IMAP
601 processes (e.g. shared mailboxes or if same uid is used for multiple
602 accounts).")
603
604 (shutdown-clients?
605 (boolean #t)
606 "Should all processes be killed when Dovecot master process shuts down.
607 Setting this to @code{#f} means that Dovecot can be upgraded without
608 forcing existing client connections to close (although that could also
609 be a problem if the upgrade is e.g. because of a security fix).")
610
611 (doveadm-worker-count
612 (non-negative-integer 0)
613 "If non-zero, run mail commands via this many connections to doveadm
614 server, instead of running them directly in the same process.")
615
616 (doveadm-socket-path
617 (string "doveadm-server")
618 "UNIX socket or host:port used for connecting to doveadm server.")
619
620 (import-environment
621 (space-separated-string-list '("TZ"))
622 "List of environment variables that are preserved on Dovecot startup
623 and passed down to all of its child processes. You can also give
624 key=value pairs to always set specific settings.")
625
626 ;;; Authentication processes
627
628 (disable-plaintext-auth?
629 (boolean #t)
630 "Disable LOGIN command and all other plaintext authentications unless
631 SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
632 matches the local IP (i.e. you're connecting from the same computer),
633 the connection is considered secure and plaintext authentication is
634 allowed. See also ssl=required setting.")
635
636 (auth-cache-size
637 (non-negative-integer 0)
638 "Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
639 Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
640 for caching to be used.")
641
642 (auth-cache-ttl
643 (string "1 hour")
644 "Time to live for cached data. After TTL expires the cached record
645 is no longer used, *except* if the main database lookup returns internal
646 failure. We also try to handle password changes automatically: If
647 user's previous authentication was successful, but this one wasn't, the
648 cache isn't used. For now this works only with plaintext
649 authentication.")
650
651 (auth-cache-negative-ttl
652 (string "1 hour")
653 "TTL for negative hits (user not found, password mismatch).
654 0 disables caching them completely.")
655
656 (auth-realms
657 (space-separated-string-list '())
658 "List of realms for SASL authentication mechanisms that need them.
659 You can leave it empty if you don't want to support multiple realms.
660 Many clients simply use the first one listed here, so keep the default
661 realm first.")
662
663 (auth-default-realm
664 (string "")
665 "Default realm/domain to use if none was specified. This is used for
666 both SASL realms and appending @@domain to username in plaintext
667 logins.")
668
669 (auth-username-chars
670 (string
671 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@")
672 "List of allowed characters in username. If the user-given username
673 contains a character not listed in here, the login automatically fails.
674 This is just an extra check to make sure user can't exploit any
675 potential quote escaping vulnerabilities with SQL/LDAP databases. If
676 you want to allow all characters, set this value to empty.")
677
678 (auth-username-translation
679 (string "")
680 "Username character translations before it's looked up from
681 databases. The value contains series of from -> to characters. For
682 example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
683 translated to @samp{@@}.")
684
685 (auth-username-format
686 (string "%Lu")
687 "Username formatting before it's looked up from databases. You can
688 use the standard variables here, e.g. %Lu would lowercase the username,
689 %n would drop away the domain if it was given, or @samp{%n-AT-%d} would
690 change the @samp{@@} into @samp{-AT-}. This translation is done after
691 @samp{auth-username-translation} changes.")
692
693 (auth-master-user-separator
694 (string "")
695 "If you want to allow master users to log in by specifying the master
696 username within the normal username string (i.e. not using SASL
697 mechanism's support for it), you can specify the separator character
698 here. The format is then <username><separator><master username>.
699 UW-IMAP uses @samp{*} as the separator, so that could be a good
700 choice.")
701
702 (auth-anonymous-username
703 (string "anonymous")
704 "Username to use for users logging in with ANONYMOUS SASL
705 mechanism.")
706
707 (auth-worker-max-count
708 (non-negative-integer 30)
709 "Maximum number of dovecot-auth worker processes. They're used to
710 execute blocking passdb and userdb queries (e.g. MySQL and PAM).
711 They're automatically created and destroyed as needed.")
712
713 (auth-gssapi-hostname
714 (string "")
715 "Host name to use in GSSAPI principal names. The default is to use
716 the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
717 allow all keytab entries.")
718
719 (auth-krb5-keytab
720 (string "")
721 "Kerberos keytab to use for the GSSAPI mechanism. Will use the
722 system default (usually /etc/krb5.keytab) if not specified. You may
723 need to change the auth service to run as root to be able to read this
724 file.")
725
726 (auth-use-winbind?
727 (boolean #f)
728 "Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
729 and @samp{ntlm-auth} helper.
730 <doc/wiki/Authentication/Mechanisms/Winbind.txt>.")
731
732 (auth-winbind-helper-path
733 (file-name "/usr/bin/ntlm_auth")
734 "Path for Samba's @samp{ntlm-auth} helper binary.")
735
736 (auth-failure-delay
737 (string "2 secs")
738 "Time to delay before replying to failed authentications.")
739
740 (auth-ssl-require-client-cert?
741 (boolean #f)
742 "Require a valid SSL client certificate or the authentication
743 fails.")
744
745 (auth-ssl-username-from-cert?
746 (boolean #f)
747 "Take the username from client's SSL certificate, using
748 @code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
749 CommonName.")
750
751 (auth-mechanisms
752 (space-separated-string-list '("plain"))
753 "List of wanted authentication mechanisms. Supported mechanisms are:
754 @samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
755 @samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
756 @samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
757 @samp{disable-plaintext-auth} setting.")
758
759 (director-servers
760 (space-separated-string-list '())
761 "List of IPs or hostnames to all director servers, including ourself.
762 Ports can be specified as ip:port. The default port is the same as what
763 director service's @samp{inet-listener} is using.")
764
765 (director-mail-servers
766 (space-separated-string-list '())
767 "List of IPs or hostnames to all backend mail servers. Ranges are
768 allowed too, like 10.0.0.10-10.0.0.30.")
769
770 (director-user-expire
771 (string "15 min")
772 "How long to redirect users to a specific server after it no longer
773 has any connections.")
774
775 (director-username-hash
776 (string "%Lu")
777 "How the username is translated before being hashed. Useful values
778 include %Ln if user can log in with or without @@domain, %Ld if mailboxes
779 are shared within domain.")
780
781 ;;; Log destination.
782
783 (log-path
784 (string "syslog")
785 "Log file to use for error messages. @samp{syslog} logs to syslog,
786 @samp{/dev/stderr} logs to stderr.")
787
788 (info-log-path
789 (string "")
790 "Log file to use for informational messages. Defaults to
791 @samp{log-path}.")
792
793 (debug-log-path
794 (string "")
795 "Log file to use for debug messages. Defaults to
796 @samp{info-log-path}.")
797
798 (syslog-facility
799 (string "mail")
800 "Syslog facility to use if you're logging to syslog. Usually if you
801 don't want to use @samp{mail}, you'll use local0..local7. Also other
802 standard facilities are supported.")
803
804 (auth-verbose?
805 (boolean #f)
806 "Log unsuccessful authentication attempts and the reasons why they
807 failed.")
808
809 (auth-verbose-passwords
810 (string "no")
811 "In case of password mismatches, log the attempted password. Valid
812 values are no, plain and sha1. sha1 can be useful for detecting brute
813 force password attempts vs. user simply trying the same password over
814 and over again. You can also truncate the value to n chars by appending
815 \":n\" (e.g. sha1:6).")
816
817 (auth-debug?
818 (boolean #f)
819 "Even more verbose logging for debugging purposes. Shows for example
820 SQL queries.")
821
822 (auth-debug-passwords?
823 (boolean #f)
824 "In case of password mismatches, log the passwords and used scheme so
825 the problem can be debugged. Enabling this also enables
826 @samp{auth-debug}.")
827
828 (mail-debug?
829 (boolean #f)
830 "Enable mail process debugging. This can help you figure out why
831 Dovecot isn't finding your mails.")
832
833 (verbose-ssl?
834 (boolean #f)
835 "Show protocol level SSL errors.")
836
837 (log-timestamp
838 (string "\"%b %d %H:%M:%S \"")
839 "Prefix for each line written to log file. % codes are in
840 strftime(3) format.")
841
842 (login-log-format-elements
843 (space-separated-string-list
844 '("user=<%u>" "method=%m" "rip=%r" "lip=%l" "mpid=%e" "%c"))
845 "List of elements we want to log. The elements which have a
846 non-empty variable value are joined together to form a comma-separated
847 string.")
848
849 (login-log-format
850 (string "%$: %s")
851 "Login log format. %s contains @samp{login-log-format-elements}
852 string, %$ contains the data we want to log.")
853
854 (mail-log-prefix
855 (string "\"%s(%u)<%{pid}><%{session}>: \"")
856 "Log prefix for mail processes. See doc/wiki/Variables.txt for list
857 of possible variables you can use.")
858
859 (deliver-log-format
860 (string "msgid=%m: %$")
861 "Format to use for logging mail deliveries. You can use variables:
862 @table @code
863 @item %$
864 Delivery status message (e.g. @samp{saved to INBOX})
865 @item %m
866 Message-ID
867 @item %s
868 Subject
869 @item %f
870 From address
871 @item %p
872 Physical size
873 @item %w
874 Virtual size.
875 @end table")
876
877 ;;; Mailbox locations and namespaces
878
879 (mail-location
880 (string "")
881 "Location for users' mailboxes. The default is empty, which means
882 that Dovecot tries to find the mailboxes automatically. This won't work
883 if the user doesn't yet have any mail, so you should explicitly tell
884 Dovecot the full location.
885
886 If you're using mbox, giving a path to the INBOX
887 file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
888 where the other mailboxes are kept. This is called the \"root mail
889 directory\", and it must be the first path given in the
890 @samp{mail-location} setting.
891
892 There are a few special variables you can use, eg.:
893
894 @table @samp
895 @item %u
896 username
897 @item %n
898 user part in user@@domain, same as %u if there's no domain
899 @item %d
900 domain part in user@@domain, empty if there's no domain
901 @item %h
902 home director
903 @end table
904
905 See doc/wiki/Variables.txt for full list. Some examples:
906 @table @samp
907 @item maildir:~/Maildir
908 @item mbox:~/mail:INBOX=/var/mail/%u
909 @item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
910 @end table")
911
912 (mail-uid
913 (string "")
914 "System user and group used to access mails. If you use multiple,
915 userdb can override these by returning uid or gid fields. You can use
916 either numbers or names. <doc/wiki/UserIds.txt>.")
917
918 (mail-gid
919 (string "")
920 "")
921
922 (mail-privileged-group
923 (string "")
924 "Group to enable temporarily for privileged operations. Currently
925 this is used only with INBOX when either its initial creation or
926 dotlocking fails. Typically this is set to \"mail\" to give access to
927 /var/mail.")
928
929 (mail-access-groups
930 (string "")
931 "Grant access to these supplementary groups for mail processes.
932 Typically these are used to set up access to shared mailboxes. Note
933 that it may be dangerous to set these if users can create
934 symlinks (e.g. if \"mail\" group is set here, ln -s /var/mail ~/mail/var
935 could allow a user to delete others' mailboxes, or ln -s
936 /secret/shared/box ~/mail/mybox would allow reading it).")
937
938 (mail-full-filesystem-access?
939 (boolean #f)
940 "Allow full file system access to clients. There's no access checks
941 other than what the operating system does for the active UID/GID. It
942 works with both maildir and mboxes, allowing you to prefix mailboxes
943 names with e.g. /path/ or ~user/.")
944
945 ;;; Mail processes
946
947 (mmap-disable?
948 (boolean #f)
949 "Don't use mmap() at all. This is required if you store indexes to
950 shared file systems (NFS or clustered file system).")
951
952 (dotlock-use-excl?
953 (boolean #t)
954 "Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
955 supports @samp{O_EXCL} since version 3, so this should be safe to use
956 nowadays by default.")
957
958 (mail-fsync
959 (string "optimized")
960 "When to use fsync() or fdatasync() calls:
961 @table @code
962 @item optimized
963 Whenever necessary to avoid losing important data
964 @item always
965 Useful with e.g. NFS when write()s are delayed
966 @item never
967 Never use it (best performance, but crashes can lose data).
968 @end table")
969
970 (mail-nfs-storage?
971 (boolean #f)
972 "Mail storage exists in NFS. Set this to yes to make Dovecot flush
973 NFS caches whenever needed. If you're using only a single mail server
974 this isn't needed.")
975
976 (mail-nfs-index?
977 (boolean #f)
978 "Mail index files also exist in NFS. Setting this to yes requires
979 @samp{mmap-disable? #t} and @samp{fsync-disable? #f}.")
980
981 (lock-method
982 (string "fcntl")
983 "Locking method for index files. Alternatives are fcntl, flock and
984 dotlock. Dotlocking uses some tricks which may create more disk I/O
985 than other locking methods. NFS users: flock doesn't work, remember to
986 change @samp{mmap-disable}.")
987
988 (mail-temp-dir
989 (file-name "/tmp")
990 "Directory in which LDA/LMTP temporarily stores incoming mails >128
991 kB.")
992
993 (first-valid-uid
994 (non-negative-integer 500)
995 "Valid UID range for users. This is mostly to make sure that users can't
996 log in as daemons or other system users. Note that denying root logins is
997 hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
998 is set to 0.")
999
1000 (last-valid-uid
1001 (non-negative-integer 0)
1002 "")
1003
1004 (first-valid-gid
1005 (non-negative-integer 1)
1006 "Valid GID range for users. Users having non-valid GID as primary group ID
1007 aren't allowed to log in. If user belongs to supplementary groups with
1008 non-valid GIDs, those groups are not set.")
1009
1010 (last-valid-gid
1011 (non-negative-integer 0)
1012 "")
1013
1014 (mail-max-keyword-length
1015 (non-negative-integer 50)
1016 "Maximum allowed length for mail keyword name. It's only forced when
1017 trying to create new keywords.")
1018
1019 (valid-chroot-dirs
1020 (colon-separated-file-name-list '())
1021 "List of directories under which chrooting is allowed for mail
1022 processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
1023 too). This setting doesn't affect @samp{login-chroot}
1024 @samp{mail-chroot} or auth chroot settings. If this setting is empty,
1025 \"/./\" in home dirs are ignored. WARNING: Never add directories here
1026 which local users can modify, that may lead to root exploit. Usually
1027 this should be done only if you don't allow shell access for users.
1028 <doc/wiki/Chrooting.txt>.")
1029
1030 (mail-chroot
1031 (string "")
1032 "Default chroot directory for mail processes. This can be overridden
1033 for specific users in user database by giving /./ in user's home
1034 directory (e.g. /home/./user chroots into /home). Note that usually
1035 there is no real need to do chrooting, Dovecot doesn't allow users to
1036 access files outside their mail directory anyway. If your home
1037 directories are prefixed with the chroot directory, append \"/.\" to
1038 @samp{mail-chroot}. <doc/wiki/Chrooting.txt>.")
1039
1040 (auth-socket-path
1041 (file-name "/var/run/dovecot/auth-userdb")
1042 "UNIX socket path to master authentication server to find users.
1043 This is used by imap (for shared users) and lda.")
1044
1045 (mail-plugin-dir
1046 (file-name "/usr/lib/dovecot")
1047 "Directory where to look up mail plugins.")
1048
1049 (mail-plugins
1050 (space-separated-string-list '())
1051 "List of plugins to load for all services. Plugins specific to IMAP,
1052 LDA, etc. are added to this list in their own .conf files.")
1053
1054
1055 (mail-cache-min-mail-count
1056 (non-negative-integer 0)
1057 "The minimum number of mails in a mailbox before updates are done to
1058 cache file. This allows optimizing Dovecot's behavior to do less disk
1059 writes at the cost of more disk reads.")
1060
1061 (mailbox-idle-check-interval
1062 (string "30 secs")
1063 "When IDLE command is running, mailbox is checked once in a while to
1064 see if there are any new mails or other changes. This setting defines
1065 the minimum time to wait between those checks. Dovecot can also use
1066 dnotify, inotify and kqueue to find out immediately when changes
1067 occur.")
1068
1069 (mail-save-crlf?
1070 (boolean #f)
1071 "Save mails with CR+LF instead of plain LF. This makes sending those
1072 mails take less CPU, especially with sendfile() syscall with Linux and
1073 FreeBSD. But it also creates a bit more disk I/O which may just make it
1074 slower. Also note that if other software reads the mboxes/maildirs,
1075 they may handle the extra CRs wrong and cause problems.")
1076
1077 (maildir-stat-dirs?
1078 (boolean #f)
1079 "By default LIST command returns all entries in maildir beginning
1080 with a dot. Enabling this option makes Dovecot return only entries
1081 which are directories. This is done by stat()ing each entry, so it
1082 causes more disk I/O.
1083 (For systems setting struct @samp{dirent->d_type} this check is free
1084 and it's done always regardless of this setting).")
1085
1086 (maildir-copy-with-hardlinks?
1087 (boolean #t)
1088 "When copying a message, do it with hard links whenever possible.
1089 This makes the performance much better, and it's unlikely to have any
1090 side effects.")
1091
1092 (maildir-very-dirty-syncs?
1093 (boolean #f)
1094 "Assume Dovecot is the only MUA accessing Maildir: Scan cur/
1095 directory only when its mtime changes unexpectedly or when we can't find
1096 the mail otherwise.")
1097
1098 (mbox-read-locks
1099 (space-separated-string-list '("fcntl"))
1100 "Which locking methods to use for locking mbox. There are four
1101 available:
1102
1103 @table @code
1104 @item dotlock
1105 Create <mailbox>.lock file. This is the oldest and most NFS-safe
1106 solution. If you want to use /var/mail/ like directory, the users will
1107 need write access to that directory.
1108 @item dotlock-try
1109 Same as dotlock, but if it fails because of permissions or because there
1110 isn't enough disk space, just skip it.
1111 @item fcntl
1112 Use this if possible. Works with NFS too if lockd is used.
1113 @item flock
1114 May not exist in all systems. Doesn't work with NFS.
1115 @item lockf
1116 May not exist in all systems. Doesn't work with NFS.
1117 @end table
1118
1119 You can use multiple locking methods; if you do the order they're declared
1120 in is important to avoid deadlocks if other MTAs/MUAs are using multiple
1121 locking methods as well. Some operating systems don't allow using some of
1122 them simultaneously.")
1123
1124 (mbox-write-locks
1125 (space-separated-string-list '("dotlock" "fcntl"))
1126 "")
1127
1128 (mbox-lock-timeout
1129 (string "5 mins")
1130 "Maximum time to wait for lock (all of them) before aborting.")
1131
1132 (mbox-dotlock-change-timeout
1133 (string "2 mins")
1134 "If dotlock exists but the mailbox isn't modified in any way,
1135 override the lock file after this much time.")
1136
1137 (mbox-dirty-syncs?
1138 (boolean #t)
1139 "When mbox changes unexpectedly we have to fully read it to find out
1140 what changed. If the mbox is large this can take a long time. Since
1141 the change is usually just a newly appended mail, it'd be faster to
1142 simply read the new mails. If this setting is enabled, Dovecot does
1143 this but still safely fallbacks to re-reading the whole mbox file
1144 whenever something in mbox isn't how it's expected to be. The only real
1145 downside to this setting is that if some other MUA changes message
1146 flags, Dovecot doesn't notice it immediately. Note that a full sync is
1147 done with SELECT, EXAMINE, EXPUNGE and CHECK commands.")
1148
1149 (mbox-very-dirty-syncs?
1150 (boolean #f)
1151 "Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
1152 EXAMINE, EXPUNGE or CHECK commands. If this is set,
1153 @samp{mbox-dirty-syncs} is ignored.")
1154
1155 (mbox-lazy-writes?
1156 (boolean #t)
1157 "Delay writing mbox headers until doing a full write sync (EXPUNGE
1158 and CHECK commands and when closing the mailbox). This is especially
1159 useful for POP3 where clients often delete all mails. The downside is
1160 that our changes aren't immediately visible to other MUAs.")
1161
1162 (mbox-min-index-size
1163 (non-negative-integer 0)
1164 "If mbox size is smaller than this (e.g. 100k), don't write index
1165 files. If an index file already exists it's still read, just not
1166 updated.")
1167
1168 (mdbox-rotate-size
1169 (non-negative-integer #e10e6)
1170 "Maximum dbox file size until it's rotated.")
1171
1172 (mdbox-rotate-interval
1173 (string "1d")
1174 "Maximum dbox file age until it's rotated. Typically in days. Day
1175 begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
1176 disabled.")
1177
1178 (mdbox-preallocate-space?
1179 (boolean #f)
1180 "When creating new mdbox files, immediately preallocate their size to
1181 @samp{mdbox-rotate-size}. This setting currently works only in Linux
1182 with some file systems (ext4, xfs).")
1183
1184 (mail-attachment-dir
1185 (string "")
1186 "sdbox and mdbox support saving mail attachments to external files,
1187 which also allows single instance storage for them. Other backends
1188 don't support this for now.
1189
1190 WARNING: This feature hasn't been tested much yet. Use at your own risk.
1191
1192 Directory root where to store mail attachments. Disabled, if empty.")
1193
1194 (mail-attachment-min-size
1195 (non-negative-integer #e128e3)
1196 "Attachments smaller than this aren't saved externally. It's also
1197 possible to write a plugin to disable saving specific attachments
1198 externally.")
1199
1200 (mail-attachment-fs
1201 (string "sis posix")
1202 "File system backend to use for saving attachments:
1203 @table @code
1204 @item posix
1205 No SiS done by Dovecot (but this might help FS's own deduplication)
1206 @item sis posix
1207 SiS with immediate byte-by-byte comparison during saving
1208 @item sis-queue posix
1209 SiS with delayed comparison and deduplication.
1210 @end table")
1211
1212 (mail-attachment-hash
1213 (string "%{sha1}")
1214 "Hash format to use in attachment filenames. You can add any text and
1215 variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
1216 @code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
1217 truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.")
1218
1219 (default-process-limit
1220 (non-negative-integer 100)
1221 "")
1222
1223 (default-client-limit
1224 (non-negative-integer 1000)
1225 "")
1226
1227 (default-vsz-limit
1228 (non-negative-integer #e256e6)
1229 "Default VSZ (virtual memory size) limit for service processes.
1230 This is mainly intended to catch and kill processes that leak memory
1231 before they eat up everything.")
1232
1233 (default-login-user
1234 (string "dovenull")
1235 "Login user is internally used by login processes. This is the most
1236 untrusted user in Dovecot system. It shouldn't have access to anything
1237 at all.")
1238
1239 (default-internal-user
1240 (string "dovecot")
1241 "Internal user is used by unprivileged processes. It should be
1242 separate from login user, so that login processes can't disturb other
1243 processes.")
1244
1245 (ssl?
1246 (string "required")
1247 "SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.")
1248
1249 (ssl-cert
1250 (string "</etc/dovecot/default.pem")
1251 "PEM encoded X.509 SSL/TLS certificate (public key).")
1252
1253 (ssl-key
1254 (string "</etc/dovecot/private/default.pem")
1255 "PEM encoded SSL/TLS private key. The key is opened before
1256 dropping root privileges, so keep the key file unreadable by anyone but
1257 root.")
1258
1259 (ssl-key-password
1260 (string "")
1261 "If key file is password protected, give the password here.
1262 Alternatively give it when starting dovecot with -p parameter. Since
1263 this file is often world-readable, you may want to place this setting
1264 instead to a different.")
1265
1266 (ssl-ca
1267 (string "")
1268 "PEM encoded trusted certificate authority. Set this only if you
1269 intend to use @samp{ssl-verify-client-cert? #t}. The file should
1270 contain the CA certificate(s) followed by the matching
1271 CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).")
1272 (ssl-require-crl?
1273 (boolean #t)
1274 "Require that CRL check succeeds for client certificates.")
1275 (ssl-verify-client-cert?
1276 (boolean #f)
1277 "Request client to send a certificate. If you also want to require
1278 it, set @samp{auth-ssl-require-client-cert? #t} in auth section.")
1279
1280 (ssl-cert-username-field
1281 (string "commonName")
1282 "Which field from certificate to use for username. commonName and
1283 x500UniqueIdentifier are the usual choices. You'll also need to set
1284 @samp{auth-ssl-username-from-cert? #t}.")
1285
1286 (ssl-min-protocol
1287 (string "TLSv1")
1288 "Minimum SSL protocol version to accept.")
1289
1290 (ssl-cipher-list
1291 (string "ALL:!kRSA:!SRP:!kDHd:!DSS:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK:!RC4:!ADH:!LOW@STRENGTH")
1292 "SSL ciphers to use.")
1293
1294 (ssl-crypto-device
1295 (string "")
1296 "SSL crypto device to use, for valid values run \"openssl engine\".")
1297
1298 (postmaster-address
1299 (string "postmaster@%d")
1300 "Address to use when sending rejection mails.
1301 Default is postmaster@@<your domain>. %d expands to recipient domain.")
1302
1303 (hostname
1304 (string "")
1305 "Hostname to use in various parts of sent mails (e.g. in Message-Id)
1306 and in LMTP replies. Default is the system's real hostname@@domain.")
1307
1308 (quota-full-tempfail?
1309 (boolean #f)
1310 "If user is over quota, return with temporary failure instead of
1311 bouncing the mail.")
1312
1313 (sendmail-path
1314 (file-name "/usr/sbin/sendmail")
1315 "Binary to use for sending mails.")
1316
1317 (submission-host
1318 (string "")
1319 "If non-empty, send mails via this SMTP host[:port] instead of
1320 sendmail.")
1321
1322 (rejection-subject
1323 (string "Rejected: %s")
1324 "Subject: header to use for rejection mails. You can use the same
1325 variables as for @samp{rejection-reason} below.")
1326
1327 (rejection-reason
1328 (string "Your message to <%t> was automatically rejected:%n%r")
1329 "Human readable error message for rejection mails. You can use
1330 variables:
1331
1332 @table @code
1333 @item %n
1334 CRLF
1335 @item %r
1336 reason
1337 @item %s
1338 original subject
1339 @item %t
1340 recipient
1341 @end table")
1342
1343 (recipient-delimiter
1344 (string "+")
1345 "Delimiter character between local-part and detail in email
1346 address.")
1347
1348 (lda-original-recipient-header
1349 (string "")
1350 "Header where the original recipient address (SMTP's RCPT TO:
1351 address) is taken from if not available elsewhere. With dovecot-lda -a
1352 parameter overrides this. A commonly used header for this is
1353 X-Original-To.")
1354
1355 (lda-mailbox-autocreate?
1356 (boolean #f)
1357 "Should saving a mail to a nonexistent mailbox automatically create
1358 it?.")
1359
1360 (lda-mailbox-autosubscribe?
1361 (boolean #f)
1362 "Should automatically created mailboxes be also automatically
1363 subscribed?.")
1364
1365
1366 (imap-max-line-length
1367 (non-negative-integer #e64e3)
1368 "Maximum IMAP command line length. Some clients generate very long
1369 command lines with huge mailboxes, so you may need to raise this if you
1370 get \"Too long argument\" or \"IMAP command line too large\" errors
1371 often.")
1372
1373 (imap-logout-format
1374 (string "in=%i out=%o deleted=%{deleted} expunged=%{expunged} trashed=%{trashed} hdr_count=%{fetch_hdr_count} hdr_bytes=%{fetch_hdr_bytes} body_count=%{fetch_body_count} body_bytes=%{fetch_body_bytes}")
1375 "IMAP logout format string:
1376 @table @code
1377 @item %i
1378 total number of bytes read from client
1379 @item %o
1380 total number of bytes sent to client.
1381 @end table
1382 See @file{doc/wiki/Variables.txt} for a list of all the variables you can use.")
1383
1384 (imap-capability
1385 (string "")
1386 "Override the IMAP CAPABILITY response. If the value begins with '+',
1387 add the given capabilities on top of the defaults (e.g. +XFOO XBAR).")
1388
1389 (imap-idle-notify-interval
1390 (string "2 mins")
1391 "How long to wait between \"OK Still here\" notifications when client
1392 is IDLEing.")
1393
1394 (imap-id-send
1395 (string "")
1396 "ID field names and values to send to clients. Using * as the value
1397 makes Dovecot use the default value. The following fields have default
1398 values currently: name, version, os, os-version, support-url,
1399 support-email.")
1400
1401 (imap-id-log
1402 (string "")
1403 "ID fields sent by client to log. * means everything.")
1404
1405 (imap-client-workarounds
1406 (space-separated-string-list '())
1407 "Workarounds for various client bugs:
1408
1409 @table @code
1410 @item delay-newmail
1411 Send EXISTS/RECENT new mail notifications only when replying to NOOP and
1412 CHECK commands. Some clients ignore them otherwise, for example OSX
1413 Mail (<v2.1). Outlook Express breaks more badly though, without this it
1414 may show user \"Message no longer in server\" errors. Note that OE6
1415 still breaks even with this workaround if synchronization is set to
1416 \"Headers Only\".
1417
1418 @item tb-extra-mailbox-sep
1419 Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
1420 adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
1421 ignore the extra @samp{/} instead of treating it as invalid mailbox name.
1422
1423 @item tb-lsub-flags
1424 Show \\Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
1425 This makes Thunderbird realize they aren't selectable and show them
1426 greyed out, instead of only later giving \"not selectable\" popup error.
1427 @end table
1428 ")
1429
1430 (imap-urlauth-host
1431 (string "")
1432 "Host allowed in URLAUTH URLs sent by client. \"*\" allows all.") )
1433
1434 (define-configuration opaque-dovecot-configuration
1435 (dovecot
1436 (package dovecot)
1437 "The dovecot package.")
1438
1439 (string
1440 (string (configuration-missing-field 'opaque-dovecot-configuration
1441 'string))
1442 "The contents of the @code{dovecot.conf} to use."))
1443
1444 (define %dovecot-accounts
1445 ;; Account and group for the Dovecot daemon.
1446 (list (user-group (name "dovecot") (system? #t))
1447 (user-account
1448 (name "dovecot")
1449 (group "dovecot")
1450 (system? #t)
1451 (comment "Dovecot daemon user")
1452 (home-directory "/var/empty")
1453 (shell (file-append shadow "/sbin/nologin")))
1454
1455 (user-group (name "dovenull") (system? #t))
1456 (user-account
1457 (name "dovenull")
1458 (group "dovenull")
1459 (system? #t)
1460 (comment "Dovecot daemon login user")
1461 (home-directory "/var/empty")
1462 (shell (file-append shadow "/sbin/nologin")))))
1463
1464 (define (%dovecot-activation config)
1465 ;; Activation gexp.
1466 (let ((config-str
1467 (cond
1468 ((opaque-dovecot-configuration? config)
1469 (opaque-dovecot-configuration-string config))
1470 (else
1471 (with-output-to-string
1472 (lambda ()
1473 (serialize-configuration config
1474 dovecot-configuration-fields)))))))
1475 #~(begin
1476 (use-modules (guix build utils))
1477 (define (mkdir-p/perms directory owner perms)
1478 (mkdir-p directory)
1479 (chown "/var/run/dovecot" (passwd:uid owner) (passwd:gid owner))
1480 (chmod directory perms))
1481 (define (build-subject parameters)
1482 (string-concatenate
1483 (map (lambda (pair)
1484 (let ((k (car pair)) (v (cdr pair)))
1485 (define (escape-char str chr)
1486 (string-join (string-split str chr) (string #\\ chr)))
1487 (string-append "/" k "="
1488 (escape-char (escape-char v #\=) #\/))))
1489 (filter (lambda (pair) (cdr pair)) parameters))))
1490 (define* (create-self-signed-certificate-if-absent
1491 #:key private-key public-key (owner (getpwnam "root"))
1492 (common-name (gethostname))
1493 (organization-name "Guix")
1494 (organization-unit-name "Default Self-Signed Certificate")
1495 (subject-parameters `(("CN" . ,common-name)
1496 ("O" . ,organization-name)
1497 ("OU" . ,organization-unit-name)))
1498 (subject (build-subject subject-parameters)))
1499 ;; Note that by default, OpenSSL outputs keys in PEM format. This
1500 ;; is what we want.
1501 (unless (file-exists? private-key)
1502 (cond
1503 ((zero? (system* (string-append #$openssl "/bin/openssl")
1504 "genrsa" "-out" private-key "2048"))
1505 (chown private-key (passwd:uid owner) (passwd:gid owner))
1506 (chmod private-key #o400))
1507 (else
1508 (format (current-error-port)
1509 "Failed to create private key at ~a.\n" private-key))))
1510 (unless (file-exists? public-key)
1511 (cond
1512 ((zero? (system* (string-append #$openssl "/bin/openssl")
1513 "req" "-new" "-x509" "-key" private-key
1514 "-out" public-key "-days" "3650"
1515 "-batch" "-subj" subject))
1516 (chown public-key (passwd:uid owner) (passwd:gid owner))
1517 (chmod public-key #o444))
1518 (else
1519 (format (current-error-port)
1520 "Failed to create public key at ~a.\n" public-key)))))
1521 (let ((user (getpwnam "dovecot")))
1522 (mkdir-p/perms "/var/run/dovecot" user #o755)
1523 (mkdir-p/perms "/var/lib/dovecot" user #o755)
1524 (mkdir-p/perms "/etc/dovecot" user #o755)
1525 (copy-file #$(plain-file "dovecot.conf" config-str)
1526 "/etc/dovecot/dovecot.conf")
1527 (mkdir-p/perms "/etc/dovecot/private" user #o700)
1528 (create-self-signed-certificate-if-absent
1529 #:private-key "/etc/dovecot/private/default.pem"
1530 #:public-key "/etc/dovecot/default.pem"
1531 #:owner (getpwnam "root")
1532 #:common-name (format #f "Dovecot service on ~a" (gethostname)))))))
1533
1534 (define (dovecot-shepherd-service config)
1535 "Return a list of <shepherd-service> for CONFIG."
1536 (let ((dovecot (if (opaque-dovecot-configuration? config)
1537 (opaque-dovecot-configuration-dovecot config)
1538 (dovecot-configuration-dovecot config))))
1539 (list (shepherd-service
1540 (documentation "Run the Dovecot POP3/IMAP mail server.")
1541 (provision '(dovecot))
1542 (requirement '(networking))
1543 (start #~(make-forkexec-constructor
1544 (list (string-append #$dovecot "/sbin/dovecot")
1545 "-F")))
1546 (stop #~(make-forkexec-constructor
1547 (list (string-append #$dovecot "/sbin/dovecot")
1548 "stop")))))))
1549
1550 (define %dovecot-pam-services
1551 (list (unix-pam-service "dovecot")))
1552
1553 (define dovecot-service-type
1554 (service-type (name 'dovecot)
1555 (extensions
1556 (list (service-extension shepherd-root-service-type
1557 dovecot-shepherd-service)
1558 (service-extension account-service-type
1559 (const %dovecot-accounts))
1560 (service-extension pam-root-service-type
1561 (const %dovecot-pam-services))
1562 (service-extension activation-service-type
1563 %dovecot-activation)))))
1564
1565 (define* (dovecot-service #:key (config (dovecot-configuration)))
1566 "Return a service that runs @command{dovecot}, a mail server that can run
1567 POP3, IMAP, and LMTP. @var{config} should be a configuration object created
1568 by @code{dovecot-configuration}. @var{config} may also be created by
1569 @code{opaque-dovecot-configuration}, which allows specification of the
1570 @code{dovecot.conf} as a string."
1571 (validate-configuration config
1572 (if (opaque-dovecot-configuration? config)
1573 opaque-dovecot-configuration-fields
1574 dovecot-configuration-fields))
1575 (service dovecot-service-type config))
1576
1577 ;; A little helper to make it easier to document all those fields.
1578 (define (generate-dovecot-documentation)
1579 (generate-documentation
1580 `((dovecot-configuration
1581 ,dovecot-configuration-fields
1582 (dict dict-configuration)
1583 (namespaces namespace-configuration)
1584 (plugin plugin-configuration)
1585 (passdbs passdb-configuration)
1586 (userdbs userdb-configuration)
1587 (services service-configuration)
1588 (protocols protocol-configuration))
1589 (dict-configuration ,dict-configuration-fields)
1590 (plugin-configuration ,plugin-configuration-fields)
1591 (passdb-configuration ,passdb-configuration-fields)
1592 (userdb-configuration ,userdb-configuration-fields)
1593 (unix-listener-configuration ,unix-listener-configuration-fields)
1594 (fifo-listener-configuration ,fifo-listener-configuration-fields)
1595 (inet-listener-configuration ,inet-listener-configuration-fields)
1596 (namespace-configuration
1597 ,namespace-configuration-fields
1598 (mailboxes mailbox-configuration))
1599 (mailbox-configuration ,mailbox-configuration-fields)
1600 (service-configuration
1601 ,service-configuration-fields
1602 (listeners unix-listener-configuration fifo-listener-configuration
1603 inet-listener-configuration))
1604 (protocol-configuration ,protocol-configuration-fields))
1605 'dovecot-configuration))
1606
1607 \f
1608 ;;;
1609 ;;; OpenSMTPD.
1610 ;;;
1611
1612 (define-record-type* <opensmtpd-configuration>
1613 opensmtpd-configuration make-opensmtpd-configuration
1614 opensmtpd-configuration?
1615 (package opensmtpd-configuration-package
1616 (default opensmtpd))
1617 (config-file opensmtpd-configuration-config-file
1618 (default %default-opensmtpd-config-file)))
1619
1620 (define %default-opensmtpd-config-file
1621 (plain-file "smtpd.conf" "
1622 listen on lo
1623 accept from any for local deliver to mbox
1624 accept from local for any relay
1625 "))
1626
1627 (define opensmtpd-shepherd-service
1628 (match-lambda
1629 (($ <opensmtpd-configuration> package config-file)
1630 (list (shepherd-service
1631 (provision '(smtpd))
1632 (requirement '(loopback))
1633 (documentation "Run the OpenSMTPD daemon.")
1634 (start (let ((smtpd (file-append package "/sbin/smtpd")))
1635 #~(make-forkexec-constructor
1636 (list #$smtpd "-f" #$config-file)
1637 #:pid-file "/var/run/smtpd.pid")))
1638 (stop #~(make-kill-destructor)))))))
1639
1640 (define %opensmtpd-accounts
1641 (list (user-group
1642 (name "smtpq")
1643 (system? #t))
1644 (user-account
1645 (name "smtpd")
1646 (group "nogroup")
1647 (system? #t)
1648 (comment "SMTP Daemon")
1649 (home-directory "/var/empty")
1650 (shell (file-append shadow "/sbin/nologin")))
1651 (user-account
1652 (name "smtpq")
1653 (group "smtpq")
1654 (system? #t)
1655 (comment "SMTPD Queue")
1656 (home-directory "/var/empty")
1657 (shell (file-append shadow "/sbin/nologin")))))
1658
1659 (define opensmtpd-activation
1660 (match-lambda
1661 (($ <opensmtpd-configuration> package config-file)
1662 (let ((smtpd (file-append package "/sbin/smtpd")))
1663 #~(begin
1664 (use-modules (guix build utils))
1665 ;; Create mbox and spool directories.
1666 (mkdir-p "/var/mail")
1667 (mkdir-p "/var/spool/smtpd")
1668 (chmod "/var/spool/smtpd" #o711))))))
1669
1670 (define opensmtpd-service-type
1671 (service-type
1672 (name 'opensmtpd)
1673 (extensions
1674 (list (service-extension account-service-type
1675 (const %opensmtpd-accounts))
1676 (service-extension activation-service-type
1677 opensmtpd-activation)
1678 (service-extension profile-service-type
1679 (compose list opensmtpd-configuration-package))
1680 (service-extension shepherd-root-service-type
1681 opensmtpd-shepherd-service)))))
1682
1683 \f
1684 ;;;
1685 ;;; mail aliases.
1686 ;;;
1687
1688 (define (mail-aliases-etc aliases)
1689 `(("aliases" ,(plain-file "aliases"
1690 ;; Ideally we'd use a format string like
1691 ;; "~:{~a: ~{~a~^,~}\n~}", but it gives a
1692 ;; warning that I can't figure out how to fix,
1693 ;; so we'll just use string-join below instead.
1694 (format #f "~:{~a: ~a\n~}"
1695 (map (match-lambda
1696 ((alias addresses ...)
1697 (list alias (string-join addresses ","))))
1698 aliases))))))
1699
1700 (define mail-aliases-service-type
1701 (service-type
1702 (name 'mail-aliases)
1703 (extensions
1704 (list (service-extension etc-service-type mail-aliases-etc)))
1705 (compose concatenate)
1706 (extend append)))
1707
1708 \f
1709 ;;;
1710 ;;; Exim.
1711 ;;;
1712
1713 (define-record-type* <exim-configuration> exim-configuration
1714 make-exim-configuration
1715 exim-configuration?
1716 (package exim-configuration-package ;<package>
1717 (default exim))
1718 (config-file exim-configuration-config-file ;file-like
1719 (default #f)))
1720
1721 (define %exim-accounts
1722 (list (user-group
1723 (name "exim")
1724 (system? #t))
1725 (user-account
1726 (name "exim")
1727 (group "exim")
1728 (system? #t)
1729 (comment "Exim Daemon")
1730 (home-directory "/var/empty")
1731 (shell (file-append shadow "/sbin/nologin")))))
1732
1733 (define (exim-computed-config-file package config-file)
1734 (computed-file "exim.conf"
1735 #~(call-with-output-file #$output
1736 (lambda (port)
1737 (format port "
1738 exim_user = exim
1739 exim_group = exim
1740 .include ~a"
1741 #$(or config-file
1742 (file-append package "/etc/exim.conf")))))))
1743
1744 (define exim-shepherd-service
1745 (match-lambda
1746 (($ <exim-configuration> package config-file)
1747 (list (shepherd-service
1748 (provision '(exim mta))
1749 (documentation "Run the exim daemon.")
1750 (requirement '(networking))
1751 (start #~(make-forkexec-constructor
1752 '(#$(file-append package "/bin/exim")
1753 "-bd" "-v" "-C"
1754 #$(exim-computed-config-file package config-file))))
1755 (stop #~(make-kill-destructor)))))))
1756
1757 (define exim-activation
1758 (match-lambda
1759 (($ <exim-configuration> package config-file)
1760 (with-imported-modules '((guix build utils))
1761 #~(begin
1762 (use-modules (guix build utils))
1763
1764 (let ((uid (passwd:uid (getpw "exim")))
1765 (gid (group:gid (getgr "exim"))))
1766 (mkdir-p "/var/spool/exim")
1767 (chown "/var/spool/exim" uid gid))
1768
1769 (zero? (system* #$(file-append package "/bin/exim")
1770 "-bV" "-C" #$(exim-computed-config-file package config-file))))))))
1771
1772 (define exim-profile
1773 (compose list exim-configuration-package))
1774
1775 (define exim-service-type
1776 (service-type
1777 (name 'exim)
1778 (extensions
1779 (list (service-extension shepherd-root-service-type exim-shepherd-service)
1780 (service-extension account-service-type (const %exim-accounts))
1781 (service-extension activation-service-type exim-activation)
1782 (service-extension profile-service-type exim-profile)
1783 (service-extension mail-aliases-service-type (const '()))))))
1784
1785 \f
1786 ;;;
1787 ;;; GNU Mailutils IMAP4 Daemon.
1788 ;;;
1789
1790 (define %default-imap4d-config-file
1791 (plain-file "imap4d.conf" "server localhost {};\n"))
1792
1793 (define-record-type* <imap4d-configuration>
1794 imap4d-configuration make-imap4d-configuration imap4d-configuration?
1795 (package imap4d-configuration-package
1796 (default mailutils))
1797 (config-file imap4d-configuration-config-file
1798 (default %default-imap4d-config-file)))
1799
1800 (define imap4d-shepherd-service
1801 (match-lambda
1802 (($ <imap4d-configuration> package config-file)
1803 (list (shepherd-service
1804 (provision '(imap4d))
1805 (requirement '(networking syslogd))
1806 (documentation "Run the imap4d daemon.")
1807 (start (let ((imap4d (file-append package "/sbin/imap4d")))
1808 #~(make-forkexec-constructor
1809 (list #$imap4d "--daemon" "--foreground"
1810 "--config-file" #$config-file))))
1811 (stop #~(make-kill-destructor)))))))
1812
1813 (define imap4d-service-type
1814 (service-type
1815 (name 'imap4d)
1816 (description
1817 "Run the GNU @command{imap4d} to serve e-mail messages through IMAP.")
1818 (extensions
1819 (list (service-extension
1820 shepherd-root-service-type imap4d-shepherd-service)))
1821 (default-value (imap4d-configuration))))