Commit | Line | Data |
---|---|---|
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 | ||
21 | structure Exim :> EXIM = struct | |
22 | ||
e0b0abd2 AC |
23 | open Ast |
24 | ||
25 | val dl = ErrorMsg.dummyLoc | |
26 | ||
27 | val _ = Main.registerDefault ("MailNodes", | |
28 | (TList (TBase "node", dl), dl), | |
29 | (EList (map (fn s => (EString s, dl)) Config.Exim.aliasTo), dl)) | |
30 | ||
8df2e702 AC |
31 | val aliasesChanged = ref false |
32 | val aliasesDefaultChanged = ref false | |
ed9fda3a | 33 | val hostsChanged = ref false |
8df2e702 AC |
34 | |
35 | val () = Slave.registerPreHandler | |
36 | (fn () => (aliasesChanged := false; | |
ed9fda3a AC |
37 | aliasesDefaultChanged := false; |
38 | hostsChanged := false)) | |
8df2e702 AC |
39 | |
40 | val () = Slave.registerFileHandler (fn fs => | |
41 | let | |
42 | val spl = OS.Path.splitDirFile (#file fs) | |
43 | in | |
44 | if #file spl = "aliases" then | |
45 | aliasesChanged := true | |
46 | else if #file spl = "aliases.default" then | |
47 | aliasesDefaultChanged := true | |
ed9fda3a AC |
48 | else if #file spl = "mail" then |
49 | hostsChanged := true | |
8df2e702 AC |
50 | else |
51 | () | |
52 | end) | |
53 | ||
54 | val () = Slave.registerPostHandler | |
55 | (fn () => | |
56 | (if !aliasesChanged then | |
57 | Slave.concatTo (fn s => s = "aliases") Config.Exim.aliases | |
58 | else | |
59 | (); | |
60 | if !aliasesDefaultChanged then | |
61 | Slave.concatTo (fn s => s = "aliases.default") Config.Exim.aliasesDefault | |
62 | else | |
63 | (); | |
ed9fda3a AC |
64 | if !hostsChanged then |
65 | Slave.enumerateTo (fn s => s = "mail") ":" Config.Exim.handleDomains | |
66 | else | |
67 | (); | |
68 | if !aliasesChanged orelse !aliasesDefaultChanged | |
69 | orelse !hostsChanged then | |
8df2e702 AC |
70 | Slave.shellF ([Config.Exim.reload], |
71 | fn cl => "Error reloading exim with " ^ cl) | |
72 | else | |
73 | ())) | |
74 | ||
ed9fda3a | 75 | |
e0b0abd2 AC |
76 | val () = Env.actionV_none "handleMail" |
77 | (fn env => | |
78 | let | |
79 | val nodes = Env.env (Env.list Env.string) (env, "MailNodes") | |
80 | in | |
81 | app (fn node => TextIO.closeOut | |
82 | (Domain.domainFile {node = node, | |
83 | name = "mail"})) nodes | |
84 | end) | |
ed9fda3a | 85 | |
8df2e702 | 86 | end |