461fab1a633bc55b46672e75419e9a91f21893a1
[hcoop/domtool2.git] / src / plugins / exim.sml
1 (* HCoop Domtool (http://hcoop.sourceforge.net/)
2 * Copyright (c) 2006, Adam Chlipala
3 *
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.
8 *
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.
13 *
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.
17 *)
18
19 (* Exim MTA handling *)
20
21 structure Exim :> EXIM = struct
22
23 open Ast
24
25 val dl = ErrorMsg.dummyLoc
26
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)))
30
31 val aliasesChanged = ref false
32 val aliasesDefaultChanged = ref false
33 val hostsChanged = ref false
34 val relayHostsChanged = ref false
35
36 val () = Slave.registerPreHandler
37 (fn () => (aliasesChanged := false;
38 aliasesDefaultChanged := false;
39 hostsChanged := false))
40
41 val () = Slave.registerFileHandler (fn fs =>
42 let
43 val spl = OS.Path.splitDirFile (#file fs)
44 in
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
50 hostsChanged := true
51 else if #file spl = "mail.relay" then
52 relayHostsChanged := true
53 else
54 ()
55 end)
56
57 val () = Slave.registerPostHandler
58 (fn () =>
59 (if !aliasesChanged then
60 Slave.concatTo (fn s => s = "aliases") Config.Exim.aliases
61 else
62 ();
63 if !aliasesDefaultChanged then
64 Slave.concatTo (fn s => s = "aliases.default") Config.Exim.aliasesDefault
65 else
66 ();
67 if !hostsChanged then
68 Slave.enumerateTo (fn s => s = "mail") ":" Config.Exim.handleDomains
69 else
70 ();
71 if !relayHostsChanged then
72 Slave.enumerateTo (fn s => s = "mail.relay") ":" Config.Exim.relayDomains
73 else
74 ();
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)
79 else
80 ()))
81
82
83 val () = Env.actionV_none "handleMail"
84 (fn env =>
85 let
86 val nodes = Env.env (Env.list Env.string) (env, "MailNodes")
87 in
88 app (fn node => #close
89 (Domain.domainsFile {node = node,
90 name = "mail"}) ()) nodes
91 end)
92
93 val () = Env.actionV_none "relayMail"
94 (fn env =>
95 let
96 val nodes = Env.env (Env.list Env.string) (env, "MailNodes")
97 in
98 app (fn node => #close
99 (Domain.domainsFile {node = node,
100 name = "mail.relay"}) ()) nodes
101 end)
102
103 end