comparison src/smtp_out.c @ 222:8cddc65765bd

added support for STARTTLS wrappers added the route config option `instant_helo' which causes masqmail, as SMTP client, not to wait for the server's 220 greeting. Instead if says EHLO right at once. You'll need this for STARTTLS wrappers that usually eat the greeting line.
author meillo@marmaro.de
date Fri, 23 Jul 2010 10:57:53 +0200
parents 10da50168dab
children 996b53a50f55
comparison
equal deleted inserted replaced
221:8742d2cee364 222:8cddc65765bd
232 } 232 }
233 233
234 static gboolean 234 static gboolean
235 check_helo_response(smtp_base * psb) 235 check_helo_response(smtp_base * psb)
236 { 236 {
237 gchar *ptr = psb->buffer; 237 gchar *ptr;
238 238
239 if (!check_response(psb, FALSE)) 239 if (!check_response(psb, FALSE))
240 return FALSE; 240 return FALSE;
241
242 if (psb->last_code == 220) {
243 logwrite(LOG_NOTICE, "received a 220 greeting after sending EHLO,\n");
244 logwrite(LOG_NOTICE, "please remove `instant_helo' from your route config\n");
245 /* read the next response, cause that's the actual helo response */
246 if (!read_response(psb, SMTP_CMD_TIMEOUT) || !check_response(psb, FALSE)) {
247 return FALSE;
248 }
249 }
250
251 ptr = psb->buffer;
241 252
242 while (*ptr) { 253 while (*ptr) {
243 if (strncasecmp(&(ptr[4]), "SIZE", 4) == 0) { 254 if (strncasecmp(&(ptr[4]), "SIZE", 4) == 0) {
244 gchar *arg; 255 gchar *arg;
245 psb->use_size = TRUE; 256 psb->use_size = TRUE;
674 } 685 }
675 686
676 #endif 687 #endif
677 688
678 gboolean 689 gboolean
679 smtp_out_init(smtp_base * psb) 690 smtp_out_init(smtp_base * psb, gboolean instant_helo)
680 { 691 {
681 gboolean ok; 692 gboolean ok;
682 693
683 if ((ok = read_response(psb, SMTP_INITIAL_TIMEOUT))) { 694 logwrite(LOG_INFO, "smtp_out_init(): instant_helo:%d\n", instant_helo);
684 if ((ok = check_init_response(psb))) { 695
685 696 if (instant_helo) {
686 if ((ok = smtp_helo(psb, psb->helo_name))) { 697 /* we say hello right away, hence we don't know if
698 ESMTP is supported; we just assume it */
699 psb->use_esmtp = 1;
700 } else {
701 if ((ok = read_response(psb, SMTP_INITIAL_TIMEOUT))) {
702 ok = check_init_response(psb);
703 }
704 if (!ok) {
705 smtp_out_log_failure(psb, NULL);
706 return ok;
707 }
708 }
709
710 if ((ok = smtp_helo(psb, psb->helo_name))) {
687 #ifdef ENABLE_AUTH 711 #ifdef ENABLE_AUTH
688 if (psb->auth_name && psb->use_auth) { 712 if (psb->auth_name && psb->use_auth) {
689 /* we completely disregard the response of server here. If 713 /* we completely disregard the response of server here. If
690 authentication fails, the server will complain later 714 authentication fails, the server will complain later
691 anyway. I know, this is not polite... */ 715 anyway. I know, this is not polite... */
692 smtp_out_auth(psb); 716 smtp_out_auth(psb);
693 } 717 }
694 #endif 718 #endif
695 }
696 }
697 } 719 }
698 if (!ok) 720 if (!ok)
699 smtp_out_log_failure(psb, NULL); 721 smtp_out_log_failure(psb, NULL);
700 return ok; 722 return ok;
701 } 723 }
905 return_path = msg->return_path; 927 return_path = msg->return_path;
906 928
907 if ((psb = smtp_out_open(host, port, resolve_list))) { 929 if ((psb = smtp_out_open(host, port, resolve_list))) {
908 set_heloname(psb, return_path->domain, TRUE); 930 set_heloname(psb, return_path->domain, TRUE);
909 /* initiate connection, send message and quit: */ 931 /* initiate connection, send message and quit: */
910 if (smtp_out_init(psb)) { 932 if (smtp_out_init(psb, FALSE)) {
911 smtp_out_msg(psb, msg, return_path, rcpt_list, NULL); 933 smtp_out_msg(psb, msg, return_path, rcpt_list, NULL);
912 if (psb->error == smtp_ok || (psb->error == smtp_fail) || (psb->error == smtp_trylater) 934 if (psb->error == smtp_ok || (psb->error == smtp_fail) || (psb->error == smtp_trylater)
913 || (psb->error == smtp_syntax) || (psb->error == smtp_cancel)) 935 || (psb->error == smtp_syntax) || (psb->error == smtp_cancel))
914 smtp_out_quit(psb); 936 smtp_out_quit(psb);
915 } 937 }