mlmmj

changeset ecb991e41a4c

Add $controlN$ substitution The interfaces to substitute() and substitute_one() have changed, as they now need to know the listdir to be able to find control files
author Ben Schmidt
date Wed, 06 Oct 2010 23:30:26 +1100
parents b58fd7980358
children bb803487199c
files ChangeLog README.listtexts include/ctrlvalue.h include/mygetline.h include/prepstdreply.h src/Makefile.am src/ctrlvalue.c src/mygetline.c src/prepstdreply.c src/send_digest.c
diffstat 10 files changed, 90 insertions(+), 27 deletions(-) [+]
line diff
     1.1 --- a/ChangeLog	Wed Oct 06 23:26:26 2010 +1100
     1.2 +++ b/ChangeLog	Wed Oct 06 23:30:26 2010 +1100
     1.3 @@ -1,3 +1,4 @@
     1.4 + o Add $controlN$ substitution
     1.5   o Fix theoretically possible memory corruption by chomp()
     1.6   o Remove .sh from mlmmj-make-ml.sh; symlink original name
     1.7   o Correct spelling of 'receive' and 'voodoo' throughout the code and
     2.1 --- a/README.listtexts	Wed Oct 06 23:26:26 2010 +1100
     2.2 +++ b/README.listtexts	Wed Oct 06 23:30:26 2010 +1100
     2.3 @@ -149,6 +149,11 @@
     2.4    the address to which to send mail to confirm the (un-)subscription in
     2.5    question
     2.6  
     2.7 +- $controlN$
     2.8 +  the contents of the control file named N, with its final newline stripped; N
     2.9 +  represents the name of the file to be found in the list's control
    2.10 +  subdirectory; the name may only include letters and digits
    2.11 +
    2.12  - $digestfirst$
    2.13    (available only in digest)
    2.14    index of the first message included in a digest
     3.1 --- a/include/ctrlvalue.h	Wed Oct 06 23:26:26 2010 +1100
     3.2 +++ b/include/ctrlvalue.h	Wed Oct 06 23:30:26 2010 +1100
     3.3 @@ -25,5 +25,6 @@
     3.4  #define CTRLVALUE_H
     3.5  
     3.6  char *ctrlvalue(const char *listdir, const char *ctrlstr);
     3.7 +char *ctrlcontent(const char *listdir, const char *ctrlstr);
     3.8  
     3.9  #endif /* CTRLVALUE_H */
     4.1 --- a/include/mygetline.h	Wed Oct 06 23:26:26 2010 +1100
     4.2 +++ b/include/mygetline.h	Wed Oct 06 23:30:26 2010 +1100
     4.3 @@ -31,5 +31,6 @@
     4.4  char *myfgetline(FILE *infile);
     4.5  #endif
     4.6  char *mygetline(int fd);
     4.7 +char *mygetcontent(int fd);
     4.8  
     4.9  #endif /* #ifndef MYGETLINE_H */
     5.1 --- a/include/prepstdreply.h	Wed Oct 06 23:26:26 2010 +1100
     5.2 +++ b/include/prepstdreply.h	Wed Oct 06 23:30:26 2010 +1100
     5.3 @@ -25,9 +25,9 @@
     5.4  #define PREPSTDREPLY_H
     5.5  
     5.6  char *substitute(const char *line, const char *listaddr, const char *listdelim,
     5.7 -		size_t datacount, char **data);
     5.8 +		size_t datacount, char **data, const char *listdir);
     5.9  char *substitute_one(const char *line, const char *listaddr,
    5.10 -		const char *listdelim, size_t datacount, char **data);
    5.11 +		const char *listdelim, size_t datacount, char **data, const char *listdir);
    5.12  int open_listtext(const char *listdir, const char *filename);
    5.13  char *prepstdreply(const char *listdir, const char *filename, const char *from,
    5.14  		const char *to, const char *replyto, size_t tokencount,
     6.1 --- a/src/Makefile.am	Wed Oct 06 23:26:26 2010 +1100
     6.2 +++ b/src/Makefile.am	Wed Oct 06 23:30:26 2010 +1100
     6.3 @@ -37,19 +37,19 @@
     6.4  			subscriberfuncs.c print-version.c \
     6.5  			log_error.c mygetline.c prepstdreply.c memory.c \
     6.6  			statctrl.c readn.c getlistdelim.c ctrlvalues.c \
     6.7 -			unistr.c
     6.8 +			unistr.c ctrlvalue.c
     6.9  
    6.10  mlmmj_unsub_SOURCES = mlmmj-unsub.c writen.c mylocking.c \
    6.11  			getlistaddr.c chomp.c subscriberfuncs.c random-int.c \
    6.12  			strgen.c print-version.c log_error.c mygetline.c \
    6.13  			prepstdreply.c memory.c statctrl.c readn.c \
    6.14 -			getlistdelim.c unistr.c
    6.15 +			getlistdelim.c unistr.c ctrlvalue.c
    6.16  			
    6.17  mlmmj_bounce_SOURCES = mlmmj-bounce.c print-version.c log_error.c \
    6.18  		       subscriberfuncs.c strgen.c random-int.c writen.c \
    6.19  		       prepstdreply.c mygetline.c chomp.c getlistaddr.c \
    6.20  		       memory.c find_email_adr.c gethdrline.c readn.c \
    6.21 -		       getlistdelim.c unistr.c
    6.22 +		       getlistdelim.c unistr.c ctrlvalue.c
    6.23  
    6.24  mlmmj_maintd_SOURCES = mlmmj-maintd.c print-version.c log_error.c mygetline.c \
    6.25  		       strgen.c random-int.c chomp.c writen.c memory.c \
     7.1 --- a/src/ctrlvalue.c	Wed Oct 06 23:26:26 2010 +1100
     7.2 +++ b/src/ctrlvalue.c	Wed Oct 06 23:30:26 2010 +1100
     7.3 @@ -33,10 +33,10 @@
     7.4  #include "chomp.h"
     7.5  #include "memory.h"
     7.6  
     7.7 -char *ctrlvalue(const char *listdir, const char *ctrlstr)
     7.8 +static char *ctrlval(const char *listdir, const char *ctrlstr, int oneline)
     7.9  {
    7.10  	char *filename, *value = NULL;
    7.11 -	int ctrlfd;
    7.12 +	int ctrlfd, i;
    7.13  
    7.14  	if(listdir == NULL)
    7.15  		return NULL;
    7.16 @@ -48,12 +48,32 @@
    7.17  	if(ctrlfd < 0)
    7.18  		return NULL;
    7.19  		
    7.20 +	if (oneline) {
    7.21  	value = mygetline(ctrlfd);
    7.22 +		chomp(value);
    7.23 +	} else {
    7.24 +		value = mygetcontent(ctrlfd);
    7.25 +		i = strlen(value) - 1;
    7.26 +		if (i >= 0 && value[i] == '\n') {
    7.27 +			value[i] = '\0';
    7.28 +			i--;
    7.29 +		}
    7.30 +		if (i >= 0 && value[i] == '\r') {
    7.31 +			value[i] = '\0';
    7.32 +			i--;
    7.33 +		}
    7.34 +	}
    7.35  	close(ctrlfd);
    7.36 -	chomp(value);
    7.37  
    7.38  	return value;
    7.39  }
    7.40  
    7.41 +char *ctrlvalue(const char *listdir, const char *ctrlstr)
    7.42 +{
    7.43 +	return ctrlval(listdir, ctrlstr, 1);
    7.44 +}
    7.45  	
    7.46 -	
    7.47 +char *ctrlcontent(const char *listdir, const char *ctrlstr)
    7.48 +{
    7.49 +	return ctrlval(listdir, ctrlstr, 0);
    7.50 +}
     8.1 --- a/src/mygetline.c	Wed Oct 06 23:26:26 2010 +1100
     8.2 +++ b/src/mygetline.c	Wed Oct 06 23:30:26 2010 +1100
     8.3 @@ -30,7 +30,7 @@
     8.4  #include "mygetline.h"
     8.5  #include "memory.h"
     8.6  
     8.7 -char *mygetline(int fd)
     8.8 +static char *mygetuntil(int fd, char eof)
     8.9  {
    8.10  	size_t i = 0, res, buf_size = BUFSIZE;  /* initial buffer size */
    8.11  	char *buf, ch;
    8.12 @@ -62,9 +62,19 @@
    8.13  			buf = myrealloc(buf, buf_size);
    8.14  		}
    8.15  		buf[i++] = ch;
    8.16 -		if(ch == '\n') {
    8.17 +		if(ch == eof) {
    8.18  			buf[i] = '\0';
    8.19  			return buf;
    8.20  		}
    8.21  	}
    8.22  }
    8.23 +
    8.24 +char *mygetline(int fd)
    8.25 +{
    8.26 +	return mygetuntil(fd, '\n');
    8.27 +}
    8.28 +
    8.29 +char *mygetcontent(int fd)
    8.30 +{
    8.31 +	return mygetuntil(fd, '\0');
    8.32 +}
     9.1 --- a/src/prepstdreply.c	Wed Oct 06 23:26:26 2010 +1100
     9.2 +++ b/src/prepstdreply.c	Wed Oct 06 23:30:26 2010 +1100
     9.3 @@ -32,6 +32,7 @@
     9.4  #include <errno.h>
     9.5  
     9.6  #include "prepstdreply.h"
     9.7 +#include "ctrlvalue.h"
     9.8  #include "strgen.h"
     9.9  #include "chomp.h"
    9.10  #include "log_error.h"
    9.11 @@ -44,13 +45,15 @@
    9.12  #include "unistr.h"
    9.13  
    9.14  char *substitute(const char *line, const char *listaddr, const char *listdelim,
    9.15 -		 size_t datacount, char **data)
    9.16 +		 size_t datacount, char **data, const char *listdir)
    9.17  {
    9.18  	char *s1, *s2;
    9.19  
    9.20 -	s1 = substitute_one(line, listaddr, listdelim, datacount, data);
    9.21 +	s1 = substitute_one(line, listaddr, listdelim, datacount, data,
    9.22 +			listdir);
    9.23  	while(s1) {
    9.24 -		s2 = substitute_one(s1, listaddr, listdelim, datacount, data);
    9.25 +		s2 = substitute_one(s1, listaddr, listdelim, datacount, data,
    9.26 +				listdir);
    9.27  		if(s2) {
    9.28  			myfree(s1);
    9.29  			s1 = s2;
    9.30 @@ -62,7 +65,8 @@
    9.31  }
    9.32  
    9.33  char *substitute_one(const char *line, const char *listaddr,
    9.34 -			const char *listdelim, size_t datacount, char **data)
    9.35 +			const char *listdelim, size_t datacount, char **data,
    9.36 +			const char *listdir)
    9.37  {
    9.38  	char *fqdn, *listname, *d1, *d2, *token, *value = NULL;
    9.39  	char *retstr, *origline;
    9.40 @@ -132,6 +136,27 @@
    9.41  		value = concatstr(4, listname, listdelim, "subscribe-nomail@",
    9.42  				  fqdn);
    9.43  		goto concatandreturn;
    9.44 +	} else if(strncmp(token, "control", 7) == 0) {
    9.45 +		value = token + 7;
    9.46 +		if(*value == '\0') {
    9.47 +			value = mystrdup("");
    9.48 +			goto concatandreturn;
    9.49 +		}
    9.50 +		for(; *value != '\0'; value++) {
    9.51 +			if(*value >= '0' && *value <= '9') continue;
    9.52 +			if(*value >= 'A' && *value <= 'Z') continue;
    9.53 +			if(*value >= 'a' && *value <= 'z') continue;
    9.54 +			break;
    9.55 +		}
    9.56 +		if(*value != '\0') {
    9.57 +			value = mystrdup(token + 7);
    9.58 +			goto concatandreturn;
    9.59 +		}
    9.60 +		value = token + 7;
    9.61 +		value = ctrlcontent(listdir, value);
    9.62 +		if (value == NULL)
    9.63 +			value = mystrdup("");
    9.64 +		goto concatandreturn;
    9.65  	}
    9.66  	if(data) {
    9.67  		for(i = 0; i < datacount; i++) {
    9.68 @@ -237,11 +262,11 @@
    9.69  	tokencount += 6;
    9.70  
    9.71  	tmp = substitute(from, listaddr, listdelim,
    9.72 -	                 tokencount, moredata);
    9.73 +	                 tokencount, moredata, listdir);
    9.74  	headers[0] = concatstr(2, "From: ", tmp);
    9.75  	myfree(tmp);
    9.76  	tmp = substitute(to, listaddr, listdelim,
    9.77 -	                 tokencount, moredata);
    9.78 +	                 tokencount, moredata, listdir);
    9.79  	headers[1] = concatstr(2, "To: ", tmp);
    9.80  	myfree(tmp);
    9.81  	headers[2] = genmsgid(listfqdn);
    9.82 @@ -255,7 +280,7 @@
    9.83  
    9.84  	if(replyto) {
    9.85  		tmp = substitute(replyto, listaddr, listdelim,
    9.86 -		                 tokencount, moredata);
    9.87 +		                 tokencount, moredata, listdir);
    9.88  		headers[8] = concatstr(2, "Reply-To: ", tmp);
    9.89  		myfree(tmp);
    9.90  	}
    9.91 @@ -279,7 +304,7 @@
    9.92  			   continuation of previous header line */
    9.93  			utfsub = unistr_escaped_to_utf8(line);
    9.94  			str = substitute(utfsub, listaddr, listdelim,
    9.95 -			                 tokencount, moredata);
    9.96 +			                 tokencount, moredata, listdir);
    9.97  			myfree(utfsub);
    9.98  			len = strlen(str);
    9.99  			str[len] = '\n';
   9.100 @@ -321,7 +346,7 @@
   9.101  			utfsub = unistr_escaped_to_utf8(tmp);
   9.102  			*tmp = '\0';
   9.103  			utfsub2 = substitute(utfsub, listaddr, listdelim,
   9.104 -			                     tokencount, moredata);
   9.105 +			                     tokencount, moredata, listdir);
   9.106  			myfree(utfsub);
   9.107  			if (strncasecmp(line, "Subject:", len) == 0) {
   9.108  				tmp = unistr_utf8_to_header(utfsub2);
   9.109 @@ -427,7 +452,7 @@
   9.110  			myfree(utfline);
   9.111  		} else {
   9.112  			str = substitute(utfline, listaddr, listdelim,
   9.113 -			                 tokencount, moredata);
   9.114 +			                 tokencount, moredata, listdir);
   9.115  			myfree(utfline);
   9.116  			if(writen(outfd, str, strlen(str)) < 0) {
   9.117  				myfree(str);
    10.1 --- a/src/send_digest.c	Wed Oct 06 23:26:26 2010 +1100
    10.2 +++ b/src/send_digest.c	Wed Oct 06 23:30:26 2010 +1100
    10.3 @@ -263,7 +263,7 @@
    10.4  		utfsub = unistr_escaped_to_utf8(line + 9);
    10.5  	}
    10.6  
    10.7 -	utfsub2 = substitute(utfsub, listaddr, listdelim, 5, subst_data);
    10.8 +	utfsub2 = substitute(utfsub, listaddr, listdelim, 5, subst_data, listdir);
    10.9  	subject = unistr_utf8_to_header(utfsub2);
   10.10  	myfree(utfsub);
   10.11  	myfree(utfsub2);
   10.12 @@ -362,7 +362,7 @@
   10.13  				myfree(line);
   10.14  
   10.15  				tmp = substitute(utfline, listaddr, listdelim,
   10.16 -						5, subst_data);
   10.17 +						5, subst_data, listdir);
   10.18  				myfree(utfline);
   10.19  
   10.20  				if(writen(fd, tmp, strlen(tmp)) < 0) {