mail.scm 62 KB

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