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