changeset 742:b00eb39643c1

Changes to how $originalmail$ works - No longer buffer the whole mail in memory, but copy a line at a time - Allow a line-count - Change to the indent/whitespace behaviour; to essentially get current behaviour, a space must be prepended to the lines currently containing $originalmail$ in the listtexts The interface to substitute() and substitute_one() has changed. They no longer take the original mail filename, and cannot be used to do $originalmail$ substitution. This was never used except by prepstdreply() which now incorporates that substitution itself.
author Ben Schmidt
date Mon, 20 Sep 2010 02:05:31 +1000
parents b72bcb7e08a2
children c2ffbdcf3be5
files ChangeLog README.listtexts include/prepstdreply.h src/prepstdreply.c src/send_digest.c
diffstat 5 files changed, 82 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Sep 20 01:44:58 2010 +1000
+++ b/ChangeLog	Mon Sep 20 02:05:31 2010 +1000
@@ -1,3 +1,6 @@
+ o Changes to how $originalmail$ works -- existing installations will change
+   behaviour due to this; prepending a space to the lines currently containing
+   $originalmail$ in the listtexts will generally retain current behaviour
  o Allow arbitrary headers in list texts
  o Ensure digest listtext is always closed
  o Fix Content-Transfer-Encoding: header for digests and list texts
--- a/README.listtexts	Mon Sep 20 01:44:58 2010 +1000
+++ b/README.listtexts	Mon Sep 20 02:05:31 2010 +1000
@@ -227,8 +227,14 @@
   the address that has been unsubscribed
 
 - $originalmail$
-  the first 100 lines (including headers)
-  of the email message being processed (usually a mail being moderated)
+- $originalmailN$
+  the email message being processed (usually a mail being moderated); this must
+  appear first on a line, optionally preceded by whitespace: any preceding
+  whitespace is prepended to each line of the mail that is included and the
+  rest of the line following originalmail$ is ignored; N represents a number,
+  which is how many lines of the message (including headers) to include: if
+  omitted, 100 will be used, and to include the whole message, use a large
+  number like 1000000000.
 
 - $posteraddr$
   (available only in subonlypost)
--- a/include/prepstdreply.h	Mon Sep 20 01:44:58 2010 +1000
+++ b/include/prepstdreply.h	Mon Sep 20 02:05:31 2010 +1000
@@ -25,10 +25,9 @@
 #define PREPSTDREPLY_H
 
 char *substitute(const char *line, const char *listaddr, const char *listdelim,
-		size_t datacount, char **data, const char* mailname);
+		size_t datacount, char **data);
 char *substitute_one(const char *line, const char *listaddr,
-		const char *listdelim, size_t datacount, char **data,
-		const char* mailname);
+		const char *listdelim, size_t datacount, char **data);
 int open_listtext(const char *listdir, const char *filename);
 char *prepstdreply(const char *listdir, const char *filename, const char *from,
 		const char *to, const char *replyto, size_t tokencount,
--- a/src/prepstdreply.c	Mon Sep 20 01:44:58 2010 +1000
+++ b/src/prepstdreply.c	Mon Sep 20 02:05:31 2010 +1000
@@ -44,13 +44,13 @@
 #include "unistr.h"
 
 char *substitute(const char *line, const char *listaddr, const char *listdelim,
-		 size_t datacount, char **data, const char *mailname)
+		 size_t datacount, char **data)
 {
 	char *s1, *s2;
 
-	s1 = substitute_one(line, listaddr, listdelim, datacount, data, mailname);
+	s1 = substitute_one(line, listaddr, listdelim, datacount, data);
 	while(s1) {
-		s2 = substitute_one(s1, listaddr, listdelim, datacount, data, mailname);
+		s2 = substitute_one(s1, listaddr, listdelim, datacount, data);
 		if(s2) {
 			myfree(s1);
 			s1 = s2;
@@ -62,8 +62,7 @@
 }
 
 char *substitute_one(const char *line, const char *listaddr,
-			const char *listdelim, size_t datacount, char **data,
-			const char* mailname)
+			const char *listdelim, size_t datacount, char **data)
 {
 	char *fqdn, *listname, *d1, *d2, *token, *value = NULL;
 	char *retstr, *origline;
@@ -133,26 +132,6 @@
 		value = concatstr(4, listname, listdelim, "subscribe-nomail@",
 				  fqdn);
 		goto concatandreturn;
-	} else if(strcmp(token, "originalmail") == 0) {
-		/* append the first 100 lines of the mail inline */
-		int mailfd;
-		if(mailname && 
-		     ((mailfd = open(mailname, O_RDONLY)) > 0)){
-			size_t count = 0;
-			char* str = NULL;
-			while(count < 100 && (str = mygetline(mailfd))) {
-				char* tmp = value;
-				value = concatstr(3, value, " ", str);
-				if(tmp)
-					myfree(tmp);
-				myfree(str);
-				count++;
-			}
-			close(mailfd);
-		}else{
-			log_error(LOG_ARGS, "Could not substitute $originalmail$ (mailname == %s)",mailname);
-		}
-		goto concatandreturn;
 	}
 	if(data) {
 		for(i = 0; i < datacount; i++) {
@@ -211,7 +190,7 @@
 		   char **data, const char *mailname)
 {
 	size_t i, len;
-	int infd, outfd;
+	int infd, outfd, mailfd;
 	char *listaddr, *listdelim, *tmp, *retstr = NULL;
 	char *listfqdn, *line, *utfline, *utfsub, *utfsub2;
 	char *str = NULL;
@@ -244,11 +223,11 @@
 	}
 
 	tmp = substitute(from, listaddr, listdelim,
-	                 tokencount, data, NULL);
+	                 tokencount, data);
 	headers[0] = concatstr(2, "From: ", tmp);
 	myfree(tmp);
 	tmp = substitute(to, listaddr, listdelim,
-	                 tokencount, data, NULL);
+	                 tokencount, data);
 	headers[1] = concatstr(2, "To: ", tmp);
 	myfree(tmp);
 	headers[2] = genmsgid(listfqdn);
@@ -262,7 +241,7 @@
 
 	if(replyto) {
 		tmp = substitute(replyto, listaddr, listdelim,
-		                 tokencount, data, NULL);
+		                 tokencount, data);
 		headers[8] = concatstr(2, "Reply-To: ", tmp);
 		myfree(tmp);
 	}
@@ -286,7 +265,7 @@
 			   continuation of previous header line */
 			utfsub = unistr_escaped_to_utf8(line);
 			str = substitute(utfsub, listaddr, listdelim,
-			                 tokencount, data, NULL);
+			                 tokencount, data);
 			myfree(utfsub);
 			len = strlen(str);
 			str[len] = '\n';
@@ -329,7 +308,7 @@
 			utfsub = unistr_escaped_to_utf8(tmp);
 			*tmp = '\0';
 			utfsub2 = substitute(utfsub, listaddr, listdelim,
-			                     tokencount, data, NULL);
+			                     tokencount, data);
 			myfree(utfsub);
 			if (strncasecmp(line, "Subject:", len) == 0) {
 				tmp = unistr_utf8_to_header(utfsub2);
@@ -393,9 +372,54 @@
 		utfline = unistr_escaped_to_utf8(str);
 		myfree(str);
 
-		str = substitute(utfline, listaddr, listdelim, tokencount, data, mailname);
+		tmp = utfline;
+		while (*tmp && (*tmp == ' ' || *tmp == '\t')) {
+			tmp++;
+		}
+		if (strncmp(tmp,"$originalmail",13) == 0) {
+			*tmp = '\0';
+			tmp += 13;
+			str = tmp;
+			while (*tmp >= '0' && *tmp <= '9')
+				tmp++;
+			if (*tmp == '$') {
+				*tmp = '\0';
+				len = 100;
+				if (str != tmp)
+					len = atol(str);
+				if (mailname && 
+		     		   ((mailfd = open(mailname, O_RDONLY)) > 0)){
+		     		    str = NULL;
+				    i = 0;
+				    while (i < len &&
+				           (str = mygetline(mailfd))) {
+				        tmp = str;
+				        str = concatstr(2,utfline,str);
+				        myfree(tmp);
+				        if(writen(outfd,str,strlen(str)) < 0) {
+				            myfree(str);
 		myfree(utfline);
-
+				            myfree(listaddr);
+				            myfree(listdelim);
+				            myfree(listfqdn);
+				            log_error(LOG_ARGS, "Could not write std mail");
+				            return NULL;
+				        }
+				        myfree(str);
+				        i++;
+				    }
+				    close(mailfd);
+				} else {
+				    log_error(LOG_ARGS, "Could not substitute $originalmail%d$ (mailname == %s)",len,mailname);
+				}
+			} else {
+				log_error(LOG_ARGS, "Bad $originalmailNNN$ substitution");
+			}
+			myfree(utfline);
+		} else {
+			str = substitute(utfline, listaddr, listdelim,
+			                 tokencount, data);
+			myfree(utfline);
 		if(writen(outfd, str, strlen(str)) < 0) {
 			myfree(str);
 			myfree(listaddr);
@@ -405,6 +429,8 @@
 			return NULL;
 		}
 		myfree(str);
+		}
+
 		str = mygetline(infd);
 	}
 
--- a/src/send_digest.c	Mon Sep 20 01:44:58 2010 +1000
+++ b/src/send_digest.c	Mon Sep 20 02:05:31 2010 +1000
@@ -263,7 +263,7 @@
 		utfsub = unistr_escaped_to_utf8(line + 9);
 	}
 
-	utfsub2 = substitute(utfsub, listaddr, listdelim, 5, subst_data, NULL);
+	utfsub2 = substitute(utfsub, listaddr, listdelim, 5, subst_data);
 	subject = unistr_utf8_to_header(utfsub2);
 	myfree(utfsub);
 	myfree(utfsub2);
@@ -362,7 +362,7 @@
 				myfree(line);
 
 				tmp = substitute(utfline, listaddr, listdelim,
-						5, subst_data, NULL);
+						5, subst_data);
 				myfree(utfline);
 
 				if(writen(fd, tmp, strlen(tmp)) < 0) {