ee4cf80c98af3e24b9bca8d63c05516d701585d1
[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 val aliasesChanged = ref false
24 val aliasesDefaultChanged = ref false
25 val hostsChanged = ref false
26
27 val () = Slave.registerPreHandler
28 (fn () => (aliasesChanged := false;
29 aliasesDefaultChanged := false;
30 hostsChanged := false))
31
32 val () = Slave.registerFileHandler (fn fs =>
33 let
34 val spl = OS.Path.splitDirFile (#file fs)
35 in
36 if #file spl = "aliases" then
37 aliasesChanged := true
38 else if #file spl = "aliases.default" then
39 aliasesDefaultChanged := true
40 else if #file spl = "mail" then
41 hostsChanged := true
42 else
43 ()
44 end)
45
46 val () = Slave.registerPostHandler
47 (fn () =>
48 (if !aliasesChanged then
49 Slave.concatTo (fn s => s = "aliases") Config.Exim.aliases
50 else
51 ();
52 if !aliasesDefaultChanged then
53 Slave.concatTo (fn s => s = "aliases.default") Config.Exim.aliasesDefault
54 else
55 ();
56 if !hostsChanged then
57 Slave.enumerateTo (fn s => s = "mail") ":" Config.Exim.handleDomains
58 else
59 ();
60 if !aliasesChanged orelse !aliasesDefaultChanged
61 orelse !hostsChanged then
62 Slave.shellF ([Config.Exim.reload],
63 fn cl => "Error reloading exim with " ^ cl)
64 else
65 ()))
66
67
68 val () = Env.action_none "handleMail"
69 (fn () => TextIO.closeOut (Domain.domainFile "mail"))
70
71 end