(* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $Id: cocanwiki_emailnotify.ml,v 1.2 2004/09/07 14:58:34 rich Exp $ *) open Apache open Registry open Cgi open Printf (* This is where we coordinate email notification from various * scripts which create or update the wiki. *) let email_notify ~subject ~body (dbh : Dbi.connection) hostid = (* Is anyone listed for email notification at this host? *) let sth = dbh#prepare_cached "select email, name from email_notify where hostid = ?" in sth#execute [`Int hostid]; let to_addr = sth#map (function | [`String email; `String name] -> name ^ " <" ^ email ^ ">" | [`String email; `Null] -> email | _ -> assert false) in if to_addr <> [] then ( (* Prepare the body of the message. The assumption is that * this takes time and database access, so we defer the creation * of the body until we know that someone needs to be notified. *) let body = body () in let subject = "Wiki notice: " ^ subject in (* Send the email. *) Sendmail.send_mail ~subject ~to_addr ~body () )