]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
Add %originalmail% and restore backward compatibility of $originalmail$.
authorBen Schmidt <none@none>
Mon, 16 Jan 2012 10:30:27 +0000 (21:30 +1100)
committerBen Schmidt <none@none>
Mon, 16 Jan 2012 10:30:27 +0000 (21:30 +1100)
ChangeLog
README.listtexts
include/prepstdreply.h
src/prepstdreply.c
src/send_digest.c

index e9ed29f6f4f8ec650193145eeedd5cd20439d938..925ed56a3c325f72e58ec0103f91654d76835599 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
index f0e5bb295bf3781258b48ddfaddee305e9c54d4a..47c8e92570945fbb24e8a945fa6873f4d2451fa1 100644 (file)
@@ -265,8 +265,7 @@ not appropriate for use in headers. They are:
   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 @@ Unformatted substitutions
   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$
index b4fd440e4b525b77acb9edc59d06acb6cc25f43f..1d3c9a0c43f6d7e1dbca7c90a51fa080dba95e3d 100644 (file)
@@ -35,7 +35,8 @@ text *open_text(const char *listdir, const char *purpose, const char *action,
                   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,
index 54b3b28ee5019b9177a53a0277a00fcc2e35a1cd..9b8fb9c014c138d173f9e4be8a1b72525aee8d8e 100644 (file)
@@ -54,6 +54,8 @@ struct source {
        char *prefix;
        char *suffix;
        int fd;
+       int transparent;
+       int limit;
 };
 
 
@@ -79,6 +81,18 @@ static char *filename_token(char *token) {
 }
 
 
+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 @@ static void substitute_one(char **line_p, char **pos_p, const char *listaddr,
        } 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 @@ text *open_text_file(const char *listdir, const char *filename)
        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 @@ static void begin_new_source_file(text *txt, char **line_p, char **pos_p,
        *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 begin_new_source_file(text *txt, char **line_p, char **pos_p,
 
 
 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 @@ static void handle_directive(text *txt, char **line_p, char **pos_p,
                        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 @@ static void handle_directive(text *txt, char **line_p, char **pos_p,
 
 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 @@ char *get_processed_text_line(text *txt,
                        txt->src->upcoming = NULL;
                        break;
                }
-               txt->src->upcoming = mygetline(txt->src->fd);
+               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 @@ char *get_processed_text_line(text *txt,
                        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 @@ char *get_processed_text_line(text *txt,
                         * 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 @@ char *prepstdreply(const char *listdir, const char *purpose, const char *action,
                   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 @@ char *prepstdreply(const char *listdir, const char *purpose, const char *action,
 
        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 @@ char *prepstdreply(const char *listdir, const char *purpose, const char *action,
 
        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 @@ char *prepstdreply(const char *listdir, const char *purpose, const char *action,
                                retstr = NULL;
                                goto freeandreturn;
                        }
-               }
-
                myfree(line);
                line = get_processed_text_line(txt, listaddr, listdelim,
-                               tokencount, moredata, listdir);
+                               tokencount, moredata, listdir, mailname);
        }
 
        fsync(outfd);
index 156d6af8f7cab282f61240c5fda51dc3b2d4c99f..eb43be676d2c30bc3cce5b72563bbfb797c38f6b 100644 (file)
@@ -256,7 +256,7 @@ int send_digest(const char *listdir, int firstindex, int lastindex,
        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 @@ int send_digest(const char *listdir, int firstindex, int lastindex,
 
                /* 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 @@ errdighdrs:
 
                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';