]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
Substitute all of them and convert moderation to prepstdreply
authormmj <none@none>
Thu, 11 Nov 2004 23:27:07 +0000 (10:27 +1100)
committermmj <none@none>
Thu, 11 Nov 2004 23:27:07 +0000 (10:27 +1100)
include/prepstdreply.h
listtexts/moderation
src/mlmmj-process.c
src/prepstdreply.c

index fed5ce4cb227e6258b8dd0c8bcf012fd87609e71..9b59c79ba95afde0961a6a50c2d09ba0f7aa3c4e 100644 (file)
@@ -26,6 +26,8 @@
 
 char *substitute(const char *line, const char *listaddr, size_t datacount,
                 char **data);
+char *substitute_one(const char *line, const char *listaddr, size_t datacount,
+                char **data);
 char *prepstdreply(const char *listdir, const char *filename, const char *from,
                   const char *to, const char *replyto, size_t tokencount,
                   char **data);
index 274cd54be4e5fc02dcc187b1bfb097dbca64015d..e86ef3daaabfb3501195ed4afe546f50ff67afb3 100644 (file)
@@ -1,4 +1,4 @@
-Subject: Mail to $listaddr$ needs moderation
+Subject: Moderation needed for $listaddr$
 
 Hello,
 
index ce2664ac76b6dac0e6dc7c14fff1c6d5b26e59df..c8fd9c4d54796f482de3d7dd117833dd5a580750 100644 (file)
@@ -68,113 +68,70 @@ struct rule_list {
 void newmoderated(const char *listdir, const char *mailfilename,
                  const char *mlmmjsend)
 {
-       char *from, *fqdn, *listname;
-       char *buf, *moderatorfilename, *listaddr = getlistaddr(listdir);
-       char *queuefilename = NULL, *moderatorsfilename, *randomstr = NULL;
-       char *mailbasename = mybasename(mailfilename), *s1;
-       int moderatorfd, queuefd, moderatorsfd, mailfd;
+       char *from, *listfqdn, *listname, *moderators = NULL;
+       char *buf, *replyto, *listaddr = getlistaddr(listdir);
+       char *queuefilename = NULL, *moderatorsfilename;
+       char *mailbasename = mybasename(mailfilename), *tmp, *to;
+       int queuefd, moderatorsfd, mailfd;
        size_t count = 0;
+       char *maildata[4] = { "moderateaddr", NULL, "moderators", NULL };
 #if 0
        printf("mailfilename = [%s], mailbasename = [%s]\n", mailfilename,
                                                             mailbasename);
 #endif
-       fqdn = genlistfqdn(listaddr);
+       listfqdn = genlistfqdn(listaddr);
        listname = genlistname(listaddr);
-       moderatorfilename = concatstr(2, listdir, "/text/moderation");
-       if((moderatorfd = open(moderatorfilename, O_RDONLY)) < 0) {
-               log_error(LOG_ARGS, "Could not open text/moderation");
-               myfree(moderatorfilename);
+
+       if((mailfd = open(mailfilename, O_RDONLY)) < 0) {
+               log_error(LOG_ARGS, "Could not open '%s'", mailfilename);
                exit(EXIT_FAILURE);
        }
-       myfree(moderatorfilename);
 
        moderatorsfilename = concatstr(2, listdir, "/control/moderators");
        if((moderatorsfd = open(moderatorsfilename, O_RDONLY)) < 0) {
                log_error(LOG_ARGS, "Could not open '%s'", moderatorsfilename);
                myfree(moderatorsfilename);
-               close(moderatorfd);
                exit(EXIT_FAILURE);
        }
        myfree(moderatorsfilename);
 
-       if((mailfd = open(mailfilename, O_RDONLY)) < 0) {
-               log_error(LOG_ARGS, "Could not open '%s'", mailfilename);
-               close(moderatorfd);
-               close(moderatorsfd);
-               exit(EXIT_FAILURE);
+       while((buf = mygetline(moderatorsfd))) {
+               tmp = moderators;
+               moderators = concatstr(2, moderators, buf);
+               myfree(buf);
+               myfree(tmp);
        }
 
-        do {
-                randomstr = random_str();
-                myfree(queuefilename);
-                queuefilename = concatstr(3, listdir, "/queue/", randomstr);
-                myfree(randomstr);
+       close(moderatorsfd);
+
+       replyto = concatstr(5, listname, "+moderate-", mailbasename, "@",
+                           listfqdn);
+
+       maildata[1] = replyto;
+       maildata[3] = moderators;
+
+       from = concatstr(3, listname, "+owner@", listfqdn);
+       to = concatstr(3, listname, "-moderators@", listfqdn);
 
-                queuefd = open(queuefilename, O_RDWR|O_CREAT|O_EXCL,
-                                             S_IRUSR|S_IWUSR);
+       myfree(listname);
+       myfree(listfqdn);
 
-        } while ((queuefd < 0) && (errno == EEXIST));
+       queuefilename = prepstdreply(listdir, "moderation", "$listowner$",
+                                    to, replyto, 2, maildata);
 
-       if(queuefd < 0) {
+       if((queuefd = open(queuefilename, O_WRONLY|O_APPEND)) < 0) {
                log_error(LOG_ARGS, "Could not open '%s'", queuefilename);
                myfree(queuefilename);
-               close(moderatorfd);
-               close(moderatorsfd);
-               close(mailfd);
                exit(EXIT_FAILURE);
        }
-
-       from = concatstr(3, listname, "+owner@", fqdn);
-       s1 = concatstr(15, "From: ", from, "\nTo: ", listname, "-moderators@",
-                       fqdn, "\nReply-To: ", listname, "+moderate-",
-                       mailbasename, "@", fqdn,
-                       "\nSubject: Moderation needed for ", listaddr, "\n\n");
-       if(writen(queuefd, s1, strlen(s1)) < 0) {
-               log_error(LOG_ARGS, "Could not write to %s", queuefilename);
-               exit(EXIT_FAILURE);
-       }
-       myfree(s1);
-       s1 = concatstr(5, listname, "+moderate-", mailbasename, "@", fqdn);
        
-       while((buf = mygetline(moderatorfd))) {
-               if(strncmp(buf, "*LISTADDR*", 10) == 0) {
-                       if(writen(queuefd, listaddr, strlen(listaddr)) < 0) {
-                               log_error(LOG_ARGS, "Could not write to %s",
-                                               queuefilename);
-                               exit(EXIT_FAILURE);
-                       }
-               } else if(strncmp(buf, "*MODERATEADDR*", 14) == 0) {
-                       if(writen(queuefd, s1, strlen(s1)) < 0) {
-                               log_error(LOG_ARGS, "Could not write to %s",
-                                               queuefilename);
-                               exit(EXIT_FAILURE);
-                       }
-                       myfree(s1);
-               } else if(strncmp(buf, "*MODERATORS*", 12) == 0) {
-                       myfree(buf);
-                       while((buf = mygetline(moderatorsfd))) {
-                               if(writen(queuefd, buf, strlen(buf)) < 0)
-                                       log_error(LOG_ARGS,
-                                               "Could not write moderators");
-                                       
-                               myfree(buf);
-                               buf = NULL;
-                       }
-               } else
-                       if(writen(queuefd, buf, strlen(buf)) < 0) {
-                               log_error(LOG_ARGS,
-                                       "Could not write moderatemail");
-                               exit(EXIT_FAILURE);
-                       }
-               myfree(buf);
-       }
-       close(moderatorfd);
-       close(moderatorsfd);
-       while((buf = mygetline(mailfd)) && count < 100) {
-               s1 = concatstr(2, " ", buf);
+       while(count < 100 && (buf = mygetline(mailfd))) {
+               tmp = concatstr(2, " ", buf);
                myfree(buf);
-               writen(queuefd, s1, strlen(s1));
-               myfree(s1);
+               if(writen(queuefd, tmp, strlen(tmp)) < 0)
+                       log_error(LOG_ARGS, "Could not write line for "
+                                           "moderatemail");
+               myfree(tmp);
                count++;
        }
        close(queuefd);
index d178ca43158ae31d9d3fe61a557b81d5151fc927..ac1fd9e8b4ba8a2208c30e3579b8dd2890949ecc 100644 (file)
 
 char *substitute(const char *line, const char *listaddr, size_t datacount,
                 char **data)
+{
+       char *s1, *s2;
+
+       s1 = substitute_one(line, listaddr, datacount, data);
+       while(s1) {
+               s2 = substitute_one(s1, listaddr, datacount, data);
+               if(s2) {
+                       myfree(s1);
+                       s1 = s2;
+               } else
+                       return s1;
+       }
+               
+       return mystrdup(line);
+}
+
+char *substitute_one(const char *line, const char *listaddr, size_t datacount,
+                    char **data)
 {
        char *fqdn, *listname, *d1, *d2, *token, *value = NULL;
-       char *retstr, *origline = mystrdup(line);
+       char *retstr, *origline;
        size_t len, i;
-       
+
+       if(line == NULL)
+               return NULL;
+
+       origline = mystrdup(line);
+
        d1 = strchr(origline, '$');
 
-       if(d1 == NULL)
-               return origline;
-       else
+       if(d1 == NULL) {
+               myfree(origline);
+               return NULL;
+       } else
                d2 = strchr(d1 + 1, '$');
        
        if(d1 && d2) {
                len = d2 - d1;
                token = mymalloc(len + 1);
                snprintf(token, len, "%s", d1 + 1);
-       } else
-               return origline;
+       } else {
+               myfree(origline);
+               return NULL;
+       }
 
        *d1 = '\0';
 
@@ -100,9 +126,14 @@ char *substitute(const char *line, const char *listaddr, size_t datacount,
                for(i = 0; i < datacount; i++) {
                        if(strcmp(token, data[i*2]) == 0) {
                                value = mystrdup(data[(i*2)+1]);
+                               goto concatandreturn;
                        }
                }
        }
+
+       myfree(origline);
+       return NULL;
+
 concatandreturn:
        retstr = concatstr(3, origline, value, d2 + 1);
        myfree(origline);
@@ -145,9 +176,12 @@ char *prepstdreply(const char *listdir, const char *filename, const char *from,
        myfrom = substitute(from, listaddr, tokencount, data);
        myto = substitute(to, listaddr, tokencount, data);
 
-       if(replyto)
+       if(replyto) {
                myreplyto = substitute(replyto, listaddr, tokencount, data);
-       else
+               tmp = concatstr(3, "Reply-To: ", myreplyto, "\n");
+               free(myreplyto);
+               myreplyto = tmp;
+       } else
                myreplyto = NULL;
 
        do {
@@ -166,8 +200,8 @@ char *prepstdreply(const char *listdir, const char *filename, const char *from,
                return NULL;
        }
 
-       str = concatstr(8, "From: ", myfrom, "\nTo: ", myto, "\nReply-To: ",
-                       myreplyto, "\n", subject);
+       str = concatstr(7, "From: ", myfrom, "\nTo: ", myto, "\n", myreplyto,
+                       subject);
 
        if(writen(outfd, str, strlen(str)) < 0) {
                log_error(LOG_ARGS, "Could not write std mail");