Mercurial > hg > mlmmj
changeset 365:24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
author | mmj |
---|---|
date | Fri, 12 Nov 2004 10:27:07 +1100 |
parents | fe02eed54635 |
children | 7d6c9bb6168f |
files | include/prepstdreply.h listtexts/moderation src/mlmmj-process.c src/prepstdreply.c |
diffstat | 4 files changed, 84 insertions(+), 91 deletions(-) [+] |
line wrap: on
line diff
--- a/include/prepstdreply.h Fri Nov 12 02:26:43 2004 +1100 +++ b/include/prepstdreply.h Fri Nov 12 10:27:07 2004 +1100 @@ -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);
--- a/listtexts/moderation Fri Nov 12 02:26:43 2004 +1100 +++ b/listtexts/moderation Fri Nov 12 10:27:07 2004 +1100 @@ -1,4 +1,4 @@ -Subject: Mail to $listaddr$ needs moderation +Subject: Moderation needed for $listaddr$ Hello,
--- a/src/mlmmj-process.c Fri Nov 12 02:26:43 2004 +1100 +++ b/src/mlmmj-process.c Fri Nov 12 10:27:07 2004 +1100 @@ -68,113 +68,70 @@ 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; - queuefd = open(queuefilename, O_RDWR|O_CREAT|O_EXCL, - S_IRUSR|S_IWUSR); + from = concatstr(3, listname, "+owner@", listfqdn); + to = concatstr(3, listname, "-moderators@", listfqdn); - } while ((queuefd < 0) && (errno == EEXIST)); + myfree(listname); + myfree(listfqdn); - if(queuefd < 0) { + queuefilename = prepstdreply(listdir, "moderation", "$listowner$", + to, replyto, 2, maildata); + + 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) { + while(count < 100 && (buf = mygetline(mailfd))) { + tmp = concatstr(2, " ", buf); 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); - 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);
--- a/src/prepstdreply.c Fri Nov 12 02:26:43 2004 +1100 +++ b/src/prepstdreply.c Fri Nov 12 10:27:07 2004 +1100 @@ -42,23 +42,49 @@ 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 @@ 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 @@ 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 @@ 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");