mail.scm 70 KB

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