Mailman shortcut working
[hcoop/zz_old/domtool2-proto.git] / src / plugins / exim.sml
CommitLineData
1f53f82b 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
668e333e 23open Ast
24
25val dl = ErrorMsg.dummyLoc
26
53d222a3 27val _ = Defaults.registerDefault ("MailNodes",
de352c91 28 (TList (TBase "mail_node", dl), dl),
53d222a3 29 (fn () => (EList (map (fn s => (EString s, dl)) Config.Exim.aliasTo), dl)))
668e333e 30
1f53f82b 31val aliasesChanged = ref false
32val aliasesDefaultChanged = ref false
cd873ae9 33val hostsChanged = ref false
ca36ffec 34val relayHostsChanged = ref false
1f53f82b 35
36val () = Slave.registerPreHandler
37 (fn () => (aliasesChanged := false;
cd873ae9 38 aliasesDefaultChanged := false;
39 hostsChanged := false))
1f53f82b 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
cd873ae9 49 else if #file spl = "mail" then
50 hostsChanged := true
ca36ffec 51 else if #file spl = "mail.relay" then
52 relayHostsChanged := true
1f53f82b 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 ();
cd873ae9 67 if !hostsChanged then
68 Slave.enumerateTo (fn s => s = "mail") ":" Config.Exim.handleDomains
69 else
70 ();
ca36ffec 71 if !relayHostsChanged then
72 Slave.enumerateTo (fn s => s = "mail.relay") ":" Config.Exim.relayDomains
73 else
74 ();
cd873ae9 75 if !aliasesChanged orelse !aliasesDefaultChanged
ca36ffec 76 orelse !hostsChanged orelse !relayHostsChanged then
1f53f82b 77 Slave.shellF ([Config.Exim.reload],
78 fn cl => "Error reloading exim with " ^ cl)
79 else
80 ()))
81
cd873ae9 82
668e333e 83val () = Env.actionV_none "handleMail"
84 (fn env =>
85 let
86 val nodes = Env.env (Env.list Env.string) (env, "MailNodes")
87 in
5b145691 88 app (fn node => #close
89 (Domain.domainsFile {node = node,
90 name = "mail"}) ()) nodes
668e333e 91 end)
cd873ae9 92
ca36ffec 93val () = Env.actionV_none "relayMail"
94 (fn env =>
95 let
96 val nodes = Env.env (Env.list Env.string) (env, "MailNodes")
97 in
5b145691 98 app (fn node => #close
99 (Domain.domainsFile {node = node,
100 name = "mail.relay"}) ()) nodes
ca36ffec 101 end)
102
1f5e7aad 103val () = Domain.registerDescriber (Domain.considerAll
104 [Domain.Filename {filename = "aliases",
105 heading = "E-mail aliases",
106 showEmpty = false},
107 Domain.Filename {filename = "aliases.default",
108 heading = "Default e-mail alias",
109 showEmpty = false},
110 Domain.Filename {filename = "mail",
111 heading = "E-mail handling",
112 showEmpty = false},
113 Domain.Filename {filename = "mail.relay",
114 heading = "E-mail relaying",
115 showEmpty = false}])
116
1f53f82b 117end