changeset 147:e53fe7b9022b

mlmmj-maintd now resends the ones that failed. Add listctrl switch to do aid with it in mlmmj-send.
author mmj
date Thu, 03 Jun 2004 05:10:11 +1000
parents 5696f7e676ec
children 906df45ea4c3
files src/mlmmj-maintd.c src/mlmmj-send.c
diffstat 2 files changed, 105 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/mlmmj-maintd.c	Thu Jun 03 01:26:25 2004 +1000
+++ b/src/mlmmj-maintd.c	Thu Jun 03 05:10:11 2004 +1000
@@ -252,17 +252,88 @@
 
 int resend_requeue(const char *listdir, const char *mlmmjsend)
 {
-#if 0
 	DIR *queuedir;
 	struct dirent *dp;
-#endif
+	char *dirname = concatstr(2, listdir, "/requeue/");
+	char *archivefilename, *subfilename, *subnewname;
+	struct stat st;
+	pid_t pid;
+	time_t t;
+
+	if(chdir(dirname) < 0) {
+		log_error(LOG_ARGS, "Could not chdir(%s)", dirname);
+		free(dirname);
+		return 1;
+	}
+		
+	if((queuedir = opendir(dirname)) == NULL) {
+		log_error(LOG_ARGS, "Could not opendir(%s)", dirname);
+		free(dirname);
+		return 1;
+	}
+
+	while((dp = readdir(queuedir)) != NULL) {
+		if((strcmp(dp->d_name, "..") == 0) ||
+			(strcmp(dp->d_name, ".") == 0))
+				continue;
+
+		if(stat(dp->d_name, &st) < 0) {
+			log_error(LOG_ARGS, "Could not stat(%s)",dp->d_name);
+			continue;
+		}
+
+		if(!S_ISDIR(st.st_mode))
+			continue;
+
+		/* Remove old empty directories */
+		t = time(NULL);
+		if(t - st.st_mtime > (time_t)3600)
+			if(rmdir(dp->d_name) == 0)
+				continue;
 
-	/* TODO: Go through all mails sitting in requeue/ and send the mail in the
-	 * archive marked by the directory name in requeue/ to the people in
-	 * the file subscribers sitting in the same dir.
-	 * IMPORTANT: do not forget to *not* archive and *not* delete when
-	 * sent.
+		archivefilename = concatstr(3, listdir, "/archive/",
+						dp->d_name);
+		if(stat(archivefilename, &st) < 0) {
+			/* Might be it's just not moved to the archive
+			 * yet because it's still getting sent, so just
+			 * continue
 	 */
+			free(archivefilename);
+			continue;
+		}
+		subfilename = concatstr(3, dirname, dp->d_name, "/subscribers");
+		if(stat(subfilename, &st) < 0) {
+			log_error(LOG_ARGS, "Could not stat(%s)", subfilename);
+			free(archivefilename);
+			free(subfilename);
+			continue;
+		}
+
+		subnewname = concatstr(2, subfilename, ".resending");
+
+		if(rename(subfilename, subnewname) < 0) {
+			log_error(LOG_ARGS, "Could not rename(%s, %s)",
+						subfilename, subnewname);
+			free(archivefilename);
+			free(subfilename);
+			free(subnewname);
+			continue;
+		}
+		free(subfilename);
+		
+		pid = fork();
+
+		if(pid == 0)
+			execlp(mlmmjsend, mlmmjsend,
+					"-l", "3",
+					"-L", listdir,
+					"-m", archivefilename,
+					"-s", subnewname,
+					"-a",
+					"-D", 0);
+
+
+	}
 
 	return 0;
 }
--- a/src/mlmmj-send.c	Thu Jun 03 01:26:25 2004 +1000
+++ b/src/mlmmj-send.c	Thu Jun 03 05:10:11 2004 +1000
@@ -108,7 +108,7 @@
 
 	if((c = strchr(myfrom, '@')) == NULL) {
 		free(myfrom);
-		return 0; /* Success when mailformed 'from' */
+		return 0; /* Success when malformed 'from' */
 	}
 	*c = '\0';
 	num = strrchr(myfrom, '-');
@@ -358,20 +358,21 @@
 {
         printf("Usage: %s [-L /path/to/list || -l listctrl] -m /path/to/mail "
 	       "[-a] [-D] [-F]\n"
-	       "       [-h] [-r] [-R] [-T] [-V]\n"
+	       "       [-h] [-r] [-R] [-s] [-T] [-V]\n"
 	       " -a: Don't archive the mail\n"
 	       " -D: Don't delete the mail after it's sent\n"
 	       " -F: What to use as MAIL FROM:\n"
 	       " -h: This help\n"
-	       " -l: List control variable:\n"
-	       "    '1' means 'send a single mail'\n"
+	       " -l: List control variable:\n", prg);
+	printf("    '1' means 'send a single mail'\n"
 	       "    '2' means 'mail to moderators'\n"
 	       " -L: Full path to list directory\n"
 	       " -m: Full path to mail file\n"
 	       " -r: Relayhost (defaults to localhost)\n"
 	       " -R: What to use as Reply-To: header\n"
+	       " -s: Subscribers file name\n"
 	       " -T: What to use as RCPT TO:\n"
-	       " -V: Print version\n", prg);
+	       " -V: Print version\n");
 	exit(EXIT_SUCCESS);
 }
 
@@ -397,7 +398,7 @@
 	mlmmjbounce = concatstr(2, bindir, "/mlmmj-bounce");
 	free(bindir);
 	
-	while ((opt = getopt(argc, argv, "aVDhm:l:L:R:F:T:r:")) != -1){
+	while ((opt = getopt(argc, argv, "aVDhm:l:L:R:F:T:r:s:")) != -1){
 		switch(opt) {
 		case 'a':
 			archive = 0;
@@ -426,6 +427,9 @@
 		case 'R':
 			replyto = optarg;
 			break;
+		case 's':
+			subfilename = optarg;
+			break;
 		case 'T':
 			to_addr = optarg;
 			break;
@@ -456,7 +460,7 @@
 		exit(EXIT_FAILURE);
 	}
 
-	if(listctrl[0] == '1' || listctrl[0] == '2')
+	if(listctrl[0] == '1' || listctrl[0] == '2' || listctrl[0] == '3')
 		archive = 0;
 
 	if(listdir)
@@ -484,6 +488,13 @@
 			exit(EXIT_SUCCESS);
 		}
 		break;
+	case '3': /* resending earlier failed mails */
+		if((subfile = fopen(subfilename, "r")) == NULL) {
+			log_error(LOG_ARGS, "Could not open '%s':",
+					    subfilename);
+			exit(EXIT_FAILURE);
+		}
+
 	default: /* normal list mail -- now handled when forking */
 		break;
 	}
@@ -536,6 +547,13 @@
 			       NULL, NULL, listdir, NULL);
 		endsmtp(&sockfd);
 		break;
+	case '3': /* resending earlier failed mails */
+		initsmtp(&sockfd, relayhost);
+		send_mail_many(sockfd, NULL, NULL, mailfile, subfile,
+				listaddr, mailfilename, listdir, mlmmjbounce);
+		endsmtp(&sockfd);
+		unlink(subfilename);
+		break;
 	default: /* normal list mail */
 		subddirname = concatstr(2, listdir, "/subscribers.d/");
 		if((subddir = opendir(subddirname)) == NULL) {
@@ -589,12 +607,9 @@
 				free(newsockfd);
 				fclose(subfile);
 				exit(EXIT_SUCCESS);
-			} else {
-				syslog(LOG_INFO, "%d/%d connections open",
-						conncount, MAX_CONNECTIONS);
+			} else
 				fclose(subfile);
 			}
-		}
 		closedir(subddir);
 		break;
 	}