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