Allow $field to be substituted in subject lines.
authorrich <rich>
Tue, 9 May 2006 11:36:16 +0000 (11:36 +0000)
committerrich <rich>
Tue, 9 May 2006 11:36:16 +0000 (11:36 +0000)
Makefile.config
scripts/contact.ml

index a66049f..bf578b8 100644 (file)
@@ -1,7 +1,7 @@
-# $Id: Makefile.config,v 1.30 2006/03/27 16:43:43 rich Exp $
+# $Id: Makefile.config,v 1.31 2006/05/09 11:36:16 rich Exp $
 
 PACKAGE := cocanwiki
-VERSION := 1.4.0
+VERSION := 1.4.1
 
 # Normally ignored.  However, if you are installing centrally (using
 # 'make pkg-install'), then the components are installed in the
index b64bd56..96469ea 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.10 2006/03/27 18:09:46 rich Exp $
+ * $Id: contact.ml,v 1.11 2006/05/09 11:36:16 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
@@ -30,6 +30,8 @@ open Cocanwiki
 open Cocanwiki_template
 open Cocanwiki_ok
 
+let subj_rex = Pcre.regexp "\\$\\w+"
+
 let run r (q : cgi) dbh hostid {hostname = hostname} user =
   let template = get_template dbh hostid "contact.txt" in
 
@@ -97,6 +99,20 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
     let not_empty name = (q#upload name).upload_value <> "" in
     List.filter not_empty uploads in
 
+  (* Substitute any $Field fields in the subject line.  The substitution
+   * is very simple-minded.
+   *)
+  let subst pat =
+    let n = String.length pat in
+    assert (n > 0 && pat.[0] = '$');
+    let fieldname = String.sub pat 1 (n-1) in
+    if List.mem fieldname names then
+      q#param fieldname
+    else
+      pat
+  in
+  let subject = Pcre.substitute ~rex:subj_rex ~subst subject in
+
   (* Get the IP address for logging purposes. *)
   let ip =
     try Connection.remote_ip (Request.connection r) with Not_found -> "" in