From: rich Date: Mon, 31 Jul 2006 09:49:42 +0000 (+0000) Subject: Switch over to using Netsendmail. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=113f16040c4eb712172eaa21e066311133fb9e6f;p=cocanwiki.git Switch over to using Netsendmail. --- diff --git a/scripts/contact.ml b/scripts/contact.ml index 23dd68b..6666b15 100644 --- a/scripts/contact.ml +++ b/scripts/contact.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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. *) diff --git a/scripts/crash.ml b/scripts/crash.ml index 15c391f..d5aa886 100644 --- a/scripts/crash.ml +++ b/scripts/crash.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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; diff --git a/scripts/edit.ml b/scripts/edit.ml index ca86f55..53ed01d 100644 --- a/scripts/edit.ml +++ b/scripts/edit.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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 ); diff --git a/scripts/forgot_password.ml b/scripts/forgot_password.ml index e51e998..e88e9c3 100644 --- a/scripts/forgot_password.ml +++ b/scripts/forgot_password.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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" diff --git a/scripts/invite_user.ml b/scripts/invite_user.ml index 8f3a09a..f7ca741 100644 --- a/scripts/invite_user.ml +++ b/scripts/invite_user.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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. *) diff --git a/scripts/invite_user_confirm.ml b/scripts/invite_user_confirm.ml index 89fb904..ad01874 100644 --- a/scripts/invite_user_confirm.ml +++ b/scripts/invite_user_confirm.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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; diff --git a/scripts/lib/cocanwiki_emailnotify.ml b/scripts/lib/cocanwiki_emailnotify.ml index 3214460..00f6433 100644 --- a/scripts/lib/cocanwiki_emailnotify.ml +++ b/scripts/lib/cocanwiki_emailnotify.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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 ) diff --git a/scripts/mailing_list_send.ml b/scripts/mailing_list_send.ml index b576d56..1ea0bae 100644 --- a/scripts/mailing_list_send.ml +++ b/scripts/mailing_list_send.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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 diff --git a/scripts/page_email_send.ml b/scripts/page_email_send.ml index 42ca71b..75e2745 100644 --- a/scripts/page_email_send.ml +++ b/scripts/page_email_send.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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 diff --git a/scripts/send_feedback.ml b/scripts/send_feedback.ml index ffe7c7c..f47517a 100644 --- a/scripts/send_feedback.ml +++ b/scripts/send_feedback.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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 "/"] diff --git a/scripts/user_prefs.ml b/scripts/user_prefs.ml index 0cc2db0..ebcf6fd 100644 --- a/scripts/user_prefs.ml +++ b/scripts/user_prefs.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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