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