Slaves and Exim
[hcoop/domtool2.git] / src / plugins / exim.sml
diff --git a/src/plugins/exim.sml b/src/plugins/exim.sml
new file mode 100644 (file)
index 0000000..112ab5f
--- /dev/null
@@ -0,0 +1,58 @@
+(* HCoop Domtool (http://hcoop.sourceforge.net/)
+ * Copyright (c) 2006, Adam Chlipala
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *)
+
+(* Exim MTA handling *)
+
+structure Exim :> EXIM = struct
+
+val aliasesChanged = ref false
+val aliasesDefaultChanged = ref false
+
+val () = Slave.registerPreHandler
+            (fn () => (aliasesChanged := false;
+                       aliasesDefaultChanged := false))
+
+val () = Slave.registerFileHandler (fn fs =>
+                                      let
+                                          val spl = OS.Path.splitDirFile (#file fs)
+                                      in
+                                          if #file spl = "aliases" then
+                                              aliasesChanged := true
+                                          else if #file spl = "aliases.default" then
+                                              aliasesDefaultChanged := true
+                                          else
+                                              ()
+                                      end)
+
+val () = Slave.registerPostHandler
+        (fn () =>
+            (if !aliasesChanged then
+                 Slave.concatTo (fn s => s = "aliases") Config.Exim.aliases
+             else
+                 ();
+             if !aliasesDefaultChanged then
+                 Slave.concatTo (fn s => s = "aliases.default") Config.Exim.aliasesDefault
+             else
+                 ();
+             if !aliasesChanged orelse !aliasesDefaultChanged then
+                 Slave.shellF ([Config.Exim.reload],
+                               fn cl => "Error reloading exim with " ^ cl)
+             else
+                 ()))
+
+end