mlmmj

changeset de31a9e15c5b

Improved and more consistent closing of SMTP sessions
author Ben Schmidt
date Fri, 12 Nov 2010 02:30:00 +1100
parents d0bf2135ab34
children 5f038f36f66f
files ChangeLog src/mlmmj-send.c
diffstat 2 files changed, 39 insertions(+), 28 deletions(-) [+]
line diff
     1.1 --- a/ChangeLog	Fri Nov 12 02:27:50 2010 +1100
     1.2 +++ b/ChangeLog	Fri Nov 12 02:30:00 2010 +1100
     1.3 @@ -1,3 +1,4 @@
     1.4 + o Improved and more consistent closing of SMTP sessions in error cases
     1.5   o Check the relayhost gives a reply before reading it to avoid a crash
     1.6   o Avoid checking addresses multiple times for notmetoo and make it work even
     1.7     when delivering messages individually
     2.1 --- a/src/mlmmj-send.c	Fri Nov 12 02:27:50 2010 +1100
     2.2 +++ b/src/mlmmj-send.c	Fri Nov 12 02:30:00 2010 +1100
     2.3 @@ -420,7 +420,6 @@
     2.4  	}
     2.5  
     2.6  	close(*sockfd);
     2.7 -
     2.8  	*sockfd = -1;
     2.9  
    2.10  	return retval;
    2.11 @@ -1008,11 +1007,11 @@
    2.12  	case '1': /* A single mail is to be sent */
    2.13  	case '6':
    2.14  		initsmtp(&sockfd, relay, smtpport);
    2.15 -		sendres = send_mail(sockfd, bounceaddr, to_addr, replyto,
    2.16 +		if(send_mail(sockfd, bounceaddr, to_addr, replyto,
    2.17  				mailmap, st.st_size, listdir, NULL,
    2.18 -				hdrs, hdrslen, body, bodylen);
    2.19 -		endsmtp(&sockfd);
    2.20 -		if(sendres) {
    2.21 +				hdrs, hdrslen, body, bodylen)) {
    2.22 +			close(sockfd);
    2.23 +			sockfd = -1;
    2.24  			/* error, so keep it in the queue */
    2.25  			deletewhensent = 0;
    2.26  			/* dump data we want when resending first check
    2.27 @@ -1060,6 +1059,8 @@
    2.28  				}
    2.29  				close(tmpfd);
    2.30  			}
    2.31 +		} else {
    2.32 +			endsmtp(&sockfd);
    2.33  		}
    2.34  		break;
    2.35  	case '2': /* Moderators */
    2.36 @@ -1067,20 +1068,24 @@
    2.37  		if(send_mail_many_fd(sockfd, bounceaddr, NULL, mailmap,
    2.38  				     st.st_size, subfd, NULL, NULL, NULL,
    2.39  				     listdir, NULL, hdrs, hdrslen,
    2.40 -				     body, bodylen))
    2.41 +				     body, bodylen)) {
    2.42  			close(sockfd);
    2.43 -		else
    2.44 +			sockfd = -1;
    2.45 +		} else {
    2.46  			endsmtp(&sockfd);
    2.47 +		}
    2.48  		break;
    2.49  	case '3': /* resending earlier failed mails */
    2.50  		initsmtp(&sockfd, relay, smtpport);
    2.51  		if(send_mail_many_fd(sockfd, NULL, NULL, mailmap, st.st_size,
    2.52  				subfd, listaddr, listdelim, mailfilename,
    2.53  				listdir, mlmmjbounce, hdrs, hdrslen,
    2.54 -				body, bodylen))
    2.55 +				body, bodylen)) {
    2.56  			close(sockfd);
    2.57 -		else
    2.58 +			sockfd = -1;
    2.59 +		} else {
    2.60  			endsmtp(&sockfd);
    2.61 +		}
    2.62  		unlink(subfilename);
    2.63  		break;
    2.64  	case '4': /* send mails to owner */
    2.65 @@ -1088,18 +1093,20 @@
    2.66  		if(send_mail_many_fd(sockfd, bounceaddr, NULL, mailmap,
    2.67  				st.st_size, subfd, listaddr, listdelim,
    2.68  				mailfilename, listdir, mlmmjbounce,
    2.69 -				hdrs, hdrslen, body, bodylen))
    2.70 +				hdrs, hdrslen, body, bodylen)) {
    2.71  			close(sockfd);
    2.72 -		else
    2.73 +			sockfd = -1;
    2.74 +		} else {
    2.75  			endsmtp(&sockfd);
    2.76 +		}
    2.77  		break;
    2.78  	case '5': /* bounceprobe - handle relayhost local users bouncing*/
    2.79  		initsmtp(&sockfd, relay, smtpport);
    2.80 -		sendres = send_mail(sockfd, bounceaddr, to_addr, replyto,
    2.81 +		if(send_mail(sockfd, bounceaddr, to_addr, replyto,
    2.82  				mailmap, st.st_size, listdir, NULL,
    2.83 -				hdrs, hdrslen, body, bodylen);
    2.84 -		endsmtp(&sockfd);
    2.85 -		if(sendres) {
    2.86 +				hdrs, hdrslen, body, bodylen)) {
    2.87 +			close(sockfd);
    2.88 +			sockfd = -1;
    2.89  			/* error, so remove the probefile */
    2.90  			tmpstr = mystrdup(to_addr);
    2.91  			a = strchr(tmpstr, '@');
    2.92 @@ -1110,6 +1117,8 @@
    2.93  			unlink(probefile);
    2.94  			myfree(probefile);
    2.95  			myfree(tmpstr);
    2.96 +		} else {
    2.97 +			endsmtp(&sockfd);
    2.98  		}
    2.99  		break;
   2.100  	case '7':
   2.101 @@ -1173,6 +1182,8 @@
   2.102  					verp = NULL;
   2.103  				}
   2.104  			}
   2.105 +			/* We can't be in SMTP DATA state or anything like
   2.106 +			 * that, so should be able to safely QUIT. */
   2.107  			endsmtp(&sockfd);
   2.108  		}
   2.109  
   2.110 @@ -1238,7 +1249,12 @@
   2.111  								hdrs, hdrslen,
   2.112  								body, bodylen);
   2.113  					}
   2.114 +				    	if (sendres) {
   2.115 +					    	close(sockfd);
   2.116 +					    	sockfd = -1;
   2.117 +				    	} else {
   2.118  					endsmtp(&sockfd);
   2.119 +				    	}
   2.120  					for(i = 0; i < stl.count; i++)
   2.121  						myfree(stl.strs[i]);
   2.122  					stl.count = 0;
   2.123 @@ -1266,21 +1282,16 @@
   2.124  						mlmmjbounce, hdrs, hdrslen,
   2.125  						body, bodylen);
   2.126  			}
   2.127 +			if (sendres) {
   2.128 +				close(sockfd);
   2.129 +				sockfd = -1;
   2.130 +			} else {
   2.131  			endsmtp(&sockfd);
   2.132 +			}
   2.133  			for(i = 0; i < stl.count; i++)
   2.134  				myfree(stl.strs[i]);
   2.135  			stl.count = 0;
   2.136  		}
   2.137 -
   2.138 -		if (sendres) {
   2.139 -			/* If send_mail_many() failed we close the
   2.140 -			 * connection to the mail server in a brutal
   2.141 -			 * manner, because we could be in any state
   2.142 -			 * (DATA for instance). */
   2.143 -			close(sockfd);
   2.144 -		} else {
   2.145 -			endsmtp(&sockfd);
   2.146 -		}
   2.147  		myfree(stl.strs);
   2.148  		myfree(verpfrom);
   2.149  		closedir(subddir);
   2.150 @@ -1296,7 +1307,6 @@
   2.151  	myfree(hdrs);
   2.152  	myfree(body);
   2.153  	myfree(mlmmjbounce);
   2.154 -	close(sockfd);
   2.155  	munmap(mailmap, st.st_size);
   2.156  	close(mailfd);
   2.157  	myfree(verp);