changeset 509:c89f55896ba5

Make resend_queue more robust
author mmj
date Mon, 20 Jun 2005 22:40:39 +1000
parents 10852fdfb3aa
children d093a6e1ed3f
files ChangeLog VERSION src/mlmmj-maintd.c src/mlmmj-send.c src/mlmmj-sub.c src/mlmmj-unsub.c
diffstat 6 files changed, 62 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Jun 17 22:55:09 2005 +1000
+++ b/ChangeLog	Mon Jun 20 22:40:39 2005 +1000
@@ -1,3 +1,9 @@
+1.2.8
+ o Make sure the resend of queue files will not loop indefinately
+ o Make Date: header RFC2822 compliant (Jakob Hirsch)
+ o Add -s switch to mlmmj-{,un}sub to control whether or not to send a mail
+   telling about already subscribed, or not subscribed when trying to
+   subscribe or unsubscribe (Christian Laursen)
 1.2.7
  o Remove old superflous cruft in the smtpreply reader function, making
    mlmmj-send not segfault in rare cases when SIGTERM was sent
--- a/VERSION	Fri Jun 17 22:55:09 2005 +1000
+++ b/VERSION	Mon Jun 20 22:40:39 2005 +1000
@@ -1,1 +1,1 @@
-1.2.7
+1.2.8-rc1
--- a/src/mlmmj-maintd.c	Fri Jun 17 22:55:09 2005 +1000
+++ b/src/mlmmj-maintd.c	Mon Jun 20 22:40:39 2005 +1000
@@ -212,7 +212,7 @@
 	char *bouncelifestr;
 	pid_t childpid, pid;
 	struct stat st;
-	int fromfd, tofd, fd, discarded = 0, status;
+	int fromfd, tofd, fd, status, err = 0;
 	time_t t, bouncelife = 0;
 
 	if(chdir(dirname) < 0) {
@@ -229,8 +229,10 @@
 	myfree(dirname);
 
 	while((dp = readdir(queuedir)) != NULL) {
-		if(stat(dp->d_name, &st) < 0) {
-			log_error(LOG_ARGS, "Could not stat(%s)",dp->d_name);
+		mailname = concatstr(3, listdir, "/queue/", dp->d_name);
+
+		if(stat(mailname, &st) < 0) {
+			log_error(LOG_ARGS, "Could not stat(%s)", mailname);
 			continue;
 		}
 
@@ -238,49 +240,51 @@
 			continue;
 
 		if(strchr(dp->d_name, '.')) {
-			mailname = mystrdup(dp->d_name);
-			ch = strchr(mailname, '.');
+			ch = strrchr(mailname, '.');
 			*ch = '\0';
-			if(stat(mailname, &st) < 0)
-				if(errno == ENOENT)
-					unlink(dp->d_name);
+			if(stat(mailname, &st) < 0) {
+				if(errno == ENOENT) {
+					*ch = '.';
+					unlink(mailname);
+				}
+			}
 			myfree(mailname);
 			continue;
 		}
 
-		mailname = concatstr(3, listdir, "/queue/", dp->d_name);
-
 		fromname = concatstr(2, mailname, ".mailfrom");
 		toname = concatstr(2, mailname, ".reciptto");
 		reptoname = concatstr(2, mailname, ".reply-to");
 
 		fromfd = open(fromname, O_RDONLY);
+		if(fromfd < 0)
+			err = errno;
 		tofd = open(toname, O_RDONLY);
 
-		if(fromfd < 0 || tofd < 0) {
-			if(discarded) {
+		if((fromfd < 0 && err == ENOENT) ||
+		   (tofd < 0 && errno == ENOENT)) {
+			unlink(mailname);
 				unlink(fromname);
 				unlink(toname);
 				unlink(reptoname);
-			}
 			myfree(mailname);
 			myfree(fromname);
 			myfree(toname);
 			myfree(reptoname);
 			if(fromfd >= 0)
 				close(fromfd);
+			if(tofd >= 0)
+				close(tofd);
 			continue;
 		}
 
 		from = mygetline(fromfd);
 		chomp(from);
 		close(fromfd);
-		unlink(fromname);
 		myfree(fromname);
 		to = mygetline(tofd);
 		chomp(to);
 		close(tofd);
-		unlink(toname);
 		myfree(toname);
 		fd = open(reptoname, O_RDONLY);
 		if(fd < 0) {
@@ -290,7 +294,6 @@
 			repto = mygetline(fd);
 			chomp(repto);
 			close(fd);
-			unlink(reptoname);
 			myfree(reptoname);
 		}
 
--- a/src/mlmmj-send.c	Fri Jun 17 22:55:09 2005 +1000
+++ b/src/mlmmj-send.c	Mon Jun 20 22:40:39 2005 +1000
@@ -927,8 +927,13 @@
 		if(sendres) {
 			/* error, so keep it in the queue */
 			deletewhensent = 0;
-			/* dump date we want when resending */
+			/* dump data we want when resending first check
+			 * if it already exists. In that case continue */
 			tmpstr = concatstr(2, mailfilename, ".mailfrom");
+			if(stat(tmpstr, &st) == 0) {
+				myfree(tmpstr);
+				break;
+			}
 			tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC,
 						S_IRUSR|S_IWUSR);
 			myfree(tmpstr);
@@ -938,6 +943,10 @@
 			}
 			close(tmpfd);
 			tmpstr = concatstr(2, mailfilename, ".reciptto");
+			if(stat(tmpstr, &st) == 0) {
+				myfree(tmpstr);
+				break;
+			}
 			tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC,
 						S_IRUSR|S_IWUSR);
 			myfree(tmpstr);
@@ -949,6 +958,10 @@
 			if(replyto) {
 				tmpstr = concatstr(2, mailfilename,
 						      ".reply-to");
+				if(stat(tmpstr, &st) == 0) {
+					myfree(tmpstr);
+					break;
+				}
 				tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC,
 							S_IRUSR|S_IWUSR);
 				myfree(tmpstr);
--- a/src/mlmmj-sub.c	Fri Jun 17 22:55:09 2005 +1000
+++ b/src/mlmmj-sub.c	Mon Jun 20 22:40:39 2005 +1000
@@ -225,7 +225,7 @@
 static void print_help(const char *prg)
 {
 	printf("Usage: %s -L /path/to/list -a john@doe.org "
-	       "[-c] [-C] [-h]\n       [-L] [-d | -n] [-U] [-V]\n"
+	       "[-c] [-C] [-h]\n       [-L] [-d | -n] [-s] [-U] [-V]\n"
 	       " -a: Email address to subscribe \n"
 	       " -c: Send welcome mail\n"
 	       " -C: Request mail confirmation\n"
@@ -233,6 +233,7 @@
 	       " -h: This help\n"
 	       " -L: Full path to list directory\n"
 	       " -n: Subscribe to no mail version of list\n"
+	       " -s: Don't send a mail to the subscriber if already subscribed\n"
 	       " -U: Don't switch to the user id of the listdir owner\n"
 	       " -V: Print version\n"
 	       "When no options are specified, subscription silently "
@@ -276,7 +277,7 @@
 	char *sublockname;
 	int subconfirm = 0, confirmsub = 0, opt, subfilefd, lock, notifysub;
 	int changeuid = 1, status, digest = 0, nomail = 0;
-	int groupwritable = 0, sublock, sublockfd;
+	int groupwritable = 0, sublock, sublockfd, nogensubscribed = 0;
 	size_t len;
 	off_t suboff;
 	struct stat st;
@@ -292,7 +293,7 @@
 	mlmmjsend = concatstr(2, bindir, "/mlmmj-send");
 	myfree(bindir);
 
-	while ((opt = getopt(argc, argv, "hcCdnVUL:a:")) != -1) {
+	while ((opt = getopt(argc, argv, "hcCdnsVUL:a:")) != -1) {
 		switch(opt) {
 		case 'a':
 			address = optarg;
@@ -315,6 +316,9 @@
 		case 'n':
 			nomail = 1;
 			break;
+		case 's':
+			nogensubscribed = 1;
+			break;
 		case 'U':
 			changeuid = 0;
 			break;
@@ -460,6 +464,7 @@
 		unlink(sublockname);
 		myfree(sublockname);
 
+		if(!nogensubscribed)
 		generate_subscribed(listdir, address, mlmmjsend);
 		
 		return EXIT_SUCCESS;
--- a/src/mlmmj-unsub.c	Fri Jun 17 22:55:09 2005 +1000
+++ b/src/mlmmj-unsub.c	Mon Jun 20 22:40:39 2005 +1000
@@ -269,7 +269,7 @@
 static void print_help(const char *prg)
 {
 	printf("Usage: %s -L /path/to/list -a john@doe.org "
-	       "[-c] [-C] [-h] [-L] [-d | -n] [-V]\n"
+	       "[-c] [-C] [-h] [-L] [-d | -n] [-s] [-V]\n"
 	       " -a: Email address to unsubscribe \n"
 	       " -c: Send goodbye mail\n"
 	       " -C: Request mail confirmation\n"
@@ -277,6 +277,7 @@
 	       " -h: This help\n"
 	       " -L: Full path to list directory\n"
 	       " -n: Subscribe to no mail version of list\n"
+	       " -s: Don't send a mail to the address if not subscribed\n"
 	       " -U: Don't switch to the user id of the listdir owner\n"
 	       " -V: Print version\n"
 	       "When no options are specified, unsubscription silently "
@@ -319,6 +320,7 @@
 	int subread, subwrite, rlock, wlock, opt, unsubres, status, nomail = 0;
 	int confirmunsub = 0, unsubconfirm = 0, notifysub = 0, digest = 0;
 	int changeuid = 1, groupwritable = 0, sublock, sublockfd;
+	int nogennotsubscribed = 0;
 	char *listaddr, *listdir = NULL, *address = NULL, *subreadname = NULL;
 	char *subwritename, *mlmmjsend, *bindir, *subdir;
 	char *subddirname, *sublockname;
@@ -338,7 +340,7 @@
 	mlmmjsend = concatstr(2, bindir, "/mlmmj-send");
 	myfree(bindir);
 
-	while ((opt = getopt(argc, argv, "hcCdnVUL:a:")) != -1) {
+	while ((opt = getopt(argc, argv, "hcCdnVUL:a:s")) != -1) {
 		switch(opt) {
 		case 'L':
 			listdir = optarg;
@@ -361,6 +363,9 @@
 		case 'h':
 			print_help(argv[0]);
 			break;
+		case 's':
+			nogennotsubscribed = 1;
+			break;
 		case 'U':
 			changeuid = 0;
 			break;
@@ -434,7 +439,9 @@
 		myfree(subddirname);
 		myfree(listaddr);
 
+		if(!nogennotsubscribed) {
 		generate_notsubscribed(listdir, address, mlmmjsend);
+		}
 
 		exit(EXIT_SUCCESS);
 	}