# HG changeset patch # User Ben Schmidt # Date 1326709827 -39600 # Node ID 262752ddbbf5e8622d6b185d0a6521020c5e6e7a # Parent 8ddfc2d59a3fb1c156b30b822b94797ac9d4a0da Add %originalmail% and restore backward compatibility of $originalmail$. diff -r 8ddfc2d59a3f -r 262752ddbbf5 ChangeLog --- a/ChangeLog Mon Jan 16 21:29:19 2012 +1100 +++ b/ChangeLog Mon Jan 16 21:30:27 2012 +1100 @@ -1,3 +1,5 @@ + o Add %originalmail% directive and restore backward compatibility of + $originalmail$ o Allow more characters in control and text filenames for substitutions o Add %%, %^%, %comment%, %control C% and %text T% formatting directives o Allow a space in $originalmail N$ substitution @@ -30,9 +32,7 @@ o Richer MIME list texts with inline messages (English only so far) o Add $random0$ through $random5$ substitutions o Add a $subject$ substitution for list texts - 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 Changes to how $originalmail$ works 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 diff -r 8ddfc2d59a3f -r 262752ddbbf5 README.listtexts --- a/README.listtexts Mon Jan 16 21:29:19 2012 +1100 +++ b/README.listtexts Mon Jan 16 21:30:27 2012 +1100 @@ -265,8 +265,7 @@ deny-post-{access|maxmailsize|tocc|subonlypost}) the email message being processed (usually a mail being moderated); N represents a number, which is how many lines of the message (including - headers) to include: if omitted, 100 will be used; to include the whole - message, use a large number like 1000000000 + headers) to include: if omitted, the whole message will be included - %digestthreads% (available only in digest) @@ -434,7 +433,7 @@ the address that has been unsubscribed - $originalmail$ - the same as %originalmail% preceded by a space + the same as %originalmail 100% preceded by a space DEPRECATED: use %originalmail% - $posteraddr$ diff -r 8ddfc2d59a3f -r 262752ddbbf5 include/prepstdreply.h --- a/include/prepstdreply.h Mon Jan 16 21:29:19 2012 +1100 +++ b/include/prepstdreply.h Mon Jan 16 21:30:27 2012 +1100 @@ -35,7 +35,8 @@ const char *reason, const char *type, const char *compat); char *get_processed_text_line(text *txt, const char *listaddr, const char *listdelim, - size_t datacount, char **data, const char *listdir); + size_t datacount, char **data, const char *listdir, + const char *mailname); void close_text(text *txt); char *prepstdreply(const char *listdir, const char *purpose, const char *action, const char *reason, const char *type, const char *compat, diff -r 8ddfc2d59a3f -r 262752ddbbf5 src/prepstdreply.c --- a/src/prepstdreply.c Mon Jan 16 21:29:19 2012 +1100 +++ b/src/prepstdreply.c Mon Jan 16 21:30:27 2012 +1100 @@ -54,6 +54,8 @@ char *prefix; char *suffix; int fd; + int transparent; + int limit; }; @@ -79,6 +81,18 @@ } +static char *numeric_token(char *token) { + char *pos; + if (*token == '\0') return NULL; + for(pos = token; *pos != '\0'; pos++) { + if(*pos >= '0' && *pos <= '9') continue; + break; + } + if (*pos != '\0') return NULL; + return token; +} + + static void substitute_one(char **line_p, char **pos_p, const char *listaddr, const char *listdelim, size_t datacount, char **data, const char *listdir) @@ -154,6 +168,9 @@ } else if(strncmp(token, "text ", 5) == 0) { token = filename_token(token + 5); if (token != NULL) value = textcontent(listdir, token); + } else if(strcmp(token, "originalmail") == 0) { + /* DEPRECATED: use %originalmail% instead */ + value = mystrdup(" %originalmail 100%"); } else if(data) { for(i = 0; i < datacount; i++) { if(strcmp(token, data[i*2]) == 0) { @@ -216,6 +233,8 @@ txt->src->upcoming = NULL; txt->src->prefix = NULL; txt->src->suffix = NULL; + txt->src->transparent = 0; + txt->src->limit = -1; tmp = concatstr(3, listdir, "/text/", filename); txt->src->fd = open(tmp, O_RDONLY); @@ -307,6 +326,8 @@ *tmp = '\0'; src->suffix = NULL; src->fd = fd; + src->transparent = 0; + src->limit = -1; txt->src = src; tmp = mygetline(fd); line = concatstr(2, line, tmp); @@ -318,12 +339,13 @@ static void handle_directive(text *txt, char **line_p, char **pos_p, - const char *listdir) { + const char *listdir, const char *mailname) { char *line = *line_p; char *pos = *pos_p; char *token = pos + 1; char *endpos; char *filename; + int limit; endpos = strchr(token, '%'); if (endpos == NULL) { @@ -375,6 +397,25 @@ myfree(filename); return; } + } else if(strncmp(token, "originalmail", 12) == 0 && mailname != NULL) { + token += 12; + limit = 0; + if (*token == '\0') { + limit = -1; + } else if (*token == ' ') { + token = numeric_token(token + 1); + if (token != NULL) limit = atol(token); + } else { + token = numeric_token(token); + if (token != NULL) limit = atol(token); + } + if (limit != 0) { + begin_new_source_file(txt, line_p, pos_p, mailname); + txt->src->transparent = 1; + if (limit == -1) txt->src->limit = -1; + else txt->src->limit = limit - 1; + return; + } } if (token == NULL) { /* We have encountered a directive, but not been able to deal @@ -395,7 +436,8 @@ char *get_processed_text_line(text *txt, const char *listaddr, const char *listdelim, - size_t datacount, char **data, const char *listdir) + size_t datacount, char **data, const char *listdir, + const char *mailname) { char *line = NULL; char *pos; @@ -413,7 +455,12 @@ txt->src->upcoming = NULL; break; } + if (txt->src->limit != 0) { txt->src->upcoming = mygetline(txt->src->fd); + if (txt->src->limit > 0) txt->src->limit--; + } else { + txt->src->upcoming = NULL; + } if (txt->src->upcoming != NULL) continue; close(txt->src->fd); src = txt->src; @@ -441,6 +488,9 @@ if (*pos == '\0') break; txt->src->upcoming = mystrdup(pos); break; + } else if (txt->src->transparent) { + /* Do nothing if the file is to be included + * transparently */ } else if (*pos == '$') { substitute_one(&line, &pos, listaddr, listdelim, @@ -449,7 +499,7 @@ * to process, so continue straight away. */ continue; } else if (*pos == '%') { - handle_directive(txt, &line, &pos, listdir); + handle_directive(txt, &line, &pos, listdir, mailname); /* The function sets up for the next character * to process, so continue straight away. */ continue; @@ -484,7 +534,7 @@ size_t tokencount, char **data, const char *mailname) { size_t len, i; - int outfd, mailfd; + int outfd; text *txt; char *listaddr, *listdelim, *tmp, *retstr = NULL; char *listfqdn, *line; @@ -557,7 +607,7 @@ for(;;) { line = get_processed_text_line(txt, listaddr, listdelim, - tokencount, moredata, listdir); + tokencount, moredata, listdir, NULL); if (!line) { log_error(LOG_ARGS, "No body in listtext"); break; @@ -650,55 +700,9 @@ if (line == NULL) { line = get_processed_text_line(txt, listaddr, listdelim, - tokencount, moredata, listdir); + tokencount, moredata, listdir, mailname); } while(line) { - tmp = line; - while (*tmp && (*tmp == ' ' || *tmp == '\t')) { - tmp++; - } - if (strncmp(tmp,"$originalmail",13) == 0) { - *tmp = '\0'; - tmp += 13; - str = tmp; - if (*tmp == ' ') { - tmp++; - 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,line,str); - myfree(tmp); - if(writen(outfd,str,strlen(str)) < 0) { - myfree(str); - log_error(LOG_ARGS, "Could not write std mail"); - myfree(retstr); - retstr = NULL; - goto freeandreturn; - } - 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 $originalmail N$ substitution"); - } - } else { len = strlen(line); line[len] = '\n'; if(writen(outfd, line, len+1) < 0) { @@ -708,11 +712,9 @@ retstr = NULL; goto freeandreturn; } - } - myfree(line); line = get_processed_text_line(txt, listaddr, listdelim, - tokencount, moredata, listdir); + tokencount, moredata, listdir, mailname); } fsync(outfd); diff -r 8ddfc2d59a3f -r 262752ddbbf5 src/send_digest.c --- a/src/send_digest.c Mon Jan 16 21:29:19 2012 +1100 +++ b/src/send_digest.c Mon Jan 16 21:30:27 2012 +1100 @@ -256,7 +256,7 @@ if (txt == NULL) goto fallback_subject; line = get_processed_text_line(txt, listaddr, listdelim, - 5, subst_data, listdir); + 5, subst_data, listdir, NULL); if (line == NULL) { log_error(LOG_ARGS, "No content in digest listtext"); @@ -284,7 +284,7 @@ /* Skip the empty line after the subject */ line = get_processed_text_line(txt, listaddr, listdelim, - 5, subst_data, listdir); + 5, subst_data, listdir, NULL); if (line == NULL || *line != '\0') { log_error(LOG_ARGS, "Too many headers " "in digest listtext"); @@ -389,7 +389,7 @@ for (;;) { line = get_processed_text_line(txt, listaddr, listdelim, - 5, subst_data, listdir); + 5, subst_data, listdir, NULL); if (line == NULL) break; len = strlen(line); line[len] = '\n';