]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
Changes to how $originalmail$ works
authorBen Schmidt <none@none>
Sun, 19 Sep 2010 16:05:31 +0000 (02:05 +1000)
committerBen Schmidt <none@none>
Sun, 19 Sep 2010 16:05:31 +0000 (02:05 +1000)
- 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.

ChangeLog
README.listtexts
include/prepstdreply.h
src/prepstdreply.c
src/send_digest.c

index f59a0d0126ce85c7625976f1dce9ad933d0c0b36..47c931bf624c0480710cd4cf350fa4bda02bc0f2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+ 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 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 fa6266f92108cbbec3931fc02e17d17a45a0f930..ba63b7e9a75030ee3a67d8932b7f2be6f8a87a55 100644 (file)
@@ -227,8 +227,14 @@ multi-line substitutions and would not work in a header):
   the address that has been unsubscribed
 
 - $originalmail$
-  the first 100 lines (including headers)
-  of the email message being processed (usually a mail being moderated)
+- $originalmailN$
+  the email message being processed (usually a mail being moderated); this must
+  appear first on a line, optionally preceded by whitespace: any preceding
+  whitespace is prepended to each line of the mail that is included and the
+  rest of the line following originalmail$ is ignored; N represents a number,
+  which is how many lines of the message (including headers) to include: if
+  omitted, 100 will be used, and to include the whole message, use a large
+  number like 1000000000.
 
 - $posteraddr$
   (available only in subonlypost)
index 9f39f227698e0f81eeaac20d238071f3a48fb733..b8c90ba6e177a3c8a881d7eea87cc3b1107cebef 100644 (file)
 #define PREPSTDREPLY_H
 
 char *substitute(const char *line, const char *listaddr, const char *listdelim,
-               size_t datacount, char **data, const char* mailname);
+               size_t datacount, char **data);
 char *substitute_one(const char *line, const char *listaddr,
-               const char *listdelim, size_t datacount, char **data,
-               const char* mailname);
+               const char *listdelim, size_t datacount, char **data);
 int open_listtext(const char *listdir, const char *filename);
 char *prepstdreply(const char *listdir, const char *filename, const char *from,
                const char *to, const char *replyto, size_t tokencount,
index 95295bace8c9e07bd52f9737929ec2db99296081..493b82651653069ed5128bf6d6531fb1e6baa3fd 100644 (file)
 #include "unistr.h"
 
 char *substitute(const char *line, const char *listaddr, const char *listdelim,
-                size_t datacount, char **data, const char *mailname)
+                size_t datacount, char **data)
 {
        char *s1, *s2;
 
-       s1 = substitute_one(line, listaddr, listdelim, datacount, data, mailname);
+       s1 = substitute_one(line, listaddr, listdelim, datacount, data);
        while(s1) {
-               s2 = substitute_one(s1, listaddr, listdelim, datacount, data, mailname);
+               s2 = substitute_one(s1, listaddr, listdelim, datacount, data);
                if(s2) {
                        myfree(s1);
                        s1 = s2;
@@ -62,8 +62,7 @@ char *substitute(const char *line, const char *listaddr, const char *listdelim,
 }
 
 char *substitute_one(const char *line, const char *listaddr,
-                       const char *listdelim, size_t datacount, char **data,
-                       const char* mailname)
+                       const char *listdelim, size_t datacount, char **data)
 {
        char *fqdn, *listname, *d1, *d2, *token, *value = NULL;
        char *retstr, *origline;
@@ -133,26 +132,6 @@ char *substitute_one(const char *line, const char *listaddr,
                value = concatstr(4, listname, listdelim, "subscribe-nomail@",
                                  fqdn);
                goto concatandreturn;
-       } else if(strcmp(token, "originalmail") == 0) {
-               /* append the first 100 lines of the mail inline */
-               int mailfd;
-               if(mailname && 
-                    ((mailfd = open(mailname, O_RDONLY)) > 0)){
-                       size_t count = 0;
-                       char* str = NULL;
-                       while(count < 100 && (str = mygetline(mailfd))) {
-                               char* tmp = value;
-                               value = concatstr(3, value, " ", str);
-                               if(tmp)
-                                       myfree(tmp);
-                               myfree(str);
-                               count++;
-                       }
-                       close(mailfd);
-               }else{
-                       log_error(LOG_ARGS, "Could not substitute $originalmail$ (mailname == %s)",mailname);
-               }
-               goto concatandreturn;
        }
        if(data) {
                for(i = 0; i < datacount; i++) {
@@ -211,7 +190,7 @@ char *prepstdreply(const char *listdir, const char *filename, const char *from,
                   char **data, const char *mailname)
 {
        size_t i, len;
-       int infd, outfd;
+       int infd, outfd, mailfd;
        char *listaddr, *listdelim, *tmp, *retstr = NULL;
        char *listfqdn, *line, *utfline, *utfsub, *utfsub2;
        char *str = NULL;
@@ -244,11 +223,11 @@ char *prepstdreply(const char *listdir, const char *filename, const char *from,
        }
 
        tmp = substitute(from, listaddr, listdelim,
-                        tokencount, data, NULL);
+                        tokencount, data);
        headers[0] = concatstr(2, "From: ", tmp);
        myfree(tmp);
        tmp = substitute(to, listaddr, listdelim,
-                        tokencount, data, NULL);
+                        tokencount, data);
        headers[1] = concatstr(2, "To: ", tmp);
        myfree(tmp);
        headers[2] = genmsgid(listfqdn);
@@ -262,7 +241,7 @@ char *prepstdreply(const char *listdir, const char *filename, const char *from,
 
        if(replyto) {
                tmp = substitute(replyto, listaddr, listdelim,
-                                tokencount, data, NULL);
+                                tokencount, data);
                headers[8] = concatstr(2, "Reply-To: ", tmp);
                myfree(tmp);
        }
@@ -286,7 +265,7 @@ char *prepstdreply(const char *listdir, const char *filename, const char *from,
                           continuation of previous header line */
                        utfsub = unistr_escaped_to_utf8(line);
                        str = substitute(utfsub, listaddr, listdelim,
-                                        tokencount, data, NULL);
+                                        tokencount, data);
                        myfree(utfsub);
                        len = strlen(str);
                        str[len] = '\n';
@@ -329,7 +308,7 @@ char *prepstdreply(const char *listdir, const char *filename, const char *from,
                        utfsub = unistr_escaped_to_utf8(tmp);
                        *tmp = '\0';
                        utfsub2 = substitute(utfsub, listaddr, listdelim,
-                                            tokencount, data, NULL);
+                                            tokencount, data);
                        myfree(utfsub);
                        if (strncasecmp(line, "Subject:", len) == 0) {
                                tmp = unistr_utf8_to_header(utfsub2);
@@ -393,18 +372,65 @@ char *prepstdreply(const char *listdir, const char *filename, const char *from,
                utfline = unistr_escaped_to_utf8(str);
                myfree(str);
 
-               str = substitute(utfline, listaddr, listdelim, tokencount, data, mailname);
-               myfree(utfline);
-
-               if(writen(outfd, str, strlen(str)) < 0) {
+               tmp = utfline;
+               while (*tmp && (*tmp == ' ' || *tmp == '\t')) {
+                       tmp++;
+               }
+               if (strncmp(tmp,"$originalmail",13) == 0) {
+                       *tmp = '\0';
+                       tmp += 13;
+                       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,utfline,str);
+                                       myfree(tmp);
+                                       if(writen(outfd,str,strlen(str)) < 0) {
+                                           myfree(str);
+                                           myfree(utfline);
+                                           myfree(listaddr);
+                                           myfree(listdelim);
+                                           myfree(listfqdn);
+                                           log_error(LOG_ARGS, "Could not write std mail");
+                                           return NULL;
+                                       }
+                                       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 $originalmailNNN$ substitution");
+                       }
+                       myfree(utfline);
+               } else {
+                       str = substitute(utfline, listaddr, listdelim,
+                                        tokencount, data);
+                       myfree(utfline);
+                       if(writen(outfd, str, strlen(str)) < 0) {
+                               myfree(str);
+                               myfree(listaddr);
+                               myfree(listdelim);
+                               myfree(listfqdn);
+                               log_error(LOG_ARGS, "Could not write std mail");
+                               return NULL;
+                       }
                        myfree(str);
-                       myfree(listaddr);
-                       myfree(listdelim);
-                       myfree(listfqdn);
-                       log_error(LOG_ARGS, "Could not write std mail");
-                       return NULL;
                }
-               myfree(str);
+
                str = mygetline(infd);
        }
 
index 127b15f773ede741da1a8fd3f33e205fbfa0ad11..2da7b5e56c0ac33882821c1f83ee345843a090c9 100644 (file)
@@ -263,7 +263,7 @@ int send_digest(const char *listdir, int firstindex, int lastindex,
                utfsub = unistr_escaped_to_utf8(line + 9);
        }
 
-       utfsub2 = substitute(utfsub, listaddr, listdelim, 5, subst_data, NULL);
+       utfsub2 = substitute(utfsub, listaddr, listdelim, 5, subst_data);
        subject = unistr_utf8_to_header(utfsub2);
        myfree(utfsub);
        myfree(utfsub2);
@@ -362,7 +362,7 @@ errdighdrs:
                                myfree(line);
 
                                tmp = substitute(utfline, listaddr, listdelim,
-                                               5, subst_data, NULL);
+                                               5, subst_data);
                                myfree(utfline);
 
                                if(writen(fd, tmp, strlen(tmp)) < 0) {