BIND
[hcoop/domtool2.git] / src / plugins / exim.sml
CommitLineData
8df2e702
AC
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
21structure Exim :> EXIM = struct
22
23val aliasesChanged = ref false
24val aliasesDefaultChanged = ref false
ed9fda3a 25val hostsChanged = ref false
8df2e702
AC
26
27val () = Slave.registerPreHandler
28 (fn () => (aliasesChanged := false;
ed9fda3a
AC
29 aliasesDefaultChanged := false;
30 hostsChanged := false))
8df2e702
AC
31
32val () = 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
ed9fda3a
AC
40 else if #file spl = "mail" then
41 hostsChanged := true
8df2e702
AC
42 else
43 ()
44 end)
45
46val () = 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 ();
ed9fda3a
AC
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
8df2e702
AC
62 Slave.shellF ([Config.Exim.reload],
63 fn cl => "Error reloading exim with " ^ cl)
64 else
65 ()))
66
ed9fda3a
AC
67
68val () = Env.action_none "handleMail"
69 (fn () => TextIO.closeOut (Domain.domainFile "mail"))
70
8df2e702 71end