# HG changeset patch # User mortenp # Date 1083060580 -36000 # Node ID c4af2c82c631f9e2877c49627906edb1493115f0 # Parent 4a80ff54043166e97ca78f498bd24cbeaa9a167c added primitive bounce handling diff -r 4a80ff540431 -r c4af2c82c631 include/listcontrol.h --- a/include/listcontrol.h Sun Apr 25 21:33:07 2004 +1000 +++ b/include/listcontrol.h Tue Apr 27 20:09:40 2004 +1000 @@ -11,6 +11,7 @@ int listcontrol(const char *mailfilename, const char *listdir, const char *controladdr, const char *mlmmjsub, - const char *mlmmjunsub, const char *mlmmjsend); + const char *mlmmjunsub, const char *mlmmjsend, + const char *mlmmjbounce); #endif /* LISTCONTROL_H */ diff -r 4a80ff540431 -r c4af2c82c631 src/Makefile.am --- a/src/Makefile.am Sun Apr 25 21:33:07 2004 +1000 +++ b/src/Makefile.am Tue Apr 27 20:09:40 2004 +1000 @@ -6,7 +6,7 @@ INCLUDES = -I../include bin_PROGRAMS = mlmmj-send mlmmj-recieve mlmmj-process mlmmj-sub \ - mlmmj-unsub + mlmmj-unsub mlmmj-bounce bin_SCRIPTS = mlmmj-make-ml.sh @@ -36,3 +36,6 @@ 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 + +mlmmj_bounce_SOURCES = mlmmj-bounce.c print-version.c log_error.c \ + strgen.c random-int.c writen.c diff -r 4a80ff540431 -r c4af2c82c631 src/listcontrol.c --- a/src/listcontrol.c Sun Apr 25 21:33:07 2004 +1000 +++ b/src/listcontrol.c Tue Apr 27 20:09:40 2004 +1000 @@ -22,10 +22,11 @@ int listcontrol(const char *mailfilename, const char *listdir, const char *controladdr, const char *mlmmjsub, - const char *mlmmjunsub, const char *mlmmjsend) + const char *mlmmjunsub, const char *mlmmjsend, + const char *mlmmjbounce) { char tmpstr[READ_BUFSIZE]; - char *atsign, *recipdelimsign, *tokenvalue, *confstr; + char *atsign, *recipdelimsign, *tokenvalue, *confstr, *bouncenr; char *controlstr, *conffilename; FILE *mailfile, *tempfile; struct email_container fromemails; @@ -119,6 +120,17 @@ } } else /* Not a confirm so silently ignore */ exit(EXIT_SUCCESS); + } else if(strncasecmp(controlstr, "bounce-", 7) == 0) { + controlstr += 7; + bouncenr = strrchr(controlstr, '-'); + if (!bouncenr) exit(EXIT_SUCCESS); /* malformed bounce, ignore */ + *bouncenr++ = '\0'; + log_error(LOG_ARGS, "bounce, bounce, bounce email=[%s] nr=[%s]", controlstr, bouncenr); + execlp(mlmmjbounce, mlmmjbounce, + "-L", listdir, + "-a", controlstr, + "-n", bouncenr, 0); + log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjbounce); } else if(strncasecmp(controlstr, "help", 4) == 0) { printf("Help wanted!\n"); free(controlstr); diff -r 4a80ff540431 -r c4af2c82c631 src/mlmmj-bounce.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mlmmj-bounce.c Tue Apr 27 20:09:40 2004 +1000 @@ -0,0 +1,105 @@ +/* Copyright (C) 2004 Morten K. Poulsen + * + * $Id$ + * + * This file is redistributable under version 2 of the GNU General + * Public License as described at http://www.gnu.org/licenses/gpl.txt + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mlmmj.h" +#include "strgen.h" +#include "wrappers.h" +#include "log_error.h" + +static void print_help(const char *prg) +{ + printf("Usage: %s [-P] -L /path/to/chat-list\n" + " -a address\n" + " -n message-number\n", prg); + exit(EXIT_SUCCESS); +} + +int main(int argc, char **argv) +{ + int opt, noprocess = 0; + char *listdir = NULL, *address = NULL, *number = NULL; + char *filename, *a, *buf; + size_t len; + int fd; + time_t t; + + log_set_name(argv[0]); + + while ((opt = getopt(argc, argv, "hVPL:a:n:")) != -1) { + switch(opt) { + case 'L': + listdir = optarg; + break; + case 'a': + address = optarg; + break; + case 'n': + number = optarg; + break; + case 'h': + print_help(argv[0]); + break; + case 'P': + noprocess = 1; + break; + case 'V': + print_version(argv[0]); + exit(0); + } + } + if(listdir == NULL || address == NULL || number == NULL) { + fprintf(stderr, "You have to specify -L, -a and -n\n"); + fprintf(stderr, "%s -h for help\n", argv[0]); + exit(EXIT_FAILURE); + } + + log_error(LOG_ARGS, "[%s] [%s] [%s]", listdir, address, number); + + filename = concatstr(3, listdir, "/bounce/", address); + if ((fd = open(filename, O_WRONLY|O_APPEND|O_CREAT, + S_IRUSR|S_IWUSR)) < 0) { + log_error(LOG_ARGS, "Could not open '%s'", filename); + exit(EXIT_FAILURE); + } + + a = strchr(address, '='); + /* ignore malformed address */ + if (!a) exit(EXIT_FAILURE); + *a = '@'; + + /* TODO check that the address is subscribed */ + /* TODO check that the message is not already bounced */ + + /* XXX How long can the string representation of an integer be? + * It is not a security issue (we use snprintf()), but it would be + * bad mojo to cut the timestamp field -- mortenp 20040427 */ + + /* int + ":" + int + " # Wed Jun 30 21:49:08 1993\n" + NUL */ + len = 20 + 1 + 20 + 28 + 1; + + buf = malloc(len); + if (!buf) exit(EXIT_FAILURE); + + t = time(NULL); + snprintf(buf, len-26, "%s:%d # ", number, (int)t); + ctime_r(&t, buf+strlen(buf)); + writen(fd, buf, strlen(buf)); + close(fd); + + return EXIT_FAILURE; +} diff -r 4a80ff540431 -r c4af2c82c631 src/mlmmj-process.c --- a/src/mlmmj-process.c Sun Apr 25 21:33:07 2004 +1000 +++ b/src/mlmmj-process.c Tue Apr 27 20:09:40 2004 +1000 @@ -39,7 +39,7 @@ char *listdir = NULL, *mailfile = NULL, *headerfilename = NULL; char *footerfilename = NULL, *donemailname = NULL; char *randomstr = random_str(); - char *mlmmjsend, *mlmmjsub, *mlmmjunsub; + char *mlmmjsend, *mlmmjsub, *mlmmjunsub, *mlmmjbounce; char *argv0 = strdup(argv[0]); FILE *headerfile, *footerfile, *rawmailfile, *donemailfile; struct email_container toemails = { 0, NULL }; @@ -50,6 +50,8 @@ { NULL, NULL } }; + log_set_name(argv[0]); + mlmmjsend = concatstr(2, dirname(argv0), "/mlmmj-send"); free(argv0); argv0 = strdup(argv[0]); @@ -58,6 +60,9 @@ argv0 = strdup(argv[0]); mlmmjunsub = concatstr(2, dirname(argv0), "/mlmmj-unsub"); free(argv0); + argv0 = strdup(argv[0]); + mlmmjbounce = concatstr(2, dirname(argv0), "/mlmmj-bounce"); + free(argv0); while ((opt = getopt(argc, argv, "hVPm:L:")) != -1) { switch(opt) { @@ -152,11 +157,11 @@ } if(strchr(toemails.emaillist[0], RECIPDELIM)) { - printf("listcontrol(%s, %s, %s, %s, %s, %s)\n", donemailname, + printf("listcontrol(%s, %s, %s, %s, %s, %s, %s)\n", donemailname, listdir, toemails.emaillist[0], mlmmjsub, - mlmmjunsub, mlmmjsend); + mlmmjunsub, mlmmjsend, mlmmjbounce); listcontrol(donemailname, listdir, toemails.emaillist[0], - mlmmjsub, mlmmjunsub, mlmmjsend); + mlmmjsub, mlmmjunsub, mlmmjsend, mlmmjbounce); return EXIT_SUCCESS; }