From 13bc3874361cef14b947c2387cc7303ff8be5bd6 Mon Sep 17 00:00:00 2001 From: rich Date: Tue, 9 May 2006 11:36:16 +0000 Subject: [PATCH] Allow $field to be substituted in subject lines. --- Makefile.config | 4 ++-- scripts/contact.ml | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Makefile.config b/Makefile.config index a66049f..bf578b8 100644 --- a/Makefile.config +++ b/Makefile.config @@ -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 diff --git a/scripts/contact.ml b/scripts/contact.ml index b64bd56..96469ea 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.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 -- 1.8.3.1