From: mmj Date: Mon, 7 Jun 2004 12:36:39 +0000 (+1000) Subject: New function to prepare a standard mail in an easy way, and make send_help X-Git-Tag: RELEASE_1_0_0~140 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ed40207b2cab35d39600ef217bcc9b31115bcfe;p=thirdparty%2Fmlmmj.git New function to prepare a standard mail in an easy way, and make send_help use it. More to follow :) --- diff --git a/src/Makefile.am b/src/Makefile.am index b568aa81..a153205d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,21 +23,23 @@ mlmmj_recieve_SOURCES = mlmmj-recieve.c writen.c random-int.c strgen.c \ mlmmj_process_SOURCES = mlmmj-process.c writen.c find_email_adr.c \ incindexfile.c itoa.c getlistaddr.c chomp.c \ mylocking.c listcontrol.c random-int.c strgen.c \ - print-version.c send_help.c \ + print-version.c send_help.c prepstdreply.c \ do_all_the_voodo_here.c mygetline.c gethdrline.c \ log_error.c statctrl.c ctrlvalue.c dumpfd2fd.c mlmmj_sub_SOURCES = mlmmj-sub.c writen.c mylocking.c \ getlistaddr.c chomp.c random-int.c strgen.c \ subscriberfuncs.c print-version.c \ - log_error.c mygetline.c + log_error.c mygetline.c prepstdreply.c mlmmj_unsub_SOURCES = mlmmj-unsub.c writen.c mylocking.c \ getlistaddr.c chomp.c subscriberfuncs.c random-int.c \ - strgen.c print-version.c log_error.c mygetline.c - + strgen.c print-version.c log_error.c mygetline.c \ + prepstdreply.c + mlmmj_bounce_SOURCES = mlmmj-bounce.c print-version.c log_error.c \ - subscriberfuncs.c strgen.c random-int.c writen.c + subscriberfuncs.c strgen.c random-int.c writen.c \ + prepstdreply.c mygetline.c mlmmj_maintd_SOURCES = mlmmj-maintd.c print-version.c log_error.c mygetline.c \ strgen.c random-int.c chomp.c diff --git a/src/prepstdreply.c b/src/prepstdreply.c new file mode 100644 index 00000000..bf1e9584 --- /dev/null +++ b/src/prepstdreply.c @@ -0,0 +1,73 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "prepstdreply.h" +#include "strgen.h" +#include "chomp.h" +#include "log_error.h" +#include "mygetline.h" +#include "wrappers.h" + +char *prepstdreply(const char *listdir, const char *filename, const char *from, + const char *to, const char *replyto, const char *subject, + size_t tokencount, char **data) +{ + int infd, outfd; + size_t i; + char *str, *tmp, *retstr; + + tmp = concatstr(3, listdir, "/text/", filename); + infd = open(tmp, O_RDONLY); + free(tmp); + if(infd < 0) { + log_error(LOG_ARGS, "Could not open std mail %s", filename); + return NULL; + } + + tmp = concatstr(6, "From: ", from, "\nTo: ", to, "\nSubject: ", subject); + if(replyto) + str = concatstr(3, tmp, "\nReply-To: ", replyto, "\n\n"); + else + str = concatstr(2, tmp, "\n\n"); + + free(tmp); + + tmp = random_str(); + retstr = concatstr(3, listdir, "/queue/", random); + free(tmp); + outfd = open(retstr, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); + if(outfd < 0) { + log_error(LOG_ARGS, "Could not open std mail %s", tmp); + return NULL; + } + + if(writen(outfd, str, strlen(str)) < 0) { + log_error(LOG_ARGS, "Could not write std mail"); + return NULL; + } + free(str); + + while((str = mygetline(infd))) { + for(i = 0; i < tokencount; i++) { + if(strncmp(str, data[i*2], strlen(data[i*2])) == 0) { + free(str); + str = strdup(data[(i*2)+1]); + } + } + if(writen(outfd, str, strlen(str)) < 0) { + log_error(LOG_ARGS, "Could not write std mail"); + return NULL; + } + free(str); + } + + fsync(outfd); + close(outfd); + + return retstr; +} diff --git a/src/send_help.c b/src/send_help.c index f3dd8474..78383180 100644 --- a/src/send_help.c +++ b/src/send_help.c @@ -23,99 +23,52 @@ #include "chomp.h" #include "wrappers.h" #include "mygetline.h" +#include "prepstdreply.h" void send_help(const char *listdir, const char *emailaddr, const char *mlmmjsend) { - int helpfd, queuefd; - char *listaddr, *buf, *fromaddr; - char *helpfilename, *queuefilename, *listname; - char *randomstr, *listfqdn, *s1; + char *queuefilename, *listaddr, *listname, *listfqdn, *fromaddr; + char *fromstr, *subject; + char *maildata[] = { "*UNSUBADDR*", NULL, "*SUBADDR*", NULL, + "*HLPADDR*", NULL }; listaddr = getlistaddr(listdir); chomp(listaddr); - helpfilename = concatstr(2, listdir, "/text/listhelp"); - - if((helpfd = open(helpfilename, O_RDONLY)) < 0) { - log_error(LOG_ARGS, "Could not open text/help"); - free(helpfilename); - exit(EXIT_FAILURE); - } - - free(helpfilename); - listname = genlistname(listaddr); listfqdn = genlistfqdn(listaddr); - randomstr = random_str(); - - queuefilename = concatstr(3, listdir, "/queue/", randomstr); - - queuefd = open(queuefilename, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); - if(queuefd < 0) { - log_error(LOG_ARGS, "Could not open '%s'", queuefilename); - free(queuefilename); - free(randomstr); - exit(EXIT_FAILURE); - } - free(randomstr); fromaddr = concatstr(3, listname, "+bounces-help@", listfqdn); - s1 = concatstr(9, "From: ", listname, "+owner@", listfqdn, - "\nTo: ", emailaddr, "\nSubject: Help for ", - listaddr, "\n\n"); + maildata[1] = concatstr(3, listname, "+unsubscribe@", listfqdn); + maildata[3] = concatstr(3, listname, "+subscribe@", listfqdn); + maildata[5] = concatstr(3, listname, "+help@", listfqdn); + fromstr = concatstr(3, listname, "+owner@", listfqdn); + subject = concatstr(2, "Help for ", listaddr); - if(writen(queuefd, s1, strlen(s1)) < 0) { - log_error(LOG_ARGS, "Could not write help mail"); + queuefilename = prepstdreply(listdir, "listhelp", fromstr, emailaddr, + NULL, subject, 3, maildata); + if(queuefilename == NULL) { + log_error(LOG_ARGS, "Could not prepare help mail"); exit(EXIT_FAILURE); } - - free(s1); - - while((buf = mygetline(helpfd)) != NULL) { - if(strncmp(buf, "*UNSUBADDR*", 11) == 0) { - s1 = concatstr(3, listname, "+unsubscribe@", listfqdn); - if(writen(queuefd, s1, strlen(s1)) < 0) { - log_error(LOG_ARGS, - "Could not write help mail"); - exit(EXIT_FAILURE); - } - free(s1); - } else if(strncmp(buf, "*SUBADDR*", 9) == 0) { - s1 = concatstr(3, listname, "+subscribe@", listfqdn); - if(writen(queuefd, s1, strlen(s1)) < 0) { - log_error(LOG_ARGS, - "Could not write help mail"); - exit(EXIT_FAILURE); - } - free(s1); - } else if(strncmp(buf, "*HLPADDR*", 9) == 0) { - s1 = concatstr(3, listname, "+help@", listfqdn); - if(writen(queuefd, s1, strlen(s1)) < 0) { - log_error(LOG_ARGS, - "Could not write help mail"); - exit(EXIT_FAILURE); - } - free(s1); - } else if(writen(queuefd, buf, strlen(buf)) < 0) { - log_error(LOG_ARGS, - "Could not write help mail"); - exit(EXIT_FAILURE); - } - free(buf); - } + free(fromstr); + free(listaddr); free(listname); free(listfqdn); - close(helpfd); - close(queuefd); + free(maildata[1]); + free(maildata[3]); + free(maildata[5]); + free(subject); execlp(mlmmjsend, mlmmjsend, "-l", "1", "-T", emailaddr, "-F", fromaddr, "-m", queuefilename, 0); + log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend); exit(EXIT_FAILURE); }