mail.scm 62 KB

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