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