1 (* HCoop
Domtool (http
://hcoop
.sourceforge
.net
/)
2 * Copyright (c
) 2006, Adam Chlipala
4 * This program is free software
; you can redistribute it
and/or
5 * modify it under the terms
of the GNU General Public License
6 * as published by the Free Software Foundation
; either version
2
7 * of the License
, or (at your option
) any later version
.
9 * This program is distributed
in the hope that it will be useful
,
10 * but WITHOUT ANY WARRANTY
; without even the implied warranty
of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
. See the
12 * GNU General Public License for more details
.
14 * You should have received a copy
of the GNU General Public License
15 * along
with this program
; if not
, write to the Free Software
16 * Foundation
, Inc
., 51 Franklin Street
, Fifth Floor
, Boston
, MA
02110-1301, USA
.
19 (* Exim MTA handling
*)
21 structure Exim
:> EXIM
= struct
25 val dl
= ErrorMsg
.dummyLoc
27 val _
= Defaults
.registerDefault ("MailNodes",
28 (TList (TBase
"mail_node", dl
), dl
),
29 (fn () => (EList (map (fn s
=> (EString s
, dl
)) Config
.Exim
.aliasTo
), dl
)))
31 val aliasesChanged
= ref
false
32 val aliasesDefaultChanged
= ref
false
33 val hostsChanged
= ref
false
34 val relayHostsChanged
= ref
false
36 val () = Slave
.registerPreHandler
37 (fn () => (aliasesChanged
:= false;
38 aliasesDefaultChanged
:= false;
39 hostsChanged
:= false))
41 val () = Slave
.registerFileHandler (fn fs
=>
43 val spl
= OS
.Path
.splitDirFile (#file fs
)
45 if #file spl
= "aliases" then
46 aliasesChanged
:= true
47 else if #file spl
= "aliases.default" then
48 aliasesDefaultChanged
:= true
49 else if #file spl
= "mail" then
51 else if #file spl
= "mail.relay" then
52 relayHostsChanged
:= true
57 val () = Slave
.registerPostHandler
59 (if !aliasesChanged
then
60 Slave
.concatTo (fn s
=> s
= "aliases") Config
.Exim
.aliases
63 if !aliasesDefaultChanged
then
64 Slave
.concatTo (fn s
=> s
= "aliases.default") Config
.Exim
.aliasesDefault
68 Slave
.enumerateTo (fn s
=> s
= "mail") ":" Config
.Exim
.handleDomains
71 if !relayHostsChanged
then
72 Slave
.enumerateTo (fn s
=> s
= "mail.relay") ":" Config
.Exim
.relayDomains
75 if !aliasesChanged
orelse !aliasesDefaultChanged
76 orelse !hostsChanged
orelse !relayHostsChanged
then
77 Slave
.shellF ([Config
.Exim
.reload
],
78 fn cl
=> "Error reloading exim with " ^ cl
)
83 val () = Env
.actionV_none
"handleMail"
86 val nodes
= Env
.env (Env
.list Env
.string) (env
, "MailNodes")
88 app (fn node
=> #close
89 (Domain
.domainsFile
{node
= node
,
90 name
= "mail"}) ()) nodes
93 val () = Env
.actionV_none
"relayMail"
96 val nodes
= Env
.env (Env
.list Env
.string) (env
, "MailNodes")
98 app (fn node
=> #close
99 (Domain
.domainsFile
{node
= node
,
100 name
= "mail.relay"}) ()) nodes
103 val () = Domain
.registerDescriber (Domain
.considerAll
104 [Domain
.Filename
{filename
= "aliases",
105 heading
= "E-mail aliases",
107 Domain
.Filename
{filename
= "aliases.default",
108 heading
= "Default e-mail alias",
110 Domain
.Filename
{filename
= "mail",
111 heading
= "E-mail handling",
113 Domain
.Filename
{filename
= "mail.relay",
114 heading
= "E-mail relaying",