mlmmj

changeset 5edfa9eef6c7

Add $random0$ through $random5$ substitutions
author Ben Schmidt
date Mon, 20 Sep 2010 02:31:03 +1000
parents 926f184eec44
children 32d3f7e3b523
files ChangeLog README.listtexts src/prepstdreply.c
diffstat 3 files changed, 57 insertions(+), 31 deletions(-) [+]
line diff
     1.1 --- a/ChangeLog	Mon Sep 20 02:25:54 2010 +1000
     1.2 +++ b/ChangeLog	Mon Sep 20 02:31:03 2010 +1000
     1.3 @@ -1,3 +1,4 @@
     1.4 + o Add $random0$ through $random5$ substitutions
     1.5   o Add a $subject$ substitution for list texts
     1.6   o Changes to how $originalmail$ works -- existing installations will change
     1.7     behaviour due to this; prepending a space to the lines currently containing
     2.1 --- a/README.listtexts	Mon Sep 20 02:25:54 2010 +1000
     2.2 +++ b/README.listtexts	Mon Sep 20 02:31:03 2010 +1000
     2.3 @@ -241,6 +241,16 @@
     2.4    subonlypost)
     2.5    the from address of the message that was received as determined by Mlmmj
     2.6  
     2.7 +- $random0$
     2.8 +- $random1$
     2.9 +- $random2$
    2.10 +- $random3$
    2.11 +- $random4$
    2.12 +- $random5$
    2.13 +  these are 6 distinct random strings; they allow list texts to be constructed
    2.14 +  that are MIME messages with attachments by using creating boundaries that are
    2.15 +  unlikely to appear in the attached messages
    2.16 +
    2.17  - $subaddr$
    2.18    (available only in submod-moderator and [un]sub-confirm[-digest|-nomail])
    2.19    the address requested to be (un-)subscribed
     3.1 --- a/src/prepstdreply.c	Mon Sep 20 02:25:54 2010 +1000
     3.2 +++ b/src/prepstdreply.c	Mon Sep 20 02:31:03 2010 +1000
     3.3 @@ -194,6 +194,7 @@
     3.4  	char *listaddr, *listdelim, *tmp, *retstr = NULL;
     3.5  	char *listfqdn, *line, *utfline, *utfsub, *utfsub2;
     3.6  	char *str = NULL;
     3.7 +	char **moredata;
     3.8  	char *headers[10] = { NULL }; /* relies on NULL to flag end */
     3.9  
    3.10  	if ((infd = open_listtext(listdir, filename)) < 0) {
    3.11 @@ -206,6 +207,7 @@
    3.12  
    3.13  	do {
    3.14  		tmp = random_str();
    3.15 +		if (retstr)
    3.16  		myfree(retstr);
    3.17  		retstr = concatstr(3, listdir, "/queue/", tmp);
    3.18  		myfree(tmp);
    3.19 @@ -219,15 +221,27 @@
    3.20  		myfree(listaddr);
    3.21  		myfree(listdelim);
    3.22  		myfree(listfqdn);
    3.23 +		myfree(retstr);
    3.24  		return NULL;
    3.25  	}
    3.26  
    3.27 +	moredata = mymalloc(2*(tokencount+6) * sizeof(char *));
    3.28 +	for (i=0; i<2*tokencount; i++) {
    3.29 +		moredata[i] = data[i];
    3.30 +	}
    3.31 +	for (i=0; i<6; i++) {
    3.32 +		moredata[2*(tokencount+i)] = mystrdup("randomN");
    3.33 +		moredata[2*(tokencount+i)][6] = '0' + i;
    3.34 +		moredata[2*(tokencount+i)+1] = random_str();
    3.35 +	}
    3.36 +	tokencount += 6;
    3.37 +
    3.38  	tmp = substitute(from, listaddr, listdelim,
    3.39 -	                 tokencount, data);
    3.40 +	                 tokencount, moredata);
    3.41  	headers[0] = concatstr(2, "From: ", tmp);
    3.42  	myfree(tmp);
    3.43  	tmp = substitute(to, listaddr, listdelim,
    3.44 -	                 tokencount, data);
    3.45 +	                 tokencount, moredata);
    3.46  	headers[1] = concatstr(2, "To: ", tmp);
    3.47  	myfree(tmp);
    3.48  	headers[2] = genmsgid(listfqdn);
    3.49 @@ -241,7 +255,7 @@
    3.50  
    3.51  	if(replyto) {
    3.52  		tmp = substitute(replyto, listaddr, listdelim,
    3.53 -		                 tokencount, data);
    3.54 +		                 tokencount, moredata);
    3.55  		headers[8] = concatstr(2, "Reply-To: ", tmp);
    3.56  		myfree(tmp);
    3.57  	}
    3.58 @@ -265,7 +279,7 @@
    3.59  			   continuation of previous header line */
    3.60  			utfsub = unistr_escaped_to_utf8(line);
    3.61  			str = substitute(utfsub, listaddr, listdelim,
    3.62 -			                 tokencount, data);
    3.63 +			                 tokencount, moredata);
    3.64  			myfree(utfsub);
    3.65  			len = strlen(str);
    3.66  			str[len] = '\n';
    3.67 @@ -273,10 +287,9 @@
    3.68  				log_error(LOG_ARGS, "Could not write std mail");
    3.69  				myfree(str);
    3.70  				myfree(line);
    3.71 -				myfree(listaddr);
    3.72 -				myfree(listdelim);
    3.73 -				myfree(listfqdn);
    3.74 -				return NULL;
    3.75 +				myfree(retstr);
    3.76 +				retstr = NULL;
    3.77 +				goto freeandreturn;
    3.78  			}
    3.79  			myfree(str);
    3.80  		} else {
    3.81 @@ -308,7 +321,7 @@
    3.82  			utfsub = unistr_escaped_to_utf8(tmp);
    3.83  			*tmp = '\0';
    3.84  			utfsub2 = substitute(utfsub, listaddr, listdelim,
    3.85 -			                     tokencount, data);
    3.86 +			                     tokencount, moredata);
    3.87  			myfree(utfsub);
    3.88  			if (strncasecmp(line, "Subject:", len) == 0) {
    3.89  				tmp = unistr_utf8_to_header(utfsub2);
    3.90 @@ -325,10 +338,9 @@
    3.91  				log_error(LOG_ARGS, "Could not write std mail");
    3.92  				myfree(str);
    3.93  				myfree(line);
    3.94 -				myfree(listaddr);
    3.95 -				myfree(listdelim);
    3.96 -				myfree(listfqdn);
    3.97 -				return NULL;
    3.98 +				myfree(retstr);
    3.99 +				retstr = NULL;
   3.100 +				goto freeandreturn;
   3.101  			}
   3.102  			myfree(str);
   3.103  		}
   3.104 @@ -343,10 +355,9 @@
   3.105  			if (line)
   3.106  				myfree(line);
   3.107  			myfree(str);
   3.108 -			myfree(listaddr);
   3.109 -			myfree(listdelim);
   3.110 -			myfree(listfqdn);
   3.111 -			return NULL;
   3.112 +			myfree(retstr);
   3.113 +			retstr = NULL;
   3.114 +			goto freeandreturn;
   3.115  		}
   3.116  	}
   3.117  
   3.118 @@ -356,10 +367,9 @@
   3.119  		myfree(str);
   3.120  		if (line)
   3.121  			myfree(line);
   3.122 -		myfree(listaddr);
   3.123 -		myfree(listdelim);
   3.124 -		myfree(listfqdn);
   3.125 -		return NULL;
   3.126 +		myfree(retstr);
   3.127 +		retstr = NULL;
   3.128 +		goto freeandreturn;
   3.129  	}
   3.130  
   3.131  	if (line) {
   3.132 @@ -399,11 +409,10 @@
   3.133  				        if(writen(outfd,str,strlen(str)) < 0) {
   3.134  				            myfree(str);
   3.135  				            myfree(utfline);
   3.136 -				            myfree(listaddr);
   3.137 -				            myfree(listdelim);
   3.138 -				            myfree(listfqdn);
   3.139  				            log_error(LOG_ARGS, "Could not write std mail");
   3.140 -				            return NULL;
   3.141 +					    myfree(retstr);
   3.142 +					    retstr = NULL;
   3.143 +					    goto freeandreturn;
   3.144  				        }
   3.145  				        myfree(str);
   3.146  				        i++;
   3.147 @@ -418,15 +427,14 @@
   3.148  			myfree(utfline);
   3.149  		} else {
   3.150  			str = substitute(utfline, listaddr, listdelim,
   3.151 -			                 tokencount, data);
   3.152 +			                 tokencount, moredata);
   3.153  			myfree(utfline);
   3.154  			if(writen(outfd, str, strlen(str)) < 0) {
   3.155  				myfree(str);
   3.156 -				myfree(listaddr);
   3.157 -				myfree(listdelim);
   3.158 -				myfree(listfqdn);
   3.159  				log_error(LOG_ARGS, "Could not write std mail");
   3.160 -				return NULL;
   3.161 +				myfree(retstr);
   3.162 +				retstr = NULL;
   3.163 +				goto freeandreturn;
   3.164  			}
   3.165  			myfree(str);
   3.166  		}
   3.167 @@ -437,9 +445,16 @@
   3.168  	fsync(outfd);
   3.169  	close(outfd);
   3.170  
   3.171 +freeandreturn:
   3.172  	myfree(listaddr);
   3.173  	myfree(listdelim);
   3.174  	myfree(listfqdn);
   3.175  
   3.176 +	for (i=tokencount-6; i<tokencount; i++) {
   3.177 +		myfree(moredata[2*i]);
   3.178 +		myfree(moredata[2*i+1]);
   3.179 +	}
   3.180 +	myfree(moredata);
   3.181 +
   3.182  	return retstr;
   3.183  }