Change subject line so it shows the name of the site.
[cocanwiki.git] / scripts / mail_import.ml
index f609062..ae04ef7 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: mail_import.ml,v 1.11 2006/03/28 13:20:00 rich Exp $
+ * $Id: mail_import.ml,v 1.12 2006/03/28 16:24:07 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
@@ -193,7 +193,7 @@ let run r (q : cgi) dbh hostid _ user =
    * NB. Do not change this unique title - it is also used during thread
    * indexing.
    *)
-  let title = sprintf "Mail/%s (%d)" subject msgid in
+  let title = sprintf "Mail/%s (%ld)" subject msgid in
 
   (* Choose a suitable URL. *)
   let url =
@@ -215,7 +215,7 @@ let run r (q : cgi) dbh hostid _ user =
     match overwrite with
       | None -> new_page (Title title)
       | Some _ -> load_page dbh hostid ~url () in
-  let model = { model with redirect = "" } in
+  let model = { model with redirect = None } in
 
   (* Create the first section (mail header). *)
   let section0 =
@@ -225,11 +225,12 @@ let run r (q : cgi) dbh hostid _ user =
       hdr_template#set "from" from;
       hdr_template#set "inet_message_id" inet_message_id;
 
-      let yyyy, mm, dd = date.Dbi.year, date.Dbi.month, date.Dbi.day in
-      hdr_template#set "yyyy" (sprintf "%04d" yyyy);
-      hdr_template#set "mm" (sprintf "%02d" mm);
-      hdr_template#set "dd" (sprintf "%02d" dd);
-      hdr_template#set "short_month" (short_month mm);
+      let date = fst message_date in
+      hdr_template#set "yyyy" (Printer.CalendarPrinter.sprint "%Y" date);
+      hdr_template#set "mm" (Printer.CalendarPrinter.sprint "%m" date);
+      hdr_template#set "dd" (Printer.CalendarPrinter.sprint "%d" date);
+      hdr_template#set "short_month"
+       (Printer.short_name_of_month (Calendar.month date));
 
       let get_table hdr =
        List.map (fun addr -> [ "addr", Template.VarString addr ])
@@ -244,7 +245,7 @@ let run r (q : cgi) dbh hostid _ user =
 
       hdr_template#to_string
     in
-    "", "mail_header", content in
+    None, Some "mail_header", content in
 
   (* Create the second section (mail body).
    * XXX Very simple.  Should be extended to understand attachments and
@@ -329,7 +330,7 @@ let run r (q : cgi) dbh hostid _ user =
       with
          Not_found ->
            "No plain text message body found" in
-    "Message", "mail_body", content in
+    Some "Message", Some "mail_body", content in
 
   (* Overwrite the first two sections of the current page, regardless of
    * what they contain.
@@ -337,22 +338,24 @@ let run r (q : cgi) dbh hostid _ user =
    * use the divname to identify the old mail_header and mail_body and
    * overwrite those, or insert them if they don't exist.
    *)
-  let contents = model.contents in
+  let contents = model.contents_ in
   let contents =
     match contents with
-       [] | [_] -> [ section0; section1 ]
-      | _ :: _ :: xs -> section0 :: section1 :: xs in
-  let model = { model with contents = contents } in
+    | [] | [_] -> [ section0; section1 ]
+    | _ :: _ :: xs -> section0 :: section1 :: xs in
+  let model = { model with contents_ = contents } in
 
   (* Write the page back.  This can throw several exceptions, but we ignore
    * them because we want to script to fail abruptly if any of these
    * unexpected conditions arises.
    *)
-  save_page dbh hostid ~user ~r model;
+  ignore (save_page dbh hostid ~user ~r model);
 
   (* Rebuild threads? *)
   if rebuild then
-    thread_mail dbh hostid ~user ~r date.Dbi.year date.Dbi.month;
+    thread_mail dbh hostid ~user ~r
+      (Calendar.year (fst message_date))
+      (Date.int_of_month (Calendar.month (fst message_date)));
 
   (* Commit to the database. *)
   PGOCaml.commit dbh;