masqmail

diff 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
line diff
     1.1 --- a/src/smtp_out.c	Fri Jul 23 10:53:04 2010 +0200
     1.2 +++ b/src/smtp_out.c	Fri Jul 23 10:57:53 2010 +0200
     1.3 @@ -234,11 +234,22 @@
     1.4  static gboolean
     1.5  check_helo_response(smtp_base * psb)
     1.6  {
     1.7 -	gchar *ptr = psb->buffer;
     1.8 +	gchar *ptr;
     1.9  
    1.10  	if (!check_response(psb, FALSE))
    1.11  		return FALSE;
    1.12  
    1.13 +	if (psb->last_code == 220) {
    1.14 +		logwrite(LOG_NOTICE, "received a 220 greeting after sending EHLO,\n");
    1.15 +		logwrite(LOG_NOTICE, "please remove `instant_helo' from your route config\n");
    1.16 +		/* read the next response, cause that's the actual helo response */
    1.17 +		if (!read_response(psb, SMTP_CMD_TIMEOUT) || !check_response(psb, FALSE)) {
    1.18 +			return FALSE;
    1.19 +		}
    1.20 +	}
    1.21 +
    1.22 +	ptr = psb->buffer;
    1.23 +
    1.24  	while (*ptr) {
    1.25  		if (strncasecmp(&(ptr[4]), "SIZE", 4) == 0) {
    1.26  			gchar *arg;
    1.27 @@ -676,24 +687,35 @@
    1.28  #endif
    1.29  
    1.30  gboolean
    1.31 -smtp_out_init(smtp_base * psb)
    1.32 +smtp_out_init(smtp_base * psb, gboolean instant_helo)
    1.33  {
    1.34  	gboolean ok;
    1.35  
    1.36 -	if ((ok = read_response(psb, SMTP_INITIAL_TIMEOUT))) {
    1.37 -		if ((ok = check_init_response(psb))) {
    1.38 +	logwrite(LOG_INFO, "smtp_out_init(): instant_helo:%d\n", instant_helo);
    1.39  
    1.40 -			if ((ok = smtp_helo(psb, psb->helo_name))) {
    1.41 +	if (instant_helo) {
    1.42 +		/* we say hello right away, hence we don't know if
    1.43 +		   ESMTP is supported; we just assume it */
    1.44 +		psb->use_esmtp = 1;
    1.45 +	} else {
    1.46 +		if ((ok = read_response(psb, SMTP_INITIAL_TIMEOUT))) {
    1.47 +			ok = check_init_response(psb);
    1.48 +		}
    1.49 +		if (!ok) {
    1.50 +			smtp_out_log_failure(psb, NULL);
    1.51 +			return ok;
    1.52 +		}
    1.53 +	}
    1.54 +
    1.55 +	if ((ok = smtp_helo(psb, psb->helo_name))) {
    1.56  #ifdef ENABLE_AUTH
    1.57 -				if (psb->auth_name && psb->use_auth) {
    1.58 -					/* we completely disregard the response of server here. If
    1.59 -					   authentication fails, the server will complain later
    1.60 -					   anyway. I know, this is not polite... */
    1.61 -					smtp_out_auth(psb);
    1.62 -				}
    1.63 +		if (psb->auth_name && psb->use_auth) {
    1.64 +			/* we completely disregard the response of server here. If
    1.65 +			   authentication fails, the server will complain later
    1.66 +			   anyway. I know, this is not polite... */
    1.67 +			smtp_out_auth(psb);
    1.68 +		}
    1.69  #endif
    1.70 -			}
    1.71 -		}
    1.72  	}
    1.73  	if (!ok)
    1.74  		smtp_out_log_failure(psb, NULL);
    1.75 @@ -907,7 +929,7 @@
    1.76  	if ((psb = smtp_out_open(host, port, resolve_list))) {
    1.77  		set_heloname(psb, return_path->domain, TRUE);
    1.78  		/* initiate connection, send message and quit: */
    1.79 -		if (smtp_out_init(psb)) {
    1.80 +		if (smtp_out_init(psb, FALSE)) {
    1.81  			smtp_out_msg(psb, msg, return_path, rcpt_list, NULL);
    1.82  			if (psb->error == smtp_ok || (psb->error == smtp_fail) || (psb->error == smtp_trylater)
    1.83  			    || (psb->error == smtp_syntax) || (psb->error == smtp_cancel))