Mercurial > hg > mlmmj
comparison 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 |
comparison
equal
deleted
inserted
replaced
780:ddae562f7cf0 | 781:563b513fae21 |
---|---|
248 size_t bodylen) | 248 size_t bodylen) |
249 { | 249 { |
250 int retval = 0; | 250 int retval = 0; |
251 char *reply, *reply2, *tohdr; | 251 char *reply, *reply2, *tohdr; |
252 | 252 |
253 if(sockfd == -1) | |
254 return EBADF; | |
255 | |
253 if(strchr(to, '@') == NULL) { | 256 if(strchr(to, '@') == NULL) { |
254 errno = 0; | 257 errno = 0; |
255 log_error(LOG_ARGS, "No @ in address, ignoring %s", | 258 log_error(LOG_ARGS, "No @ in address, ignoring %s", |
256 to); | 259 to); |
257 return 0; | 260 return 0; |
376 int initsmtp(int *sockfd, const char *relayhost, unsigned short port) | 379 int initsmtp(int *sockfd, const char *relayhost, unsigned short port) |
377 { | 380 { |
378 int retval = 0; | 381 int retval = 0; |
379 char *reply = NULL; | 382 char *reply = NULL; |
380 char *myhostname = hostnamestr(); | 383 char *myhostname = hostnamestr(); |
381 | 384 |
382 init_sockfd(sockfd, relayhost, port); | 385 init_sockfd(sockfd, relayhost, port); |
383 | 386 |
387 if(*sockfd == -1) | |
388 return EBADF; | |
389 | |
384 if((reply = checkwait_smtpreply(*sockfd, MLMMJ_CONNECT)) != NULL) { | 390 if((reply = checkwait_smtpreply(*sockfd, MLMMJ_CONNECT)) != NULL) { |
385 log_error(LOG_ARGS, "No proper greeting to our connect" | 391 log_error(LOG_ARGS, "No proper greeting to our connect" |
386 "Reply: [%s]", reply); | 392 "Reply: [%s]", reply); |
387 myfree(reply); | 393 myfree(reply); |
388 retval = MLMMJ_CONNECT; | 394 retval = MLMMJ_CONNECT; |
430 const char *hdrs, size_t hdrslen, const char *body, | 436 const char *hdrs, size_t hdrslen, const char *body, |
431 size_t bodylen, const char *verpextra) | 437 size_t bodylen, const char *verpextra) |
432 { | 438 { |
433 int retval, i; | 439 int retval, i; |
434 char *reply, *reply2; | 440 char *reply, *reply2; |
441 | |
442 if(sockfd == -1) | |
443 return EBADF; | |
435 | 444 |
436 retval = write_mail_from(sockfd, from, verpextra); | 445 retval = write_mail_from(sockfd, from, verpextra); |
437 if(retval) { | 446 if(retval) { |
438 log_error(LOG_ARGS, "Could not write MAIL FROM\n"); | 447 log_error(LOG_ARGS, "Could not write MAIL FROM\n"); |
439 return retval; | 448 return retval; |
1165 verp = NULL; | 1174 verp = NULL; |
1166 } | 1175 } |
1167 | 1176 |
1168 if(verp) { | 1177 if(verp) { |
1169 initsmtp(&sockfd, relay, smtpport); | 1178 initsmtp(&sockfd, relay, smtpport); |
1170 if(write_mail_from(sockfd, verpfrom, verp)) { | 1179 if(sockfd > -1) { |
1180 if(write_mail_from(sockfd, verpfrom, verp)) { | |
1171 log_error(LOG_ARGS, | 1181 log_error(LOG_ARGS, |
1172 "Could not write MAIL FROM\n"); | 1182 "Could not write VERP MAIL FROM. " |
1183 "Not sending with VERP."); | |
1173 verp = NULL; | 1184 verp = NULL; |
1174 } else { | 1185 } else { |
1175 reply = checkwait_smtpreply(sockfd, MLMMJ_FROM); | 1186 reply = checkwait_smtpreply(sockfd, MLMMJ_FROM); |
1176 if(reply) { | 1187 if(reply) { |
1177 log_error(LOG_ARGS, | 1188 log_error(LOG_ARGS, |
1178 "Mailserver did not " | 1189 "Mailserver did not " |
1179 "accept verp mail from. " | 1190 "accept VERP MAIL FROM. " |
1180 "Not sending with VERP."); | 1191 "Not sending with VERP."); |
1181 myfree(reply); | 1192 myfree(reply); |
1182 verp = NULL; | 1193 verp = NULL; |
1183 } | 1194 } |
1195 } | |
1196 /* We can't be in SMTP DATA state or anything like | |
1197 * that, so should be able to safely QUIT. */ | |
1198 endsmtp(&sockfd); | |
1199 } else { | |
1200 log_error(LOG_ARGS, | |
1201 "Could not connect to " | |
1202 "write VERP MAIL FROM. " | |
1203 "Not sending with VERP."); | |
1204 verp = NULL; | |
1184 } | 1205 } |
1185 /* We can't be in SMTP DATA state or anything like | |
1186 * that, so should be able to safely QUIT. */ | |
1187 endsmtp(&sockfd); | |
1188 } | 1206 } |
1189 | 1207 |
1190 while((dp = readdir(subddir)) != NULL) { | 1208 while((dp = readdir(subddir)) != NULL) { |
1191 if(!strcmp(dp->d_name, ".")) | 1209 if(!strcmp(dp->d_name, ".")) |
1192 continue; | 1210 continue; |