changeset 143:f13bdf402943

Also remove leftover .{mailfrom,reciptto,reply-to} files without the corresponding mail.
author mmj
date Wed, 02 Jun 2004 15:24:59 +1000
parents 67eadb823b92
children c5f63433fbca
files src/mlmmj-maintd.c
diffstat 1 files changed, 13 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/mlmmj-maintd.c	Wed Jun 02 08:57:48 2004 +1000
+++ b/src/mlmmj-maintd.c	Wed Jun 02 15:24:59 2004 +1000
@@ -113,7 +113,7 @@
 	DIR *queuedir;
 	struct dirent *dp;
 	char *mailname, *fromname, *toname, *reptoname, *from, *to, *repto;
-	char *discardedname = NULL;
+	char *discardedname = NULL, *ch;
 	char *dirname = concatstr(2, listdir, "/queue/");
 	FILE *ffrom, *fto, *f;
 	pid_t pid;
@@ -133,9 +133,6 @@
 	}
 
 	while((dp = readdir(queuedir)) != NULL) {
-		if(strchr(dp->d_name, '.'))
-			continue;
-
 		if(stat(dp->d_name, &st) < 0) {
 			log_error(LOG_ARGS, "Could not stat(%s)",dp->d_name);
 			continue;
@@ -144,6 +141,17 @@
 		if(!S_ISREG(st.st_mode))
 			continue;
 
+		if(strchr(dp->d_name, '.')) {
+			mailname = strdup(dp->d_name);
+			ch = strchr(mailname, '.');
+			*ch = '\0';
+			if(stat(mailname, &st) < 0)
+				if(errno == ENOENT)
+					unlink(dp->d_name);
+			free(mailname);
+			continue;
+		}
+
 		mailname = concatstr(3, listdir, "/queue/", dp->d_name);
 
 		fromname = concatstr(2, mailname, ".mailfrom");
@@ -328,7 +336,7 @@
 	mlmmjsend = concatstr(2, bindir, "/mlmmj-send");
 	free(bindir);
 
-	if(daemon(1,0) < 0) {
+	if(daemonize && daemon(1,0) < 0) {
 		log_error(LOG_ARGS, "Could not daemonize. Only one "
 				"maintenance run will be done.");
 		daemonize = 0;