mlmmj

changeset 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, 83 insertions(+), 49 deletions(-) [+]
line diff
     1.1 --- a/ChangeLog	Mon Sep 20 01:44:58 2010 +1000
     1.2 +++ b/ChangeLog	Mon Sep 20 02:05:31 2010 +1000
     1.3 @@ -1,3 +1,6 @@
     1.4 + o Changes to how $originalmail$ works -- existing installations will change
     1.5 +   behaviour due to this; prepending a space to the lines currently containing
     1.6 +   $originalmail$ in the listtexts will generally retain current behaviour
     1.7   o Allow arbitrary headers in list texts
     1.8   o Ensure digest listtext is always closed
     1.9   o Fix Content-Transfer-Encoding: header for digests and list texts
     2.1 --- a/README.listtexts	Mon Sep 20 01:44:58 2010 +1000
     2.2 +++ b/README.listtexts	Mon Sep 20 02:05:31 2010 +1000
     2.3 @@ -227,8 +227,14 @@
     2.4    the address that has been unsubscribed
     2.5  
     2.6  - $originalmail$
     2.7 -  the first 100 lines (including headers)
     2.8 -  of the email message being processed (usually a mail being moderated)
     2.9 +- $originalmailN$
    2.10 +  the email message being processed (usually a mail being moderated); this must
    2.11 +  appear first on a line, optionally preceded by whitespace: any preceding
    2.12 +  whitespace is prepended to each line of the mail that is included and the
    2.13 +  rest of the line following originalmail$ is ignored; N represents a number,
    2.14 +  which is how many lines of the message (including headers) to include: if
    2.15 +  omitted, 100 will be used, and to include the whole message, use a large
    2.16 +  number like 1000000000.
    2.17  
    2.18  - $posteraddr$
    2.19    (available only in subonlypost)
     3.1 --- a/include/prepstdreply.h	Mon Sep 20 01:44:58 2010 +1000
     3.2 +++ b/include/prepstdreply.h	Mon Sep 20 02:05:31 2010 +1000
     3.3 @@ -25,10 +25,9 @@
     3.4  #define PREPSTDREPLY_H
     3.5  
     3.6  char *substitute(const char *line, const char *listaddr, const char *listdelim,
     3.7 -		size_t datacount, char **data, const char* mailname);
     3.8 +		size_t datacount, char **data);
     3.9  char *substitute_one(const char *line, const char *listaddr,
    3.10 -		const char *listdelim, size_t datacount, char **data,
    3.11 -		const char* mailname);
    3.12 +		const char *listdelim, size_t datacount, char **data);
    3.13  int open_listtext(const char *listdir, const char *filename);
    3.14  char *prepstdreply(const char *listdir, const char *filename, const char *from,
    3.15  		const char *to, const char *replyto, size_t tokencount,
     4.1 --- a/src/prepstdreply.c	Mon Sep 20 01:44:58 2010 +1000
     4.2 +++ b/src/prepstdreply.c	Mon Sep 20 02:05:31 2010 +1000
     4.3 @@ -44,13 +44,13 @@
     4.4  #include "unistr.h"
     4.5  
     4.6  char *substitute(const char *line, const char *listaddr, const char *listdelim,
     4.7 -		 size_t datacount, char **data, const char *mailname)
     4.8 +		 size_t datacount, char **data)
     4.9  {
    4.10  	char *s1, *s2;
    4.11  
    4.12 -	s1 = substitute_one(line, listaddr, listdelim, datacount, data, mailname);
    4.13 +	s1 = substitute_one(line, listaddr, listdelim, datacount, data);
    4.14  	while(s1) {
    4.15 -		s2 = substitute_one(s1, listaddr, listdelim, datacount, data, mailname);
    4.16 +		s2 = substitute_one(s1, listaddr, listdelim, datacount, data);
    4.17  		if(s2) {
    4.18  			myfree(s1);
    4.19  			s1 = s2;
    4.20 @@ -62,8 +62,7 @@
    4.21  }
    4.22  
    4.23  char *substitute_one(const char *line, const char *listaddr,
    4.24 -			const char *listdelim, size_t datacount, char **data,
    4.25 -			const char* mailname)
    4.26 +			const char *listdelim, size_t datacount, char **data)
    4.27  {
    4.28  	char *fqdn, *listname, *d1, *d2, *token, *value = NULL;
    4.29  	char *retstr, *origline;
    4.30 @@ -133,26 +132,6 @@
    4.31  		value = concatstr(4, listname, listdelim, "subscribe-nomail@",
    4.32  				  fqdn);
    4.33  		goto concatandreturn;
    4.34 -	} else if(strcmp(token, "originalmail") == 0) {
    4.35 -		/* append the first 100 lines of the mail inline */
    4.36 -		int mailfd;
    4.37 -		if(mailname && 
    4.38 -		     ((mailfd = open(mailname, O_RDONLY)) > 0)){
    4.39 -			size_t count = 0;
    4.40 -			char* str = NULL;
    4.41 -			while(count < 100 && (str = mygetline(mailfd))) {
    4.42 -				char* tmp = value;
    4.43 -				value = concatstr(3, value, " ", str);
    4.44 -				if(tmp)
    4.45 -					myfree(tmp);
    4.46 -				myfree(str);
    4.47 -				count++;
    4.48 -			}
    4.49 -			close(mailfd);
    4.50 -		}else{
    4.51 -			log_error(LOG_ARGS, "Could not substitute $originalmail$ (mailname == %s)",mailname);
    4.52 -		}
    4.53 -		goto concatandreturn;
    4.54  	}
    4.55  	if(data) {
    4.56  		for(i = 0; i < datacount; i++) {
    4.57 @@ -211,7 +190,7 @@
    4.58  		   char **data, const char *mailname)
    4.59  {
    4.60  	size_t i, len;
    4.61 -	int infd, outfd;
    4.62 +	int infd, outfd, mailfd;
    4.63  	char *listaddr, *listdelim, *tmp, *retstr = NULL;
    4.64  	char *listfqdn, *line, *utfline, *utfsub, *utfsub2;
    4.65  	char *str = NULL;
    4.66 @@ -244,11 +223,11 @@
    4.67  	}
    4.68  
    4.69  	tmp = substitute(from, listaddr, listdelim,
    4.70 -	                 tokencount, data, NULL);
    4.71 +	                 tokencount, data);
    4.72  	headers[0] = concatstr(2, "From: ", tmp);
    4.73  	myfree(tmp);
    4.74  	tmp = substitute(to, listaddr, listdelim,
    4.75 -	                 tokencount, data, NULL);
    4.76 +	                 tokencount, data);
    4.77  	headers[1] = concatstr(2, "To: ", tmp);
    4.78  	myfree(tmp);
    4.79  	headers[2] = genmsgid(listfqdn);
    4.80 @@ -262,7 +241,7 @@
    4.81  
    4.82  	if(replyto) {
    4.83  		tmp = substitute(replyto, listaddr, listdelim,
    4.84 -		                 tokencount, data, NULL);
    4.85 +		                 tokencount, data);
    4.86  		headers[8] = concatstr(2, "Reply-To: ", tmp);
    4.87  		myfree(tmp);
    4.88  	}
    4.89 @@ -286,7 +265,7 @@
    4.90  			   continuation of previous header line */
    4.91  			utfsub = unistr_escaped_to_utf8(line);
    4.92  			str = substitute(utfsub, listaddr, listdelim,
    4.93 -			                 tokencount, data, NULL);
    4.94 +			                 tokencount, data);
    4.95  			myfree(utfsub);
    4.96  			len = strlen(str);
    4.97  			str[len] = '\n';
    4.98 @@ -329,7 +308,7 @@
    4.99  			utfsub = unistr_escaped_to_utf8(tmp);
   4.100  			*tmp = '\0';
   4.101  			utfsub2 = substitute(utfsub, listaddr, listdelim,
   4.102 -			                     tokencount, data, NULL);
   4.103 +			                     tokencount, data);
   4.104  			myfree(utfsub);
   4.105  			if (strncasecmp(line, "Subject:", len) == 0) {
   4.106  				tmp = unistr_utf8_to_header(utfsub2);
   4.107 @@ -393,9 +372,54 @@
   4.108  		utfline = unistr_escaped_to_utf8(str);
   4.109  		myfree(str);
   4.110  
   4.111 -		str = substitute(utfline, listaddr, listdelim, tokencount, data, mailname);
   4.112 +		tmp = utfline;
   4.113 +		while (*tmp && (*tmp == ' ' || *tmp == '\t')) {
   4.114 +			tmp++;
   4.115 +		}
   4.116 +		if (strncmp(tmp,"$originalmail",13) == 0) {
   4.117 +			*tmp = '\0';
   4.118 +			tmp += 13;
   4.119 +			str = tmp;
   4.120 +			while (*tmp >= '0' && *tmp <= '9')
   4.121 +				tmp++;
   4.122 +			if (*tmp == '$') {
   4.123 +				*tmp = '\0';
   4.124 +				len = 100;
   4.125 +				if (str != tmp)
   4.126 +					len = atol(str);
   4.127 +				if (mailname && 
   4.128 +		     		   ((mailfd = open(mailname, O_RDONLY)) > 0)){
   4.129 +		     		    str = NULL;
   4.130 +				    i = 0;
   4.131 +				    while (i < len &&
   4.132 +				           (str = mygetline(mailfd))) {
   4.133 +				        tmp = str;
   4.134 +				        str = concatstr(2,utfline,str);
   4.135 +				        myfree(tmp);
   4.136 +				        if(writen(outfd,str,strlen(str)) < 0) {
   4.137 +				            myfree(str);
   4.138  		myfree(utfline);
   4.139 -
   4.140 +				            myfree(listaddr);
   4.141 +				            myfree(listdelim);
   4.142 +				            myfree(listfqdn);
   4.143 +				            log_error(LOG_ARGS, "Could not write std mail");
   4.144 +				            return NULL;
   4.145 +				        }
   4.146 +				        myfree(str);
   4.147 +				        i++;
   4.148 +				    }
   4.149 +				    close(mailfd);
   4.150 +				} else {
   4.151 +				    log_error(LOG_ARGS, "Could not substitute $originalmail%d$ (mailname == %s)",len,mailname);
   4.152 +				}
   4.153 +			} else {
   4.154 +				log_error(LOG_ARGS, "Bad $originalmailNNN$ substitution");
   4.155 +			}
   4.156 +			myfree(utfline);
   4.157 +		} else {
   4.158 +			str = substitute(utfline, listaddr, listdelim,
   4.159 +			                 tokencount, data);
   4.160 +			myfree(utfline);
   4.161  		if(writen(outfd, str, strlen(str)) < 0) {
   4.162  			myfree(str);
   4.163  			myfree(listaddr);
   4.164 @@ -405,6 +429,8 @@
   4.165  			return NULL;
   4.166  		}
   4.167  		myfree(str);
   4.168 +		}
   4.169 +
   4.170  		str = mygetline(infd);
   4.171  	}
   4.172  
     5.1 --- a/src/send_digest.c	Mon Sep 20 01:44:58 2010 +1000
     5.2 +++ b/src/send_digest.c	Mon Sep 20 02:05:31 2010 +1000
     5.3 @@ -263,7 +263,7 @@
     5.4  		utfsub = unistr_escaped_to_utf8(line + 9);
     5.5  	}
     5.6  
     5.7 -	utfsub2 = substitute(utfsub, listaddr, listdelim, 5, subst_data, NULL);
     5.8 +	utfsub2 = substitute(utfsub, listaddr, listdelim, 5, subst_data);
     5.9  	subject = unistr_utf8_to_header(utfsub2);
    5.10  	myfree(utfsub);
    5.11  	myfree(utfsub2);
    5.12 @@ -362,7 +362,7 @@
    5.13  				myfree(line);
    5.14  
    5.15  				tmp = substitute(utfline, listaddr, listdelim,
    5.16 -						5, subst_data, NULL);
    5.17 +						5, subst_data);
    5.18  				myfree(utfline);
    5.19  
    5.20  				if(writen(fd, tmp, strlen(tmp)) < 0) {