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 | ||
aa56e112 | 27 | val _ = 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 |
31 | val aliasesChanged = ref false |
32 | val aliasesDefaultChanged = ref false | |
ed9fda3a | 33 | val hostsChanged = ref false |
5543e924 | 34 | val relayHostsChanged = ref false |
8df2e702 AC |
35 | |
36 | val () = Slave.registerPreHandler | |
37 | (fn () => (aliasesChanged := false; | |
ed9fda3a AC |
38 | aliasesDefaultChanged := false; |
39 | hostsChanged := false)) | |
8df2e702 AC |
40 | |
41 | val () = Slave.registerFileHandler (fn fs => | |
42 | let | |
43 | val spl = OS.Path.splitDirFile (#file fs) | |
44 | in | |
3ae703b6 | 45 | if #file spl = "aliases.base" then |
8df2e702 AC |
46 | aliasesChanged := true |
47 | else if #file spl = "aliases.default" then | |
48 | aliasesDefaultChanged := true | |
3ae703b6 | 49 | else if #file spl = "mail.handle" then |
ed9fda3a | 50 | hostsChanged := true |
5543e924 AC |
51 | else if #file spl = "mail.relay" then |
52 | relayHostsChanged := true | |
8df2e702 AC |
53 | else |
54 | () | |
55 | end) | |
56 | ||
57 | val () = Slave.registerPostHandler | |
58 | (fn () => | |
59 | (if !aliasesChanged then | |
3ae703b6 | 60 | Slave.concatTo (fn s => s = "aliases.base") Config.Exim.aliases |
8df2e702 AC |
61 | else |
62 | (); | |
63 | if !aliasesDefaultChanged then | |
64 | Slave.concatTo (fn s => s = "aliases.default") Config.Exim.aliasesDefault | |
65 | else | |
66 | (); | |
ed9fda3a | 67 | if !hostsChanged then |
3ae703b6 | 68 | Slave.enumerateTo (fn s => s = "mail.handle") ":" Config.Exim.handleDomains |
ed9fda3a AC |
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 |
83 | val () = Env.actionV_none "handleMail" |
84 | (fn env => | |
85 | let | |
86 | val nodes = Env.env (Env.list Env.string) (env, "MailNodes") | |
87 | in | |
4bed2594 AC |
88 | app (fn node => #close |
89 | (Domain.domainsFile {node = node, | |
3ae703b6 | 90 | name = "mail.handle"}) ()) nodes |
e0b0abd2 | 91 | end) |
ed9fda3a | 92 | |
5543e924 AC |
93 | val () = Env.actionV_none "relayMail" |
94 | (fn env => | |
95 | let | |
96 | val nodes = Env.env (Env.list Env.string) (env, "MailNodes") | |
97 | in | |
4bed2594 AC |
98 | app (fn node => #close |
99 | (Domain.domainsFile {node = node, | |
100 | name = "mail.relay"}) ()) nodes | |
5543e924 AC |
101 | end) |
102 | ||
41c58daf | 103 | val () = Domain.registerDescriber (Domain.considerAll |
3ae703b6 | 104 | [Domain.Filename {filename = "aliases.base", |
d936cf4d | 105 | heading = "E-mail aliases:", |
41c58daf AC |
106 | showEmpty = false}, |
107 | Domain.Filename {filename = "aliases.default", | |
d936cf4d | 108 | heading = "Default e-mail alias:", |
41c58daf | 109 | showEmpty = false}, |
3ae703b6 | 110 | Domain.Filename {filename = "mail.handle", |
d936cf4d AC |
111 | heading = "E-mail handling is on.", |
112 | showEmpty = true}, | |
41c58daf | 113 | Domain.Filename {filename = "mail.relay", |
d936cf4d AC |
114 | heading = "E-mail relaying is on.", |
115 | showEmpty = true}]) | |
41c58daf | 116 | |
8df2e702 | 117 | end |