changeset 106:c0df06494518

Dump needed data when failing in mlmmj-send. Add mlmmj-maintd, the mlmmj maintenance daemon
author mmj
date Mon, 24 May 2004 08:07:35 +1000
parents e13914ea89b5
children 6c21525eb588
files src/Makefile.am src/mlmmj-maintd.c src/mlmmj-send.c
diffstat 3 files changed, 154 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.am	Mon May 24 08:06:58 2004 +1000
+++ b/src/Makefile.am	Mon May 24 08:07:35 2004 +1000
@@ -6,7 +6,7 @@
 INCLUDES = -I../include
 
 bin_PROGRAMS = mlmmj-send mlmmj-recieve mlmmj-process mlmmj-sub \
-               mlmmj-unsub mlmmj-bounce
+               mlmmj-unsub mlmmj-bounce mlmmj-maintd
 
 bin_SCRIPTS = mlmmj-make-ml.sh
 
@@ -37,5 +37,7 @@
 			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 subscriberfuncs.c \
-			strgen.c random-int.c writen.c
+mlmmj_bounce_SOURCES = mlmmj-bounce.c print-version.c log_error.c \
+		       subscriberfuncs.c strgen.c random-int.c writen.c
+
+mlmmj_maintd_SOURCES = mlmmj-maintd.c print-version.c log_error.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/mlmmj-maintd.c	Mon May 24 08:07:35 2004 +1000
@@ -0,0 +1,144 @@
+/* Copyright (C) 2004 Mads Martin Joergensen <mmj at mmj.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 <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <dirent.h>
+
+#include "mlmmj-maintd.h"
+#include "mlmmj.h"
+#include "log_error.h"
+
+static void print_help(const char *prg)
+{
+	printf("Usage: %s -L /path/to/listdir [-F]\n"
+	       " -L: Full path to list directory\n"
+	       " -F: Don't fork, performing one maintenance run only.\n"
+	       "     This option should be used when one wants to\n"
+	       "     avoid running another daemon, and use e.g."
+	       "     cron to control it instead.\n", prg);
+	exit(EXIT_SUCCESS);
+}
+
+int clean_moderation(const char *listdir)
+{
+#if 0
+	DIR *moddir;
+	struct dirent *dp;
+#endif
+
+	/* TODO: Go through the moderation/ directory and delete mails
+	 * older than MODREQLIFE (control/modreqlife later on)
+	 */
+		
+	return 0;
+}
+
+int resend_queue(const char *listdir)
+{
+#if 0
+	DIR *queuedir;
+	struct dirent *dp;
+#endif
+
+	/* TODO: Go through all mails sitting in queue and send all that
+	 * has a .mailfrom, .reciptto suffix.
+	 */
+
+	return 0;
+}
+
+int probe_bouncers(const char *listdir)
+{
+#if 0
+	DIR *bouncedir;
+	struct dirent *dp;
+#endif
+
+	/* TODO: invoke mlmmj-bounce -p address for all that haven't been
+	 * probed in PROBEINTERVAL (control/probeinterval) seconds
+	 */
+	
+	return 0;
+}
+
+int unsub_bouncers(const char *listdir)
+{
+#if 0
+	DIR *bouncedir;
+	struct dirent *dp;
+#endif
+
+	/* TODO: Unsubscribe all that still bounces after BOUNCELIFE time
+	 * (control/bouncelife later on )
+	 */
+
+	return 0;
+}
+
+int main(int argc, char **argv)
+{
+	int opt, daemonize = 1;
+	char *listdir = NULL;
+	
+	log_set_name(argv[0]);
+
+	while ((opt = getopt(argc, argv, "hFVL:")) != -1) {
+		switch(opt) {
+		case 'F':
+			daemonize = 0;
+			break;
+		case 'L':
+			listdir = optarg;
+			break;
+		case 'h':
+			print_help(argv[0]);
+			break;
+		case 'V':
+			print_version(argv[0]);
+			exit(0);
+		}
+	}
+
+	if(listdir == NULL) {
+		fprintf(stderr, "You have to specify -L\n");
+		fprintf(stderr, "%s -h for help\n", argv[0]);
+		exit(EXIT_FAILURE);
+	}
+	
+	if(chdir(listdir) < 0) {
+		log_error(LOG_ARGS, "Could not chdir(%s), exiting. "
+				    "No maintenance performed.", listdir);
+		exit(EXIT_FAILURE);
+	}
+
+	if(daemonize) {
+		if(daemon(1,0) < 0) {
+			log_error(LOG_ARGS, "Could not daemonize. Only one "
+					    "maintenance run will be done.");
+			daemonize = 0;
+		}
+	}
+
+	for(;;) {
+		clean_moderation(listdir);
+		resend_queue(listdir);
+		probe_bouncers(listdir);
+		unsub_bouncers(listdir);
+		
+		if(daemonize == 0)
+			break;
+		else
+			sleep(MAINTD_SLEEP);
+	}
+		
+	exit(EXIT_SUCCESS);
+}
--- a/src/mlmmj-send.c	Mon May 24 08:06:58 2004 +1000
+++ b/src/mlmmj-send.c	Mon May 24 08:07:35 2004 +1000
@@ -197,6 +197,7 @@
 {
 	int sendres = 0;
 	char *bounceaddr, *addr, *index, *dirname, *addrfilename;
+	char *myarchivefilename = strdup(archivefilename);
 	FILE *addrfile;
 
 	while((addr = myfgetline(subfile))) {
@@ -213,7 +214,8 @@
 		}
 		if(sendres && listaddr && archivefilename) {
 			/* we failed, so save the addresses and bail */
-			index = basename(archivefilename);	
+			index = basename(myarchivefilename);	
+			free(myarchivefilename);
 			dirname = concatstr(3, listdir, "/requeue/", index);
 			free(index);
 			if(mkdir(dirname, 0750) < 0) {
@@ -417,14 +419,14 @@
 			free(tmpstr);
 			fputs(bounceaddr, tmpfile);
 			fclose(tmpfile);
-			tmpstr = concatstr(2, mailfilename, ".rcptto");
+			tmpstr = concatstr(2, mailfilename, ".reciptto");
 			tmpfile = fopen(tmpstr, "w");
 			free(tmpstr);
 			fputs(to_addr, tmpfile);
 			fclose(tmpfile);
 			if(replyto) {
 				tmpstr = concatstr(2, mailfilename,
-						      ".replyto");
+						      ".reply-to");
 				tmpfile = fopen(tmpstr, "w");
 				free(tmpstr);
 				fputs(replyto, tmpfile);