Proper generation of Exim domainlists
[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
e0b0abd2
AC
23open Ast
24
25val dl = ErrorMsg.dummyLoc
26
aa56e112 27val _ = Defaults.registerDefault ("MailNodes",
bbdf617f 28 (TList (TBase "mail_node", dl), dl),
aa56e112 29 (fn () => (EList (map (fn s => (EString s, dl)) Config.Exim.aliasTo), dl)))
e0b0abd2 30
8df2e702
AC
31val aliasesChanged = ref false
32val aliasesDefaultChanged = ref false
ed9fda3a 33val hostsChanged = ref false
5543e924 34val relayHostsChanged = ref false
8df2e702
AC
35
36val () = Slave.registerPreHandler
37 (fn () => (aliasesChanged := false;
ed9fda3a
AC
38 aliasesDefaultChanged := false;
39 hostsChanged := false))
8df2e702
AC
40
41val () = 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
ed9fda3a
AC
49 else if #file spl = "mail" then
50 hostsChanged := true
5543e924
AC
51 else if #file spl = "mail.relay" then
52 relayHostsChanged := true
8df2e702
AC
53 else
54 ()
55 end)
56
57val () = 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 ();
ed9fda3a
AC
67 if !hostsChanged then
68 Slave.enumerateTo (fn s => s = "mail") ":" Config.Exim.handleDomains
69 else
70 ();
5543e924
AC
71 if !relayHostsChanged then
72 Slave.enumerateTo (fn s => s = "mail.relay") ":" Config.Exim.relayDomains
73 else
74 ();
ed9fda3a 75 if !aliasesChanged orelse !aliasesDefaultChanged
5543e924 76 orelse !hostsChanged orelse !relayHostsChanged then
8df2e702
AC
77 Slave.shellF ([Config.Exim.reload],
78 fn cl => "Error reloading exim with " ^ cl)
79 else
80 ()))
81
ed9fda3a 82
e0b0abd2
AC
83val () = 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 => TextIO.closeOut
89 (Domain.domainFile {node = node,
90 name = "mail"})) nodes
91 end)
ed9fda3a 92
5543e924
AC
93val () = 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 => TextIO.closeOut
99 (Domain.domainFile {node = node,
100 name = "mail.relay"})) nodes
101 end)
102
8df2e702 103end