Switch over to using Netsendmail.
authorrich <rich>
Mon, 31 Jul 2006 09:49:42 +0000 (09:49 +0000)
committerrich <rich>
Mon, 31 Jul 2006 09:49:42 +0000 (09:49 +0000)
scripts/contact.ml
scripts/crash.ml
scripts/edit.ml
scripts/forgot_password.ml
scripts/invite_user.ml
scripts/invite_user_confirm.ml
scripts/lib/cocanwiki_emailnotify.ml
scripts/mailing_list_send.ml
scripts/page_email_send.ml
scripts/send_feedback.ml
scripts/user_prefs.ml

index 23dd68b..6666b15 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: contact.ml,v 1.12 2006/07/31 09:10:33 rich Exp $
+ * $Id: contact.ml,v 1.13 2006/07/31 09:49:42 rich Exp $
  *
  * 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
@@ -148,8 +148,10 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
   template#set "nr_uploads" (string_of_int (List.length uploads));
 
   (* Send the initial email. *)
+  let content_type =
+    "text/plain", ["charset", Mimestring.mk_param "UTF-8"] in
   let body = template#to_string in
-  let msg = Netsendmail.compose ~to_addrs ~subject body in
+  let msg = Netsendmail.compose ~to_addrs ~subject ~content_type body in
   Netsendmail.sendmail msg;
 
   (* Send the following uploads by email. *)
index 15c391f..d5aa886 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: crash.ml,v 1.5 2006/03/27 18:09:46 rich Exp $
+ * $Id: crash.ml,v 1.6 2006/07/31 09:49:42 rich Exp $
  *
  * 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
@@ -36,12 +36,8 @@ let run r (q : cgi) dbh hostid
   let crash_email = server_settings_crash_email dbh in
 
   (* Get the current time and write it into the logs. *)
-  let time = Unix.gmtime (Unix.time ()) in
-  let time =
-    sprintf "%04d/%02d/%02d %02d:%02d:%02d"
-      (time.Unix.tm_year + 1900) (time.Unix.tm_mon + 1) time.Unix.tm_mday
-      time.Unix.tm_hour time.Unix.tm_min time.Unix.tm_sec in
-
+  let time = Calendar.now () in
+  let time = Printer.CalendarPrinter.to_string time in
   prerr_endline ("crash: " ^ time);
 
   (* Send a feedback email to the designated address if
@@ -49,16 +45,23 @@ let run r (q : cgi) dbh hostid
    *)
   let mail_sent =
     match crash_email with
-       None -> false
-      | Some email ->
-         let subject =
-           "Crash notify: There was a 500 internal server error" in
-         let body = "Crash at " ^ time ^ "\n" ^
-                    "Hostname is " ^ canonical_hostname ^ "\n" ^
-                    "Please see the error log for details." in
-         Sendmail.send_mail ~subject ~to_addr:[email] body;
+    | None -> false
+    | Some email ->
+       let subject =
+         "Crash notify: There was a 500 internal server error" in
+       let body = "Crash at " ^ time ^ "\n" ^
+         "Hostname is " ^ canonical_hostname ^ "\n" ^
+         "Please see the error log for details." in
+
+       let to_addrs = ["", email] in
+       let content_type =
+         "text/plain", ["charset", Mimestring.mk_param "UTF-8"] in
+
+       let msg =
+         Netsendmail.compose ~subject ~to_addrs ~content_type body in
+       Netsendmail.sendmail msg;
 
-         true in
+       true in
 
   template#conditional "mail_sent" mail_sent;
 
index ca86f55..53ed01d 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: edit.ml,v 1.31 2006/07/27 16:46:55 rich Exp $
+ * $Id: edit.ml,v 1.32 2006/07/31 09:49:42 rich Exp $
  *
  * 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
@@ -452,14 +452,19 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
        let subject =
          "Site notice: " ^ hostname ^ "/" ^ url ^ " has been updated" in
 
+       let content_type =
+         "text/plain", ["charset", Mimestring.mk_param "UTF-8"] in
+
        (* Send each email individually (they all have different opt out
         * links).
         *)
        List.iter (fun (to_addr, opt_out) ->
                     template_email#set "opt_out" opt_out;
                     let body = template_email#to_string in
-                    Sendmail.send_mail ~subject
-                      ~to_addr:[to_addr] body)
+
+                    let msg = Netsendmail.compose ~to_addrs:["", to_addr]
+                      ~subject ~content_type body in
+                    Netsendmail.sendmail msg)
          addrs
       );
 
index e51e998..e88e9c3 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: forgot_password.ml,v 1.10 2006/03/27 19:10:29 rich Exp $
+ * $Id: forgot_password.ml,v 1.11 2006/07/31 09:49:43 rich Exp $
  *
  * 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
@@ -65,7 +65,12 @@ let run r (q : cgi) dbh hostid { hostname = hostname } _ =
       "\n" ^
       "IP address of request: " ^ ip ^ "\n" in
 
-    Sendmail.send_mail ~subject ~to_addr:[ email ] body;
+    let content_type =
+      "text/plain", ["charset", Mimestring.mk_param "UTF-8"] in
+    let to_addrs = [ "", email ] in
+
+    let msg = Netsendmail.compose ~subject ~to_addrs ~content_type body in
+    Netsendmail.sendmail msg;
 
     let buttons = [ ok_button "/_login" ] in
     ok ~buttons ~title:"Password sent by email"
index 8f3a09a..f7ca741 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: invite_user.ml,v 1.8 2006/07/26 13:12:10 rich Exp $
+ * $Id: invite_user.ml,v 1.9 2006/07/31 09:49:43 rich Exp $
  *
  * 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
@@ -49,10 +49,10 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
   let subject = username ^ " has invited you to join " ^ hostname in
 
   (* Get a suitable return address for the email. *)
-  let from =
+  let from_addr =
     match email with
-      | Some email -> email
-      | None -> "service@merjis.com" in
+      | Some email -> username, email
+      | None -> username, "service@merjis.com" in
 
   (* Add user accounts for these new users.  For users who are already
    * registered, we'll send reminder emails.
@@ -94,7 +94,14 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
         | _ -> assert false in
 
        (* Send the email. *)
-       Sendmail.send_mail ~subject ~to_addr:[email] ~from body
+       let to_addrs = [ "", email ] in
+       let content_type =
+        "text/plain", ["charset", Mimestring.mk_param "UTF-8"] in
+
+       let msg =
+        Netsendmail.compose ~subject
+          ~to_addrs ~from_addr ~content_type body in
+       Netsendmail.sendmail msg
     ) emails;
 
   (* Finish off. *)
index 89fb904..ad01874 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: invite_user_confirm.ml,v 1.7 2006/03/28 16:24:07 rich Exp $
+ * $Id: invite_user_confirm.ml,v 1.8 2006/07/31 09:49:43 rich Exp $
  *
  * 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
@@ -83,7 +83,13 @@ let run r (q : cgi) dbh hostid { hostname = hostname } _ =
         let body = template#to_string in
 
         let subject = "Your new account details" in
-        Sendmail.send_mail ~to_addr:[email] ~subject body);
+
+        let to_addrs = [ "", email ] in
+        let content_type =
+          "text/plain", ["charset", Mimestring.mk_param "UTF-8"] in
+
+        let msg = Netsendmail.compose ~to_addrs ~subject ~content_type body in
+        Netsendmail.sendmail msg);
 
   PGOCaml.commit dbh;
 
index 3214460..00f6433 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_emailnotify.ml,v 1.8 2006/04/08 14:46:24 rich Exp $
+ * $Id: cocanwiki_emailnotify.ml,v 1.9 2006/07/31 09:49:45 rich Exp $
  *
  * 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
@@ -39,11 +39,14 @@ let email_notify ~subject ~body ?user dbh hostid =
    *
    * Also get the user's email address.
    *)
-  let own_userid, from =
+  let own_userid, from_addr =
     match user with
       | None
       | Some Anonymous -> 0l, None
-      | Some (User (userid, _, _, prefs)) -> userid, prefs.email in
+      | Some (User (userid, _, _, {email = Some email})) ->
+         userid, Some ("", email)
+      | Some (User (userid, _, _, _)) ->
+         userid, None in
 
   (* Send a change email to everyone who hasn't opted out using
    * their preferences.  This behaviour replaces the old
@@ -55,10 +58,10 @@ let email_notify ~subject ~body ?user dbh hostid =
        from users
       where hostid = $hostid and id <> $own_userid and email_notify
         and email is not null and invite is null" in
-  let to_addr = List.filter_map (
+  let to_addrs = List.filter_map (
     function
     | (name, Some email) ->
-       Some ("\"" ^ name ^ "\" <" ^ email ^ ">")
+       Some (name, email)
     | (name, None) -> None
   ) rows in
 
@@ -68,7 +71,7 @@ let email_notify ~subject ~body ?user dbh hostid =
       "select canonical_hostname from hosts where id = $hostid"
   ) in
 
-  if to_addr <> [] then (
+  if to_addrs <> [] 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.
@@ -84,6 +87,11 @@ let email_notify ~subject ~body ?user dbh hostid =
 
     let subject = canonical_hostname ^ ": " ^ subject in
 
+    let content_type =
+      "text/plain", ["charset", Mimestring.mk_param "UTF-8"] in
+
     (* Send the email. *)
-    Sendmail.send_mail ~subject ~to_addr ?from body
+    let msg =
+      Netsendmail.compose ~to_addrs ?from_addr ~content_type ~subject body in
+    Netsendmail.sendmail msg
   )
index b576d56..1ea0bae 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: mailing_list_send.ml,v 1.8 2006/03/28 13:20:00 rich Exp $
+ * $Id: mailing_list_send.ml,v 1.9 2006/07/31 09:49:43 rich Exp $
  *
  * 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
@@ -84,7 +84,13 @@ let run r (q : cgi) dbh hostid { hostname = hostname } _ =
 
   let body = template#to_string in
   let subject = "Site notice: " ^ hostname ^ ": Confirm your email address" in
-  Sendmail.send_mail ~subject ~to_addr:[email] body;
+
+  let content_type =
+    "text/plain", ["charset", Mimestring.mk_param "UTF-8"] in
+  let to_addrs = [ "", email ] in
+
+  let msg = Netsendmail.compose ~subject ~to_addrs ~content_type body in
+  Netsendmail.sendmail msg;
 
   (* Finish up. *)
   let buttons = [ ok_button "/" ] in
index 42ca71b..75e2745 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: page_email_send.ml,v 1.6 2006/03/28 16:24:07 rich Exp $
+ * $Id: page_email_send.ml,v 1.7 2006/07/31 09:49:43 rich Exp $
  *
  * 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
@@ -89,7 +89,13 @@ let run r (q : cgi) dbh hostid { hostname = hostname } _ =
 
   let body = template#to_string in
   let subject = "Site notice: " ^ hostname ^ ": Confirm your email address" in
-  Sendmail.send_mail ~subject ~to_addr:[email] body;
+
+  let content_type =
+    "text/plain", ["charset", Mimestring.mk_param "UTF-8"] in
+  let to_addrs = [ "", email ] in
+
+  let msg = Netsendmail.compose ~subject ~to_addrs ~content_type body in
+  Netsendmail.sendmail msg;
 
   (* Finish up. *)
   let buttons = [ ok_button ("/" ^ page) ] in
index ffe7c7c..f47517a 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: send_feedback.ml,v 1.9 2006/07/26 13:12:10 rich Exp $
+ * $Id: send_feedback.ml,v 1.10 2006/07/31 09:49:43 rich Exp $
  *
  * 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
@@ -80,7 +80,13 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
   (* Send the feedback email. *)
   let subject = "Wiki feedback: Feedback about " ^ page ^ " page" in
   let body = template#to_string in
-  Sendmail.send_mail ~subject ~to_addr:[to_addr] body;
+
+  let to_addrs = [ "", to_addr ] in
+  let content_type =
+    "text/plain", ["charset", Mimestring.mk_param "UTF-8"] in
+
+  let msg = Netsendmail.compose ~subject ~to_addrs ~content_type body in
+  Netsendmail.sendmail msg;
 
   (* Confirm. *)
   ok ~title:"Thank you for your feedback" ~buttons:[ok_button "/"]
index 0cc2db0..ebcf6fd 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: user_prefs.ml,v 1.8 2006/03/28 16:24:08 rich Exp $
+ * $Id: user_prefs.ml,v 1.9 2006/07/31 09:49:43 rich Exp $
  *
  * 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
@@ -80,7 +80,13 @@ let run r (q : cgi) dbh hostid {hostname=hostname} user =
        let body = email_change_template#to_string in
 
        let subject = "Please verify your new email address at " ^ hostname in
-       Sendmail.send_mail ~subject ~to_addr:[new_email] body
+
+       let content_type =
+         "text/plain", ["charset", Mimestring.mk_param "UTF-8"] in
+       let to_addrs = [ "", new_email ] in
+
+       let msg = Netsendmail.compose ~subject ~to_addrs ~content_type body in
+       Netsendmail.sendmail msg
       );
 
       changed