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