]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
added primitive bounce handling
authormortenp <none@none>
Tue, 27 Apr 2004 10:09:40 +0000 (20:09 +1000)
committermortenp <none@none>
Tue, 27 Apr 2004 10:09:40 +0000 (20:09 +1000)
include/listcontrol.h
src/Makefile.am
src/listcontrol.c
src/mlmmj-bounce.c [new file with mode: 0644]
src/mlmmj-process.c

index b7461414f44729ca88513b02d0d54689207be613..3bc6f59251cd9553fea06f859336d0e052ab6ccc 100644 (file)
@@ -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 */
index af9c3a0d408a119427a84fe3bb03085ffe96dfab..4bdf6159484f87b3f576cf1ebf5c10396203daa9 100644 (file)
@@ -6,7 +6,7 @@ CFLAGS = -g -Wall -pedantic -Wsign-compare
 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_sub_SOURCES = mlmmj-sub.c writen.c mylocking.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
+
+mlmmj_bounce_SOURCES = mlmmj-bounce.c print-version.c log_error.c \
+                       strgen.c random-int.c writen.c
index 611d7088302995088be49a8eb7c0967fe3d01b65..532275f7b1a9692b2570049b5714c04e81bb86ff 100644 (file)
 
 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 @@ int listcontrol(const char *mailfilename, const char *listdir,
                        }
                } 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 --git a/src/mlmmj-bounce.c b/src/mlmmj-bounce.c
new file mode 100644 (file)
index 0000000..b98f8f0
--- /dev/null
@@ -0,0 +1,105 @@
+/* Copyright (C) 2004 Morten K. Poulsen <morten at afdelingp.dk>
+ *
+ * $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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <time.h>
+
+#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;
+}
index 6630dcfb6290e33db5d017444aaec89b38837cd6..7036451907158d2ddea881d0ec49ecf526d30da5 100644 (file)
@@ -39,7 +39,7 @@ int main(int argc, char **argv)
        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 @@ int main(int argc, char **argv)
                { NULL, NULL }
        };
 
+       log_set_name(argv[0]);
+
        mlmmjsend = concatstr(2, dirname(argv0), "/mlmmj-send");
        free(argv0);
        argv0 = strdup(argv[0]);
@@ -58,6 +60,9 @@ int main(int argc, char **argv)
        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 @@ int main(int argc, char **argv)
        }
 
        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;
        }