From: mmj Date: Tue, 8 Jun 2004 10:15:27 +0000 (+1000) Subject: Bounce probes done. Review appreciated. X-Git-Tag: RELEASE_1_0_0~136 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2aa1db7fa88613a1d976d6f63d5213efa7831aab;p=thirdparty%2Fmlmmj.git Bounce probes done. Review appreciated. --- diff --git a/src/Makefile.am b/src/Makefile.am index 7f3238b2..2b31a710 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -39,7 +39,8 @@ mlmmj_unsub_SOURCES = mlmmj-unsub.c writen.c mylocking.c \ mlmmj_bounce_SOURCES = mlmmj-bounce.c print-version.c log_error.c \ subscriberfuncs.c strgen.c random-int.c writen.c \ - prepstdreply.c mygetline.c openrandexclrw.c + prepstdreply.c mygetline.c openrandexclrw.c chomp.c \ + getlistaddr.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/mlmmj-bounce.c b/src/mlmmj-bounce.c index 764d93fc..8a42a252 100644 --- a/src/mlmmj-bounce.c +++ b/src/mlmmj-bounce.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "getlistaddr.h" #include "mlmmj.h" @@ -24,12 +25,14 @@ #include "log_error.h" #include "subscriberfuncs.h" #include "mygetline.h" - +#include "chomp.h" +#include "prepstdreply.h" char *fetchindexes(const char *bouncefile) { int fd; - char *indexstr, *tmp, *start, *cur, *next; + char *indexstr = NULL, *s, *start, *line, *cur, *colon, *next; + size_t len; struct stat st; fd = open(bouncefile, O_RDONLY); @@ -42,7 +45,7 @@ char *fetchindexes(const char *bouncefile) if(fstat(fd, &st) < 0) { log_error(LOG_ARGS, "Could not open bounceindexfile %s", bouncefile); - + } start = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); if(start == MAP_FAILED) { @@ -50,24 +53,38 @@ char *fetchindexes(const char *bouncefile) return NULL; } - for(next = cur = start; next < start + st.st_size; next++) { - - - - - + for(next = cur = start; next < start + st.st_size; next++) { + if(*next == '\n') { + len = next - cur; + line = malloc(len + 1); + strncpy(line, cur, len); + line[len] = '\0'; + cur = next + 1; + } else + continue; + + colon = strchr(line, ':'); + *colon = '\0'; + s = indexstr; + indexstr = concatstr(4, s, " ", line, "\n"); + free(s); + free(line); + } + + munmap(start, st.st_size); + close(fd); + return indexstr; } -/* XXX this is not finished */ void do_probe(const char *listdir, const char *mlmmjsend, const char *addr) { - char *myaddr, *from, *randomstr, *a, *line, *textfilename; - char *queuefilename, *listaddr, *listfqdn, *listname; - char *fromstr, *tostr, *subjectstr, *tmp; - int textfd, queuefd; - ssize_t n; + char *myaddr, *from, *a, *fromstr, *subjectstr, *indexstr; + char *queuefilename, *listaddr, *listfqdn, *listname, *probefile; + char *maildata[] = { "*LSTADDR*", NULL, "*BOUNCENUMBERS*", NULL }; + int fd; + time_t t; myaddr = strdup(addr); MY_ASSERT(myaddr); @@ -78,7 +95,7 @@ void do_probe(const char *listdir, const char *mlmmjsend, const char *addr) listname = genlistname(listaddr); listfqdn = genlistfqdn(listaddr); - from = concatstr(3, listname, "+bounces-", myaddr, "-probe@", listfqdn); + from = concatstr(5, listname, "+bounces-", myaddr, "-probe@", listfqdn); a = strchr(myaddr, '='); if (!a) { @@ -89,35 +106,45 @@ void do_probe(const char *listdir, const char *mlmmjsend, const char *addr) } *a = '@'; - tmp = concatstr(2, listdir, "/queue/"); - queuefd = openrandexclrw(tmp, "-probe", S_IRUSR|S_IWUSR); - free(tmp); - - if(queuefd < 0) { - log_error(LOG_ARGS, "Could not create a queue file (%s)"); - free(myaddr); - exit(EXIT_FAILURE); - } - - /* XXX */ fromstr = concatstr(3, listname, "+owner@", listfqdn); - /* XXX Put subject in the text file? */ - subjectstr = concatstr(2, "Mails to you from ", listaddr, + subjectstr = concatstr(3, "Mails to you from ", listaddr, " have been bouncing"); - - while((line = mygetline(textfd))) { - if (strncmp(line, "*LISTADDR*", 10) == 0) { - free(line); - /*line = concatstr( XXX */ - } else { - n = writen(queuefd, line, strlen(line)); - MY_ASSERT(n >= 0); - free(line); - } + indexstr = fetchindexes(addr); + if(indexstr == NULL) { + log_error(LOG_ARGS, "Could not fetch bounceindexes"); + exit(EXIT_FAILURE); } + maildata[1] = listaddr; + maildata[3] = indexstr; + queuefilename = prepstdreply(listdir, "bounce-probe", fromstr, + myaddr, NULL, subjectstr, 2, maildata); + MY_ASSERT(queuefilename); + free(fromstr); + free(subjectstr); + free(listaddr); + free(listfqdn); + free(listname); + + probefile = concatstr(4, listdir, "/bounce/", addr, "-probe"); + MY_ASSERT(probefile); + t = time(NULL); + a = malloc(32); + snprintf(a, 31, "%ld", (long int)t); + a[31] = '\0'; + unlink(probefile); + fd = open(probefile, O_WRONLY|O_TRUNC|O_CREAT|O_NOFOLLOW, + S_IRUSR|S_IWUSR); + if(fd < 0) + log_error(LOG_ARGS, "Could not open %s", probefile); + else + if(writen(fd, a, strlen(a)) < 0) + log_error(LOG_ARGS, "Could not write time in probe"); + + free(probefile); + execlp(mlmmjsend, mlmmjsend, "-l", "1", "-T", myaddr, @@ -129,12 +156,9 @@ void do_probe(const char *listdir, const char *mlmmjsend, const char *addr) exit(EXIT_FAILURE); } - static void print_help(const char *prg) { - /* XXX how do we represent the fact that you have to specify either -n - * or -p ? MMJ, please change to your preferred way. */ - printf("Usage: %s -L /path/to/list -a john=doe.org (-n 12 | -p)\n" + printf("Usage: %s -L /path/to/list -a john=doe.org [-n num | -p]\n" " -a: Address string that bounces\n" " -h: This help\n" " -L: Full path to list directory\n" @@ -272,7 +296,7 @@ int main(int argc, char **argv) if (!buf) exit(EXIT_FAILURE); t = time(NULL); - snprintf(buf, len-26, "%s:%d # ", number, (int)t); + snprintf(buf, len-26, "%s:%ld # ", number, (long int)t); ctime_r(&t, buf+strlen(buf)); writen(fd, buf, strlen(buf)); close(fd);