diff src/mlmmj-send.c @ 781:563b513fae21

Avoid losing mail when connection to relayhost fails
author Ben Schmidt
date Mon, 15 Nov 2010 11:12:50 +1100
parents 5f038f36f66f
children 1c13e314e5b9
line wrap: on
line diff
--- a/src/mlmmj-send.c	Mon Nov 15 10:11:28 2010 +1100
+++ b/src/mlmmj-send.c	Mon Nov 15 11:12:50 2010 +1100
@@ -250,6 +250,9 @@
 	int retval = 0;
 	char *reply, *reply2, *tohdr;
 
+	if(sockfd == -1)
+		return EBADF;
+
 	if(strchr(to, '@') == NULL) {
 		errno = 0;
 		log_error(LOG_ARGS, "No @ in address, ignoring %s",
@@ -381,6 +384,9 @@
 	
 	init_sockfd(sockfd, relayhost, port);
 	
+	if(*sockfd == -1)
+		return EBADF;
+
 	if((reply = checkwait_smtpreply(*sockfd, MLMMJ_CONNECT)) != NULL) {
 		log_error(LOG_ARGS, "No proper greeting to our connect"
 			  "Reply: [%s]", reply);
@@ -433,6 +439,9 @@
 	int retval, i;
 	char *reply, *reply2;
 
+	if(sockfd == -1)
+		return EBADF;
+
 	retval = write_mail_from(sockfd, from, verpextra);
 	if(retval) {
 		log_error(LOG_ARGS, "Could not write MAIL FROM\n");
@@ -1167,16 +1176,18 @@
 		
 		if(verp) {
 			initsmtp(&sockfd, relay, smtpport);
+			if(sockfd > -1) {
 			if(write_mail_from(sockfd, verpfrom, verp)) {
 				log_error(LOG_ARGS,
-						"Could not write MAIL FROM\n");
+					    "Could not write VERP MAIL FROM. "
+					    "Not sending with VERP.");
 				verp = NULL;
 			} else {
 				reply = checkwait_smtpreply(sockfd, MLMMJ_FROM);
 				if(reply) {
 					log_error(LOG_ARGS,
 						"Mailserver did not "
-						"accept verp mail from. "
+						"accept VERP MAIL FROM. "
 						"Not sending with VERP.");
 					myfree(reply);
 					verp = NULL;
@@ -1185,6 +1196,13 @@
 			/* We can't be in SMTP DATA state or anything like
 			 * that, so should be able to safely QUIT. */
 			endsmtp(&sockfd);
+			} else {
+			    log_error(LOG_ARGS,
+				    "Could not connect to "
+				    "write VERP MAIL FROM. "
+				    "Not sending with VERP.");
+			    verp = NULL;
+			}
 		}
 
 		while((dp = readdir(subddir)) != NULL) {