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 */
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
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
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;
}
} 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);
--- /dev/null
+/* 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;
+}
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 };
{ NULL, NULL }
};
+ log_set_name(argv[0]);
+
mlmmjsend = concatstr(2, dirname(argv0), "/mlmmj-send");
free(argv0);
argv0 = strdup(argv[0]);
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) {
}
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;
}