mail.scm 62 KB

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