Fix the problem of corrupting binary attachments; changed to using Gerd S's
authorrich <rich>
Mon, 31 Jul 2006 09:10:33 +0000 (09:10 +0000)
committerrich <rich>
Mon, 31 Jul 2006 09:10:33 +0000 (09:10 +0000)
Netsendmail instead of our homebrew/insecure Cgi.Sendmail module.

scripts/contact.ml

index 96469ea..23dd68b 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.11 2006/05/09 11:36:16 rich Exp $
+ * $Id: contact.ml,v 1.12 2006/07/31 09:10:33 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
@@ -59,10 +59,11 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
     | [] -> fail "There is no such contact form in the database."
     | _ -> assert false in
 
-  let emails =
+  let to_addrs =
     PGSQL(dbh) "select email from contact_emails where contactid = $id" in
+  let to_addrs = List.map (fun email -> "", email) to_addrs in
 
-  if emails = [] then
+  if to_addrs = [] then
     fail "There are no email addresses associated with that contact id.";
 
   (* Now process the strings passed as parameters to the script.  Any
@@ -148,17 +149,19 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
 
   (* Send the initial email. *)
   let body = template#to_string in
-  Sendmail.send_mail ~subject ~to_addr:emails body;
+  let msg = Netsendmail.compose ~to_addrs ~subject body in
+  Netsendmail.sendmail msg;
 
   (* Send the following uploads by email. *)
   List.iter (fun name ->
               let upload = q#upload name in
               let subject = upload.upload_filename in
-              (* XXX This is insecure. *)
-              let content_type = upload.upload_content_type in
+              let content_type = upload.upload_content_type, [] in
               let body = upload.upload_value in
 
-              Sendmail.send_mail ~subject ~to_addr:emails ~content_type body)
+              let msg =
+                Netsendmail.compose ~to_addrs ~subject ~content_type body in
+              Netsendmail.sendmail msg)
     uploads;
 
   (* Confirm. *)