masqmail-0.2

diff src/smtp_out.c @ 10:26e34ae9a3e3

changed indention and line wrapping to a more consistent style
author meillo@marmaro.de
date Mon, 27 Oct 2008 16:23:10 +0100
parents 08114f7dcc23
children f671821d8222
line diff
     1.1 --- a/src/smtp_out.c	Mon Oct 27 16:21:27 2008 +0100
     1.2 +++ b/src/smtp_out.c	Mon Oct 27 16:23:10 2008 +0100
     1.3 @@ -4,7 +4,7 @@
     1.4   * it under the terms of the GNU General Public License as published by
     1.5   * the Free Software Foundation; either version 2 of the License, or
     1.6   * (at your option) any later version.
     1.7 - * 
     1.8 + *
     1.9   * This program is distributed in the hope that it will be useful,
    1.10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.12 @@ -47,872 +47,860 @@
    1.13  #include "base64/base64.h"
    1.14  #endif
    1.15  
    1.16 -void destroy_smtpbase(smtp_base *psb)
    1.17 +void
    1.18 +destroy_smtpbase(smtp_base * psb)
    1.19  {
    1.20 -  fclose(psb->in);
    1.21 -  fclose(psb->out);
    1.22 +	fclose(psb->in);
    1.23 +	fclose(psb->out);
    1.24  
    1.25 -  close(psb->sock);
    1.26 +	close(psb->sock);
    1.27  
    1.28 -  if(psb->helo_name) g_free(psb->helo_name);
    1.29 -  if(psb->buffer) g_free(psb->buffer);
    1.30 -  if(psb->auth_names) g_strfreev(psb->auth_names);
    1.31 +	if (psb->helo_name)
    1.32 +		g_free(psb->helo_name);
    1.33 +	if (psb->buffer)
    1.34 +		g_free(psb->buffer);
    1.35 +	if (psb->auth_names)
    1.36 +		g_strfreev(psb->auth_names);
    1.37  
    1.38 -  if(psb->auth_name) g_free(psb->auth_name);
    1.39 -  if(psb->auth_login) g_free(psb->auth_login);
    1.40 -  if(psb->auth_secret) g_free(psb->auth_secret);
    1.41 +	if (psb->auth_name)
    1.42 +		g_free(psb->auth_name);
    1.43 +	if (psb->auth_login)
    1.44 +		g_free(psb->auth_login);
    1.45 +	if (psb->auth_secret)
    1.46 +		g_free(psb->auth_secret);
    1.47  }
    1.48  
    1.49 -gchar *set_heloname(smtp_base *psb, gchar *default_name, gboolean do_correct)
    1.50 +gchar*
    1.51 +set_heloname(smtp_base * psb, gchar * default_name, gboolean do_correct)
    1.52  {
    1.53 -  struct sockaddr_in sname;
    1.54 -  int len = sizeof(struct sockaddr_in);
    1.55 -  struct hostent *host_entry;
    1.56 +	struct sockaddr_in sname;
    1.57 +	int len = sizeof(struct sockaddr_in);
    1.58 +	struct hostent *host_entry;
    1.59  
    1.60 -  if(do_correct){
    1.61 -    getsockname(psb->sock, (struct sockaddr *)(&sname), &len);
    1.62 -    DEBUG(5) debugf("socket: name.sin_addr = %s\n", inet_ntoa(sname.sin_addr));
    1.63 -    host_entry =
    1.64 -      gethostbyaddr((const char *)&(sname.sin_addr),
    1.65 -		    sizeof(sname.sin_addr), AF_INET);
    1.66 -    if(host_entry){
    1.67 -      psb->helo_name = g_strdup(host_entry->h_name);
    1.68 -    }else{
    1.69 -      /* we failed to look up our own name. Instead of giving our local hostname,
    1.70 -	 we may give our IP number to show the server that we are at least
    1.71 -	 willing to be honest. For the really picky ones.*/
    1.72 -      DEBUG(5) debugf("failed to look up own host name.\n");
    1.73 -      psb->helo_name = g_strdup_printf("[%s]", inet_ntoa(sname.sin_addr));
    1.74 -    }
    1.75 -    DEBUG(5) debugf("helo_name = %s\n", psb->helo_name);
    1.76 -  }
    1.77 -  if(psb->helo_name == NULL){
    1.78 -    psb->helo_name = g_strdup(default_name);
    1.79 -  }
    1.80 -  return psb->helo_name;
    1.81 -} 
    1.82 +	if (do_correct) {
    1.83 +		getsockname(psb->sock, (struct sockaddr *) (&sname), &len);
    1.84 +		DEBUG(5) debugf("socket: name.sin_addr = %s\n", inet_ntoa(sname.sin_addr));
    1.85 +		host_entry = gethostbyaddr((const char *) &(sname.sin_addr), sizeof(sname.sin_addr), AF_INET);
    1.86 +		if (host_entry) {
    1.87 +			psb->helo_name = g_strdup(host_entry->h_name);
    1.88 +		} else {
    1.89 +			/* we failed to look up our own name. Instead of giving our local hostname,
    1.90 +			   we may give our IP number to show the server that we are at least
    1.91 +			   willing to be honest. For the really picky ones. */
    1.92 +			DEBUG(5) debugf("failed to look up own host name.\n");
    1.93 +			psb->helo_name = g_strdup_printf("[%s]", inet_ntoa(sname.sin_addr));
    1.94 +		}
    1.95 +		DEBUG(5) debugf("helo_name = %s\n", psb->helo_name);
    1.96 +	}
    1.97 +	if (psb->helo_name == NULL) {
    1.98 +		psb->helo_name = g_strdup(default_name);
    1.99 +	}
   1.100 +	return psb->helo_name;
   1.101 +}
   1.102  
   1.103  #ifdef ENABLE_AUTH
   1.104  
   1.105 -gboolean set_auth(smtp_base *psb, gchar *name, gchar *login, gchar *secret)
   1.106 +gboolean
   1.107 +set_auth(smtp_base * psb, gchar * name, gchar * login, gchar * secret)
   1.108  {
   1.109 -  if((strcasecmp(name, "CRAM-MD5") == 0) ||
   1.110 -     (strcasecmp(name, "LOGIN") == 0)) {
   1.111 -    psb->auth_name = g_strdup(name);
   1.112 -    psb->auth_login = g_strdup(login);
   1.113 -    psb->auth_secret = g_strdup(secret);
   1.114 -    
   1.115 -    return TRUE;
   1.116 -  }
   1.117 -  return FALSE;
   1.118 +	if ((strcasecmp(name, "CRAM-MD5") == 0) || (strcasecmp(name, "LOGIN") == 0)) {
   1.119 +		psb->auth_name = g_strdup(name);
   1.120 +		psb->auth_login = g_strdup(login);
   1.121 +		psb->auth_secret = g_strdup(secret);
   1.122 +
   1.123 +		return TRUE;
   1.124 +	}
   1.125 +	return FALSE;
   1.126  }
   1.127  
   1.128  #endif
   1.129  
   1.130 -static
   1.131 -smtp_base *create_smtpbase(gint sock)
   1.132 +static smtp_base*
   1.133 +create_smtpbase(gint sock)
   1.134  {
   1.135 -  gint dup_sock;
   1.136 +	gint dup_sock;
   1.137  
   1.138 -  smtp_base *psb = (smtp_base *)g_malloc(sizeof(smtp_base));
   1.139 +	smtp_base *psb = (smtp_base *) g_malloc(sizeof(smtp_base));
   1.140  
   1.141 -  psb->sock = sock;
   1.142 +	psb->sock = sock;
   1.143  
   1.144 -  psb->use_esmtp = FALSE;
   1.145 -  psb->use_size = FALSE;
   1.146 -  psb->use_pipelining = FALSE;
   1.147 -  psb->use_auth = FALSE;
   1.148 +	psb->use_esmtp = FALSE;
   1.149 +	psb->use_size = FALSE;
   1.150 +	psb->use_pipelining = FALSE;
   1.151 +	psb->use_auth = FALSE;
   1.152  
   1.153 -  psb->max_size = 0;
   1.154 -  psb->auth_names = NULL;
   1.155 +	psb->max_size = 0;
   1.156 +	psb->auth_names = NULL;
   1.157  
   1.158 -  psb->buffer = (gchar *)g_malloc(SMTP_BUF_LEN);
   1.159 +	psb->buffer = (gchar *) g_malloc(SMTP_BUF_LEN);
   1.160  
   1.161 -  dup_sock = dup(sock);
   1.162 -  psb->out = fdopen(sock, "w");
   1.163 -  psb->in = fdopen(dup_sock, "r");
   1.164 +	dup_sock = dup(sock);
   1.165 +	psb->out = fdopen(sock, "w");
   1.166 +	psb->in = fdopen(dup_sock, "r");
   1.167  
   1.168 -  psb->error = smtp_ok;
   1.169 +	psb->error = smtp_ok;
   1.170  
   1.171 -  psb->helo_name = NULL;
   1.172 -  
   1.173 -  psb->auth_name = psb->auth_login = psb->auth_secret = NULL;
   1.174 +	psb->helo_name = NULL;
   1.175  
   1.176 -  return psb;
   1.177 +	psb->auth_name = psb->auth_login = psb->auth_secret = NULL;
   1.178 +
   1.179 +	return psb;
   1.180  }
   1.181  
   1.182 -static
   1.183 -gboolean read_response(smtp_base *psb, int timeout)
   1.184 +static gboolean
   1.185 +read_response(smtp_base * psb, int timeout)
   1.186  {
   1.187 -  gint buf_pos = 0;
   1.188 -  gchar code[5];
   1.189 -  gint i, len;
   1.190 +	gint buf_pos = 0;
   1.191 +	gchar code[5];
   1.192 +	gint i, len;
   1.193  
   1.194 -  do{
   1.195 -    len = read_sockline(psb->in, &(psb->buffer[buf_pos]),
   1.196 -			SMTP_BUF_LEN - buf_pos, timeout, READSOCKL_CHUG);
   1.197 -    if(len == -3){
   1.198 -      psb->error = smtp_timeout;
   1.199 -      return FALSE;
   1.200 -    }
   1.201 -    else if(len == -2){
   1.202 -      psb->error = smtp_syntax;
   1.203 -      return FALSE;
   1.204 -    }
   1.205 -    else if(len == -1){
   1.206 -      psb->error = smtp_eof;
   1.207 -      return FALSE;
   1.208 -    }
   1.209 -    for(i = 0; i < 4; i++)
   1.210 -      code[i] = psb->buffer[buf_pos+i];
   1.211 -    code[i] = 0;
   1.212 -    psb->last_code = atoi(code);
   1.213 +	do {
   1.214 +		len = read_sockline(psb->in, &(psb->buffer[buf_pos]), SMTP_BUF_LEN - buf_pos, timeout, READSOCKL_CHUG);
   1.215 +		if (len == -3) {
   1.216 +			psb->error = smtp_timeout;
   1.217 +			return FALSE;
   1.218 +		} else if (len == -2) {
   1.219 +			psb->error = smtp_syntax;
   1.220 +			return FALSE;
   1.221 +		} else if (len == -1) {
   1.222 +			psb->error = smtp_eof;
   1.223 +			return FALSE;
   1.224 +		}
   1.225 +		for (i = 0; i < 4; i++)
   1.226 +			code[i] = psb->buffer[buf_pos + i];
   1.227 +		code[i] = 0;
   1.228 +		psb->last_code = atoi(code);
   1.229  
   1.230 -    buf_pos += len;
   1.231 +		buf_pos += len;
   1.232  
   1.233 -  }while(code[3] == '-');
   1.234 +	} while (code[3] == '-');
   1.235  
   1.236 -  return TRUE;
   1.237 +	return TRUE;
   1.238  }
   1.239  
   1.240 -static
   1.241 -gboolean check_response(smtp_base *psb, gboolean after_data)
   1.242 +static gboolean
   1.243 +check_response(smtp_base * psb, gboolean after_data)
   1.244  {
   1.245 -  char c = psb->buffer[0];
   1.246 +	char c = psb->buffer[0];
   1.247  
   1.248 -  if(((c == '2') && !after_data) || ((c == '3') && after_data)){
   1.249 -    psb->error = smtp_ok;
   1.250 -    DEBUG(6) debugf("response OK:'%s' after_date = %d\n", psb->buffer, (int)after_data);
   1.251 -    return TRUE;
   1.252 -  }else{
   1.253 -    if(c == '4')
   1.254 -      psb->error = smtp_trylater;
   1.255 -    else if(c == '5')
   1.256 -      psb->error = smtp_fail;
   1.257 -    else
   1.258 -      psb->error = smtp_syntax;
   1.259 -    DEBUG(6) debugf("response failure:'%s' after_date = %d\n", psb->buffer, (int)after_data);
   1.260 -    return FALSE;
   1.261 -  }
   1.262 +	if (((c == '2') && !after_data) || ((c == '3') && after_data)) {
   1.263 +		psb->error = smtp_ok;
   1.264 +		DEBUG(6) debugf("response OK:'%s' after_date = %d\n", psb->buffer, (int) after_data);
   1.265 +		return TRUE;
   1.266 +	} else {
   1.267 +		if (c == '4')
   1.268 +			psb->error = smtp_trylater;
   1.269 +		else if (c == '5')
   1.270 +			psb->error = smtp_fail;
   1.271 +		else
   1.272 +			psb->error = smtp_syntax;
   1.273 +		DEBUG(6) debugf("response failure:'%s' after_date = %d\n", psb->buffer, (int) after_data);
   1.274 +		return FALSE;
   1.275 +	}
   1.276  }
   1.277  
   1.278 -static
   1.279 -gboolean check_init_response(smtp_base *psb)
   1.280 +static gboolean
   1.281 +check_init_response(smtp_base * psb)
   1.282  {
   1.283 -  if(check_response(psb, FALSE)){
   1.284 -    psb->use_esmtp = (strstr(psb->buffer, "ESMTP") != NULL);
   1.285 +	if (check_response(psb, FALSE)) {
   1.286 +		psb->use_esmtp = (strstr(psb->buffer, "ESMTP") != NULL);
   1.287  
   1.288 -    DEBUG(4) debugf(psb->use_esmtp ? "uses esmtp\n" : "no esmtp\n");
   1.289 +		DEBUG(4) debugf(psb->use_esmtp ? "uses esmtp\n" : "no esmtp\n");
   1.290  
   1.291 -    return TRUE;
   1.292 -  }
   1.293 -  return FALSE;
   1.294 +		return TRUE;
   1.295 +	}
   1.296 +	return FALSE;
   1.297  }
   1.298  
   1.299 -static
   1.300 -gchar *get_response_arg(gchar *response)
   1.301 +static gchar*
   1.302 +get_response_arg(gchar * response)
   1.303  {
   1.304 -  gchar buf[SMTP_BUF_LEN];
   1.305 -  gchar *p = response, *q = buf;
   1.306 +	gchar buf[SMTP_BUF_LEN];
   1.307 +	gchar *p = response, *q = buf;
   1.308  
   1.309 -  while(*p && (*p != '\n') && isspace(*p)) p++;
   1.310 -  if(*p && (*p != '\n')){
   1.311 -    while(*p && (*p != '\n') && (*p != '\r') && (q < buf+SMTP_BUF_LEN-1)) *(q++) = *(p++);
   1.312 -    *q = 0;
   1.313 -    return g_strdup(buf);
   1.314 -  }
   1.315 -  return NULL;
   1.316 +	while (*p && (*p != '\n') && isspace(*p))
   1.317 +		p++;
   1.318 +	if (*p && (*p != '\n')) {
   1.319 +		while (*p && (*p != '\n') && (*p != '\r') && (q < buf + SMTP_BUF_LEN - 1))
   1.320 +			*(q++) = *(p++);
   1.321 +		*q = 0;
   1.322 +		return g_strdup(buf);
   1.323 +	}
   1.324 +	return NULL;
   1.325  }
   1.326  
   1.327 -static
   1.328 -gboolean check_helo_response(smtp_base *psb)
   1.329 +static gboolean
   1.330 +check_helo_response(smtp_base * psb)
   1.331  {
   1.332 -  gchar *ptr = psb->buffer;
   1.333 +	gchar *ptr = psb->buffer;
   1.334  
   1.335 -  if(!check_response(psb, FALSE))
   1.336 -    return FALSE;
   1.337 +	if (!check_response(psb, FALSE))
   1.338 +		return FALSE;
   1.339  
   1.340 -  while(*ptr){
   1.341 -    if(strncasecmp(&(ptr[4]), "SIZE", 4) == 0){
   1.342 -      gchar *arg;
   1.343 -      psb->use_size = TRUE;
   1.344 -      arg = get_response_arg(&(ptr[8]));
   1.345 -      if(arg){
   1.346 -	psb->max_size = atoi(arg);
   1.347 -	g_free(arg);
   1.348 -      }
   1.349 -    }
   1.350 +	while (*ptr) {
   1.351 +		if (strncasecmp(&(ptr[4]), "SIZE", 4) == 0) {
   1.352 +			gchar *arg;
   1.353 +			psb->use_size = TRUE;
   1.354 +			arg = get_response_arg(&(ptr[8]));
   1.355 +			if (arg) {
   1.356 +				psb->max_size = atoi(arg);
   1.357 +				g_free(arg);
   1.358 +			}
   1.359 +		}
   1.360  
   1.361 -    if(strncasecmp(&(ptr[4]), "PIPELINING", 10) == 0)
   1.362 -      psb->use_pipelining = TRUE;
   1.363 +		if (strncasecmp(&(ptr[4]), "PIPELINING", 10) == 0)
   1.364 +			psb->use_pipelining = TRUE;
   1.365  
   1.366 -    if(strncasecmp(&(ptr[4]), "AUTH", 4) == 0){
   1.367 -      if((ptr[8] == ' ') || (ptr[8] == '=') || (ptr[8] == '\t')){ /* not sure about '\t' */
   1.368 -	gchar *arg;
   1.369 -	psb->use_auth = TRUE;
   1.370 -	arg = get_response_arg(&(ptr[9])); /* after several years I finally learnt to count */
   1.371 -	if(arg){
   1.372 -	  psb->auth_names = g_strsplit(arg, " " , 0);
   1.373 -	  g_free(arg);
   1.374 -	  
   1.375 -	  DEBUG(4){
   1.376 -	    gint i = 0;
   1.377 -	    while(psb->auth_names[i]){
   1.378 -	      debugf("offered AUTH %s\n", psb->auth_names[i]);
   1.379 -	      i++;
   1.380 -	    }
   1.381 -	  }
   1.382 +		if (strncasecmp(&(ptr[4]), "AUTH", 4) == 0) {
   1.383 +			if ((ptr[8] == ' ') || (ptr[8] == '=') || (ptr[8] == '\t')) {  /* not sure about '\t' */
   1.384 +				gchar *arg;
   1.385 +				psb->use_auth = TRUE;
   1.386 +				arg = get_response_arg(&(ptr[9]));  /* after several years I finally learnt to count */
   1.387 +				if (arg) {
   1.388 +					psb->auth_names = g_strsplit(arg, " ", 0);
   1.389 +					g_free(arg);
   1.390 +
   1.391 +					DEBUG(4) {
   1.392 +						gint i = 0;
   1.393 +						while (psb->auth_names[i]) {
   1.394 +							debugf("offered AUTH %s\n", psb->auth_names[i]);
   1.395 +							i++;
   1.396 +						}
   1.397 +					}
   1.398 +				}
   1.399 +			}
   1.400 +		}
   1.401 +
   1.402 +		while (*ptr != '\n')
   1.403 +			ptr++;
   1.404 +		ptr++;
   1.405  	}
   1.406 -      }
   1.407 -    }
   1.408  
   1.409 -    while(*ptr != '\n') ptr++;
   1.410 -    ptr++;
   1.411 -  }
   1.412 +	DEBUG(4) {
   1.413 +		debugf(psb->use_size ? "uses SIZE\n" : "no size\n");
   1.414 +		debugf(psb->use_pipelining ? "uses PIPELINING\n" : "no pipelining\n");
   1.415 +		debugf(psb->use_auth ? "uses AUTH\n" : "no auth\n");
   1.416 +	}
   1.417  
   1.418 -  DEBUG(4){
   1.419 -    debugf(psb->use_size ? "uses SIZE\n" : "no size\n");
   1.420 -    debugf(psb->use_pipelining ? "uses PIPELINING\n" : "no pipelining\n");
   1.421 -    debugf(psb->use_auth ? "uses AUTH\n" : "no auth\n");
   1.422 -  }
   1.423 -
   1.424 -  return TRUE;
   1.425 +	return TRUE;
   1.426  }
   1.427  
   1.428 -static
   1.429 -gboolean smtp_helo(smtp_base *psb, gchar *helo)
   1.430 +static gboolean
   1.431 +smtp_helo(smtp_base * psb, gchar * helo)
   1.432  {
   1.433 -  while(TRUE){
   1.434 -    if(psb->use_esmtp){
   1.435 -      fprintf(psb->out, "EHLO %s\r\n", helo); fflush(psb->out);
   1.436 +	while (TRUE) {
   1.437 +		if (psb->use_esmtp) {
   1.438 +			fprintf(psb->out, "EHLO %s\r\n", helo);
   1.439 +			fflush(psb->out);
   1.440  
   1.441 -      DEBUG(4) debugf("EHLO %s\r\n", helo);
   1.442 +			DEBUG(4) debugf("EHLO %s\r\n", helo);
   1.443  
   1.444 -    }else{
   1.445 -      fprintf(psb->out, "HELO %s\r\n", helo); fflush(psb->out);
   1.446 +		} else {
   1.447 +			fprintf(psb->out, "HELO %s\r\n", helo);
   1.448 +			fflush(psb->out);
   1.449  
   1.450 -      DEBUG(4) debugf("HELO %s\r\n", helo);
   1.451 +			DEBUG(4) debugf("HELO %s\r\n", helo);
   1.452  
   1.453 -    }
   1.454 -    
   1.455 -    if(!read_response(psb, SMTP_CMD_TIMEOUT))
   1.456 -      return FALSE;
   1.457 +		}
   1.458  
   1.459 -    if(check_helo_response(psb))
   1.460 -      return TRUE;
   1.461 -    else{
   1.462 -      if(psb->error == smtp_fail){
   1.463 -	if(psb->use_esmtp){
   1.464 -	  /* our guess that server understands EHLO was wrong,
   1.465 -	     try again with HELO
   1.466 -	  */
   1.467 -	  psb->use_esmtp = FALSE;
   1.468 -	}else{
   1.469 -	  /* what sort of server ist THAT ?!
   1.470 -	     give up...
   1.471 -	  */
   1.472 -	  return FALSE;
   1.473 +		if (!read_response(psb, SMTP_CMD_TIMEOUT))
   1.474 +			return FALSE;
   1.475 +
   1.476 +		if (check_helo_response(psb))
   1.477 +			return TRUE;
   1.478 +		else {
   1.479 +			if (psb->error == smtp_fail) {
   1.480 +				if (psb->use_esmtp) {
   1.481 +					/* our guess that server understands EHLO was wrong, try again with HELO */
   1.482 +					psb->use_esmtp = FALSE;
   1.483 +				} else {
   1.484 +					/* what sort of server ist THAT ?!  give up...  */
   1.485 +					return FALSE;
   1.486 +				}
   1.487 +			} else
   1.488 +				return FALSE;
   1.489 +		}
   1.490  	}
   1.491 -      }else
   1.492 -	return FALSE;
   1.493 -    }
   1.494 -  }
   1.495  }
   1.496  
   1.497 -static
   1.498 -void smtp_cmd_mailfrom(smtp_base *psb, address *return_path, guint size)
   1.499 +static void
   1.500 +smtp_cmd_mailfrom(smtp_base * psb, address * return_path, guint size)
   1.501  {
   1.502 -  if(psb->use_size){
   1.503 -    fprintf(psb->out, "MAIL FROM:%s SIZE=%d\r\n",
   1.504 -	    addr_string(return_path), size);
   1.505 -    fflush(psb->out);
   1.506 +	if (psb->use_size) {
   1.507 +		fprintf(psb->out, "MAIL FROM:%s SIZE=%d\r\n", addr_string(return_path), size);
   1.508 +		fflush(psb->out);
   1.509  
   1.510 -    DEBUG(4) debugf("MAIL FROM:%s SIZE=%d\r\n",
   1.511 -		    addr_string(return_path), size);
   1.512 +		DEBUG(4) debugf("MAIL FROM:%s SIZE=%d\r\n", addr_string(return_path), size);
   1.513  
   1.514 -  }else{
   1.515 -    fprintf(psb->out, "MAIL FROM:%s\r\n", addr_string(return_path));
   1.516 -    fflush(psb->out);
   1.517 +	} else {
   1.518 +		fprintf(psb->out, "MAIL FROM:%s\r\n", addr_string(return_path));
   1.519 +		fflush(psb->out);
   1.520  
   1.521 -    DEBUG(4) debugf("MAIL FROM:%s\r\n", addr_string(return_path));
   1.522 -  }
   1.523 +		DEBUG(4) debugf("MAIL FROM:%s\r\n", addr_string(return_path));
   1.524 +	}
   1.525  }
   1.526  
   1.527 -static
   1.528 -void smtp_cmd_rcptto(smtp_base *psb, address *rcpt)
   1.529 +static void
   1.530 +smtp_cmd_rcptto(smtp_base * psb, address * rcpt)
   1.531  {
   1.532 -  fprintf(psb->out, "RCPT TO:%s\r\n", addr_string(rcpt));
   1.533 -  fflush(psb->out);
   1.534 -  DEBUG(4) debugf("RCPT TO:%s\n", addr_string(rcpt));
   1.535 +	fprintf(psb->out, "RCPT TO:%s\r\n", addr_string(rcpt));
   1.536 +	fflush(psb->out);
   1.537 +	DEBUG(4) debugf("RCPT TO:%s\n", addr_string(rcpt));
   1.538  }
   1.539  
   1.540 -static
   1.541 -void send_data_line(smtp_base *psb, gchar *data)
   1.542 +static void
   1.543 +send_data_line(smtp_base * psb, gchar * data)
   1.544  {
   1.545 -  /* According to RFC 821 each line should be terminated with CRLF.
   1.546 -     Since a dot on a line itself marks the end of data, each line
   1.547 -     beginning with a dot is prepended with another dot.
   1.548 -  */
   1.549 -  gchar *ptr;
   1.550 -  gboolean new_line = TRUE; /* previous versions assumed that each item was
   1.551 -			       exactly one line. This is no longer the case */
   1.552 +	/* According to RFC 821 each line should be terminated with CRLF.
   1.553 +	   Since a dot on a line itself marks the end of data, each line
   1.554 +	   beginning with a dot is prepended with another dot.
   1.555 +	 */
   1.556 +	gchar *ptr;
   1.557 +	gboolean new_line = TRUE;  /* previous versions assumed that each item was exactly one line. This is no longer the case */
   1.558  
   1.559 -  ptr = data;
   1.560 -  while(*ptr){
   1.561 -    int c = (int)(*ptr);
   1.562 -    if(c == '.')
   1.563 -      if(new_line)
   1.564 -	putc('.', psb->out);
   1.565 -    if(c == '\n'){
   1.566 -      putc('\r', psb->out);
   1.567 -      putc('\n', psb->out);
   1.568 -      new_line = TRUE;
   1.569 -    }else{
   1.570 -      putc(c, psb->out);
   1.571 -      new_line = FALSE;
   1.572 -    }
   1.573 -    ptr++;
   1.574 -  }
   1.575 +	ptr = data;
   1.576 +	while (*ptr) {
   1.577 +		int c = (int) (*ptr);
   1.578 +		if (c == '.')
   1.579 +			if (new_line)
   1.580 +				putc('.', psb->out);
   1.581 +		if (c == '\n') {
   1.582 +			putc('\r', psb->out);
   1.583 +			putc('\n', psb->out);
   1.584 +			new_line = TRUE;
   1.585 +		} else {
   1.586 +			putc(c, psb->out);
   1.587 +			new_line = FALSE;
   1.588 +		}
   1.589 +		ptr++;
   1.590 +	}
   1.591  }
   1.592  
   1.593 -static
   1.594 -void send_header(smtp_base *psb, GList *hdr_list)
   1.595 +static void
   1.596 +send_header(smtp_base * psb, GList * hdr_list)
   1.597  {
   1.598 -  GList *node;
   1.599 -  gint num_hdrs = 0;
   1.600 +	GList *node;
   1.601 +	gint num_hdrs = 0;
   1.602  
   1.603 -  /* header */
   1.604 -  if(hdr_list){
   1.605 -    foreach(hdr_list, node){
   1.606 -      if(node->data){
   1.607 -	header *hdr = (header *)(node->data);
   1.608 -	if(hdr->header){
   1.609 -	  send_data_line(psb, hdr->header);
   1.610 -	  num_hdrs++;
   1.611 +	/* header */
   1.612 +	if (hdr_list) {
   1.613 +		foreach(hdr_list, node) {
   1.614 +			if (node->data) {
   1.615 +				header *hdr = (header *) (node->data);
   1.616 +				if (hdr->header) {
   1.617 +					send_data_line(psb, hdr->header);
   1.618 +					num_hdrs++;
   1.619 +				}
   1.620 +			}
   1.621 +		}
   1.622  	}
   1.623 -      }
   1.624 -    }
   1.625 -  }
   1.626  
   1.627 -  /* empty line separating headers from data: */
   1.628 -  putc('\r', psb->out);
   1.629 -  putc('\n', psb->out);
   1.630 +	/* empty line separating headers from data: */
   1.631 +	putc('\r', psb->out);
   1.632 +	putc('\n', psb->out);
   1.633  
   1.634 -  DEBUG(4) debugf("sent %d headers\n", num_hdrs);
   1.635 +	DEBUG(4) debugf("sent %d headers\n", num_hdrs);
   1.636  }
   1.637  
   1.638 -static
   1.639 -void send_data(smtp_base *psb, message *msg)
   1.640 +static void
   1.641 +send_data(smtp_base * psb, message * msg)
   1.642  {
   1.643 -  GList *node;
   1.644 -  gint num_lines = 0;
   1.645 +	GList *node;
   1.646 +	gint num_lines = 0;
   1.647  
   1.648 -  /* data */
   1.649 -  if(msg->data_list){
   1.650 -    for(node = g_list_first(msg->data_list); node; node = g_list_next(node)){
   1.651 -      if(node->data){
   1.652 -	send_data_line(psb, node->data);
   1.653 -	num_lines++;
   1.654 -      }
   1.655 -    }
   1.656 -  }
   1.657 +	/* data */
   1.658 +	if (msg->data_list) {
   1.659 +		for (node = g_list_first(msg->data_list); node; node = g_list_next(node)) {
   1.660 +			if (node->data) {
   1.661 +				send_data_line(psb, node->data);
   1.662 +				num_lines++;
   1.663 +			}
   1.664 +		}
   1.665 +	}
   1.666  
   1.667 -  DEBUG(4) debugf("sent %d lines of data\n", num_lines);
   1.668 +	DEBUG(4) debugf("sent %d lines of data\n", num_lines);
   1.669  
   1.670 -  fprintf(psb->out, ".\r\n");
   1.671 -  fflush(psb->out);
   1.672 +	fprintf(psb->out, ".\r\n");
   1.673 +	fflush(psb->out);
   1.674  }
   1.675  
   1.676 -void smtp_out_mark_rcpts(smtp_base *psb, GList *rcpt_list)
   1.677 +void
   1.678 +smtp_out_mark_rcpts(smtp_base * psb, GList * rcpt_list)
   1.679  {
   1.680 -  GList *rcpt_node;
   1.681 -  for(rcpt_node = g_list_first(rcpt_list);
   1.682 -      rcpt_node;
   1.683 -      rcpt_node = g_list_next(rcpt_node)){
   1.684 -    address *rcpt = (address *)(rcpt_node->data);
   1.685 +	GList *rcpt_node;
   1.686 +	for (rcpt_node = g_list_first(rcpt_list); rcpt_node; rcpt_node = g_list_next(rcpt_node)) {
   1.687 +		address *rcpt = (address *) (rcpt_node->data);
   1.688  
   1.689 -    addr_unmark_delivered(rcpt);
   1.690 +		addr_unmark_delivered(rcpt);
   1.691  
   1.692 -    if((psb->error == smtp_trylater) || (psb->error == smtp_timeout) ||
   1.693 -       (psb->error == smtp_eof)){
   1.694 -      addr_mark_defered(rcpt);
   1.695 -    }else{
   1.696 -      addr_mark_failed(rcpt);
   1.697 -    }
   1.698 -  }
   1.699 +		if ((psb->error == smtp_trylater) || (psb->error == smtp_timeout) || (psb->error == smtp_eof)) {
   1.700 +			addr_mark_defered(rcpt);
   1.701 +		} else {
   1.702 +			addr_mark_failed(rcpt);
   1.703 +		}
   1.704 +	}
   1.705  }
   1.706  
   1.707 -void smtp_out_log_failure(smtp_base *psb, message *msg)
   1.708 +void
   1.709 +smtp_out_log_failure(smtp_base * psb, message * msg)
   1.710  {
   1.711 -  gchar *err_str;
   1.712 +	gchar *err_str;
   1.713  
   1.714 -  if(psb->error == smtp_timeout)
   1.715 -    err_str = g_strdup("connection timed out.");
   1.716 -  else if(psb->error == smtp_eof)
   1.717 -    err_str = g_strdup("connection terminated prematurely.");
   1.718 -  else if(psb->error == smtp_syntax)
   1.719 -    err_str = g_strdup_printf("got unexpected response: %s", psb->buffer);
   1.720 -  else if(psb->error == smtp_cancel)
   1.721 -    err_str = g_strdup("delivery was canceled.\n");
   1.722 -  else
   1.723 -    /* error message should still be in the buffer */
   1.724 -    err_str = g_strdup_printf("failed: %s\n", psb->buffer);
   1.725 +	if (psb->error == smtp_timeout)
   1.726 +		err_str = g_strdup("connection timed out.");
   1.727 +	else if (psb->error == smtp_eof)
   1.728 +		err_str = g_strdup("connection terminated prematurely.");
   1.729 +	else if (psb->error == smtp_syntax)
   1.730 +		err_str = g_strdup_printf("got unexpected response: %s", psb->buffer);
   1.731 +	else if (psb->error == smtp_cancel)
   1.732 +		err_str = g_strdup("delivery was canceled.\n");
   1.733 +	else
   1.734 +		/* error message should still be in the buffer */
   1.735 +		err_str = g_strdup_printf("failed: %s\n", psb->buffer);
   1.736  
   1.737 -  if(msg == NULL)
   1.738 -    logwrite(LOG_NOTICE, "host=%s %s\n",
   1.739 -	     psb->remote_host, err_str);
   1.740 -  else
   1.741 -    logwrite(LOG_NOTICE, "%s == host=%s %s\n",
   1.742 -	     msg->uid, psb->remote_host, err_str);
   1.743 +	if (msg == NULL)
   1.744 +		logwrite(LOG_NOTICE, "host=%s %s\n", psb->remote_host, err_str);
   1.745 +	else
   1.746 +		logwrite(LOG_NOTICE, "%s == host=%s %s\n", msg->uid, psb->remote_host, err_str);
   1.747  
   1.748 -  g_free(err_str);
   1.749 +	g_free(err_str);
   1.750  }
   1.751  
   1.752 -smtp_base *smtp_out_open(gchar *host, gint port, GList *resolve_list)
   1.753 +smtp_base*
   1.754 +smtp_out_open(gchar * host, gint port, GList * resolve_list)
   1.755  {
   1.756 -  smtp_base *psb;
   1.757 -  gint sock;
   1.758 -  mxip_addr *addr;
   1.759 +	smtp_base *psb;
   1.760 +	gint sock;
   1.761 +	mxip_addr *addr;
   1.762  
   1.763 -  DEBUG(5) debugf("smtp_out_open entered, host = %s\n", host);
   1.764 +	DEBUG(5) debugf("smtp_out_open entered, host = %s\n", host);
   1.765  
   1.766 -  if((addr = connect_resolvelist(&sock, host, port, resolve_list))){
   1.767 -    /* create structure to hold status data: */
   1.768 -    psb = create_smtpbase(sock);
   1.769 -    psb->remote_host = addr->name;
   1.770 +	if ((addr = connect_resolvelist(&sock, host, port, resolve_list))) {
   1.771 +		/* create structure to hold status data: */
   1.772 +		psb = create_smtpbase(sock);
   1.773 +		psb->remote_host = addr->name;
   1.774  
   1.775 -    DEBUG(5){
   1.776 -      struct sockaddr_in name;
   1.777 -      int len = sizeof(struct sockaddr);
   1.778 -      getsockname(sock, (struct sockaddr *)(&name), &len);
   1.779 -      debugf("socket: name.sin_addr = %s\n", inet_ntoa(name.sin_addr));
   1.780 -    }
   1.781 -    return psb;
   1.782 -  }else{
   1.783 -    DEBUG(5) debugf("connect_resolvelist failed: %s %s\n", strerror(errno), hstrerror(h_errno));
   1.784 -  }
   1.785 +		DEBUG(5) {
   1.786 +			struct sockaddr_in name;
   1.787 +			int len = sizeof(struct sockaddr);
   1.788 +			getsockname(sock, (struct sockaddr *) (&name), &len);
   1.789 +			debugf("socket: name.sin_addr = %s\n", inet_ntoa(name.sin_addr));
   1.790 +		}
   1.791 +		return psb;
   1.792 +	} else {
   1.793 +		DEBUG(5) debugf("connect_resolvelist failed: %s %s\n", strerror(errno), hstrerror(h_errno));
   1.794 +	}
   1.795  
   1.796 -  return NULL;
   1.797 +	return NULL;
   1.798  }
   1.799  
   1.800 -smtp_base *smtp_out_open_child(gchar *cmd)
   1.801 +smtp_base*
   1.802 +smtp_out_open_child(gchar * cmd)
   1.803  {
   1.804 -  smtp_base *psb;
   1.805 -  gint sock;
   1.806 +	smtp_base *psb;
   1.807 +	gint sock;
   1.808  
   1.809 -  DEBUG(5) debugf("smtp_out_open_child entered, cmd = %s\n", cmd);
   1.810 +	DEBUG(5) debugf("smtp_out_open_child entered, cmd = %s\n", cmd);
   1.811  
   1.812 -  sock = child(cmd);
   1.813 +	sock = child(cmd);
   1.814  
   1.815 -  if(sock > 0){
   1.816 -    psb = create_smtpbase(sock);
   1.817 -    psb->remote_host = NULL;
   1.818 +	if (sock > 0) {
   1.819 +		psb = create_smtpbase(sock);
   1.820 +		psb->remote_host = NULL;
   1.821  
   1.822 -    return psb;
   1.823 -  }
   1.824 +		return psb;
   1.825 +	}
   1.826  
   1.827 -  return NULL;
   1.828 +	return NULL;
   1.829  }
   1.830  
   1.831 -gboolean smtp_out_rset(smtp_base *psb)
   1.832 +gboolean
   1.833 +smtp_out_rset(smtp_base * psb)
   1.834  {
   1.835 -  gboolean ok;
   1.836 -  
   1.837 -  fprintf(psb->out, "RSET\r\n"); fflush(psb->out);
   1.838 -  DEBUG(4) debugf("RSET\n");
   1.839 +	gboolean ok;
   1.840  
   1.841 -  if((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
   1.842 -    if(check_response(psb, FALSE))
   1.843 -      return TRUE;
   1.844 +	fprintf(psb->out, "RSET\r\n");
   1.845 +	fflush(psb->out);
   1.846 +	DEBUG(4) debugf("RSET\n");
   1.847  
   1.848 -  smtp_out_log_failure(psb, NULL);
   1.849 +	if ((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
   1.850 +		if (check_response(psb, FALSE))
   1.851 +			return TRUE;
   1.852  
   1.853 -  return FALSE;
   1.854 +	smtp_out_log_failure(psb, NULL);
   1.855 +
   1.856 +	return FALSE;
   1.857  }
   1.858  
   1.859  #ifdef ENABLE_AUTH
   1.860  
   1.861 -static
   1.862 -gboolean smtp_out_auth_cram_md5(smtp_base *psb)
   1.863 +static gboolean
   1.864 +smtp_out_auth_cram_md5(smtp_base * psb)
   1.865  {
   1.866 -  gboolean ok = FALSE;
   1.867 +	gboolean ok = FALSE;
   1.868  
   1.869 -  fprintf(psb->out, "AUTH CRAM-MD5\r\n"); fflush(psb->out);
   1.870 -  DEBUG(4) debugf("AUTH CRAM-MD5\n");
   1.871 -  if((ok = read_response(psb, SMTP_CMD_TIMEOUT))){
   1.872 -    if((ok = check_response(psb, TRUE))){
   1.873 -      gchar *chall64 = get_response_arg(&(psb->buffer[4]));
   1.874 -      gint chall_size;
   1.875 -      gchar *chall = base64_decode(chall64, &chall_size);
   1.876 -      guchar digest[16], *reply64, *reply;
   1.877 -      gchar digest_string[33];
   1.878 -      gint i;
   1.879 +	fprintf(psb->out, "AUTH CRAM-MD5\r\n");
   1.880 +	fflush(psb->out);
   1.881 +	DEBUG(4) debugf("AUTH CRAM-MD5\n");
   1.882 +	if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
   1.883 +		if ((ok = check_response(psb, TRUE))) {
   1.884 +			gchar *chall64 = get_response_arg(&(psb->buffer[4]));
   1.885 +			gint chall_size;
   1.886 +			gchar *chall = base64_decode(chall64, &chall_size);
   1.887 +			guchar digest[16], *reply64, *reply;
   1.888 +			gchar digest_string[33];
   1.889 +			gint i;
   1.890  #ifdef USE_LIB_CRYPTO
   1.891 -      unsigned int digest_len;
   1.892 +			unsigned int digest_len;
   1.893  #endif
   1.894 -      
   1.895 -      DEBUG(5) debugf("encoded challenge = %s\n", chall64);
   1.896 -      DEBUG(5) debugf("decoded challenge = %s, size = %d\n", chall, chall_size);
   1.897 -      
   1.898 -      DEBUG(5) debugf("secret = %s\n", psb->auth_secret);
   1.899 -      
   1.900 +
   1.901 +			DEBUG(5) debugf("encoded challenge = %s\n", chall64);
   1.902 +			DEBUG(5) debugf("decoded challenge = %s, size = %d\n", chall, chall_size);
   1.903 +
   1.904 +			DEBUG(5) debugf("secret = %s\n", psb->auth_secret);
   1.905 +
   1.906  #ifdef USE_LIB_CRYPTO
   1.907 -      HMAC(EVP_md5(), psb->auth_secret, strlen(psb->auth_secret), chall, chall_size, digest, &digest_len);
   1.908 +			HMAC(EVP_md5(), psb->auth_secret, strlen(psb->auth_secret), chall, chall_size, digest, &digest_len);
   1.909  #else
   1.910 -      hmac_md5(chall, chall_size, psb->auth_secret, strlen(psb->auth_secret), digest);
   1.911 +			hmac_md5(chall, chall_size, psb->auth_secret, strlen(psb->auth_secret), digest);
   1.912  #endif
   1.913 -      
   1.914 -      for(i = 0; i < 16; i++)
   1.915 -	sprintf(&(digest_string[i+i]), "%02x", (unsigned int)(digest[i]));
   1.916 -      digest_string[32] = 0;
   1.917 -      
   1.918 -      DEBUG(5) debugf("digest = %s\n", digest_string);
   1.919 -      
   1.920 -      reply = g_strdup_printf("%s %s", psb->auth_login, digest_string);
   1.921 -      DEBUG(5) debugf("unencoded reply = %s\n", reply);
   1.922 -      
   1.923 -      reply64 = base64_encode(reply, strlen(reply));
   1.924 -      DEBUG(5) debugf("encoded reply = %s\n", reply64);
   1.925 -          
   1.926 -      fprintf(psb->out, "%s\r\n", reply64); fflush(psb->out);
   1.927 -      DEBUG(4) debugf("%s\n", reply64);
   1.928 -          
   1.929 -      if((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
   1.930 -	ok = check_response(psb, FALSE);
   1.931 -          
   1.932 -      g_free(reply64);
   1.933 -      g_free(reply);
   1.934 -      g_free(chall);
   1.935 -      g_free(chall64);
   1.936 -    }
   1.937 -  }
   1.938 -  return ok;
   1.939 +
   1.940 +			for (i = 0; i < 16; i++)
   1.941 +				sprintf(&(digest_string[i + i]), "%02x", (unsigned int) (digest[i]));
   1.942 +			digest_string[32] = 0;
   1.943 +
   1.944 +			DEBUG(5) debugf("digest = %s\n", digest_string);
   1.945 +
   1.946 +			reply = g_strdup_printf("%s %s", psb->auth_login, digest_string);
   1.947 +			DEBUG(5) debugf("unencoded reply = %s\n", reply);
   1.948 +
   1.949 +			reply64 = base64_encode(reply, strlen(reply));
   1.950 +			DEBUG(5) debugf("encoded reply = %s\n", reply64);
   1.951 +
   1.952 +			fprintf(psb->out, "%s\r\n", reply64);
   1.953 +			fflush(psb->out);
   1.954 +			DEBUG(4) debugf("%s\n", reply64);
   1.955 +
   1.956 +			if ((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
   1.957 +				ok = check_response(psb, FALSE);
   1.958 +
   1.959 +			g_free(reply64);
   1.960 +			g_free(reply);
   1.961 +			g_free(chall);
   1.962 +			g_free(chall64);
   1.963 +		}
   1.964 +	}
   1.965 +	return ok;
   1.966  }
   1.967  
   1.968 -static
   1.969 -gboolean smtp_out_auth_login(smtp_base *psb)
   1.970 +static gboolean
   1.971 +smtp_out_auth_login(smtp_base * psb)
   1.972  {
   1.973 -  gboolean ok = FALSE;
   1.974 -  fprintf(psb->out, "AUTH LOGIN\r\n"); fflush(psb->out);
   1.975 -  if((ok = read_response(psb, SMTP_CMD_TIMEOUT))){
   1.976 -    if((ok = check_response(psb, TRUE))){
   1.977 -      gchar *resp64;
   1.978 -      guchar *resp;
   1.979 -      gint resp_size;
   1.980 -      gchar *reply64;
   1.981 -      
   1.982 -      resp64 = get_response_arg(&(psb->buffer[4]));
   1.983 -      DEBUG(5) debugf("encoded response = %s\n", resp64);
   1.984 -      resp = base64_decode(resp64, &resp_size);
   1.985 -      g_free(resp64);
   1.986 -      DEBUG(5) debugf("decoded response = %s, size = %d\n", 
   1.987 -                                        resp, resp_size);
   1.988 -      g_free(resp);
   1.989 -      reply64 = base64_encode(psb->auth_login,
   1.990 -			      strlen(psb->auth_login));
   1.991 -      fprintf(psb->out, "%s\r\n", reply64); fflush(psb->out);
   1.992 -      g_free(reply64);
   1.993 -      if((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
   1.994 -	if ((ok = check_response(psb, TRUE))) {
   1.995 -	  resp64 = get_response_arg(&(psb->buffer[4]));
   1.996 -	  DEBUG(5) debugf("encoded response = %s\n", resp64);
   1.997 -	  resp = base64_decode(resp64, &resp_size);
   1.998 -	  g_free(resp64);
   1.999 -	  DEBUG(5) debugf("decoded response = %s, size = %d\n", 
  1.1000 -			  resp, resp_size);
  1.1001 -	  g_free(resp);
  1.1002 -	  reply64 = base64_encode(psb->auth_secret,
  1.1003 -				  strlen(psb->auth_secret));
  1.1004 -	  fprintf(psb->out, "%s\r\n", reply64); fflush(psb->out);
  1.1005 -	  g_free(reply64);
  1.1006 -	  if((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
  1.1007 -	    ok = check_response(psb, FALSE);
  1.1008 +	gboolean ok = FALSE;
  1.1009 +	fprintf(psb->out, "AUTH LOGIN\r\n");
  1.1010 +	fflush(psb->out);
  1.1011 +	if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
  1.1012 +		if ((ok = check_response(psb, TRUE))) {
  1.1013 +			gchar *resp64;
  1.1014 +			guchar *resp;
  1.1015 +			gint resp_size;
  1.1016 +			gchar *reply64;
  1.1017 +
  1.1018 +			resp64 = get_response_arg(&(psb->buffer[4]));
  1.1019 +			DEBUG(5) debugf("encoded response = %s\n", resp64);
  1.1020 +			resp = base64_decode(resp64, &resp_size);
  1.1021 +			g_free(resp64);
  1.1022 +			DEBUG(5) debugf("decoded response = %s, size = %d\n", resp, resp_size);
  1.1023 +			g_free(resp);
  1.1024 +			reply64 = base64_encode(psb->auth_login, strlen(psb->auth_login));
  1.1025 +			fprintf(psb->out, "%s\r\n", reply64);
  1.1026 +			fflush(psb->out);
  1.1027 +			g_free(reply64);
  1.1028 +			if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
  1.1029 +				if ((ok = check_response(psb, TRUE))) {
  1.1030 +					resp64 = get_response_arg(&(psb->buffer[4]));
  1.1031 +					DEBUG(5) debugf("encoded response = %s\n", resp64);
  1.1032 +					resp = base64_decode(resp64, &resp_size);
  1.1033 +					g_free(resp64);
  1.1034 +					DEBUG(5) debugf("decoded response = %s, size = %d\n", resp, resp_size);
  1.1035 +					g_free(resp);
  1.1036 +					reply64 = base64_encode(psb->auth_secret, strlen(psb->auth_secret));
  1.1037 +					fprintf(psb->out, "%s\r\n", reply64);
  1.1038 +					fflush(psb->out);
  1.1039 +					g_free(reply64);
  1.1040 +					if ((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
  1.1041 +						ok = check_response(psb, FALSE);
  1.1042 +				}
  1.1043 +			}
  1.1044 +		}
  1.1045  	}
  1.1046 -      }          
  1.1047 -    }
  1.1048 -  }
  1.1049 -  return ok;
  1.1050 +	return ok;
  1.1051  }
  1.1052  
  1.1053 -gboolean smtp_out_auth(smtp_base *psb)
  1.1054 +gboolean
  1.1055 +smtp_out_auth(smtp_base * psb)
  1.1056  {
  1.1057 -  gboolean ok = FALSE;
  1.1058 -  gint i = 0;
  1.1059 -  while(psb->auth_names[i]){
  1.1060 -    if(strcasecmp(psb->auth_names[i], psb->auth_name) == 0)
  1.1061 -      break;
  1.1062 -    i++;
  1.1063 -  }
  1.1064 -  if(psb->auth_names[i]){
  1.1065 -    if(strcasecmp(psb->auth_name, "cram-md5") == 0){
  1.1066 -      smtp_out_auth_cram_md5(psb);
  1.1067 -    }else if(strcasecmp(psb->auth_name, "login") == 0){
  1.1068 -      smtp_out_auth_login(psb);
  1.1069 -    }else{
  1.1070 -      logwrite(LOG_ERR, "auth method %s not supported\n",  psb->auth_name);
  1.1071 -    }
  1.1072 -  }else{
  1.1073 -    logwrite(LOG_ERR, "no auth method %s found.\n", psb->auth_name);
  1.1074 -  }
  1.1075 -  return ok;
  1.1076 +	gboolean ok = FALSE;
  1.1077 +	gint i = 0;
  1.1078 +	while (psb->auth_names[i]) {
  1.1079 +		if (strcasecmp(psb->auth_names[i], psb->auth_name) == 0)
  1.1080 +			break;
  1.1081 +		i++;
  1.1082 +	}
  1.1083 +	if (psb->auth_names[i]) {
  1.1084 +		if (strcasecmp(psb->auth_name, "cram-md5") == 0) {
  1.1085 +			smtp_out_auth_cram_md5(psb);
  1.1086 +		} else if (strcasecmp(psb->auth_name, "login") == 0) {
  1.1087 +			smtp_out_auth_login(psb);
  1.1088 +		} else {
  1.1089 +			logwrite(LOG_ERR, "auth method %s not supported\n", psb->auth_name);
  1.1090 +		}
  1.1091 +	} else {
  1.1092 +		logwrite(LOG_ERR, "no auth method %s found.\n", psb->auth_name);
  1.1093 +	}
  1.1094 +	return ok;
  1.1095  }
  1.1096  
  1.1097  #endif
  1.1098  
  1.1099 -gboolean smtp_out_init(smtp_base *psb)
  1.1100 +gboolean
  1.1101 +smtp_out_init(smtp_base * psb)
  1.1102  {
  1.1103 -  gboolean ok;
  1.1104 +	gboolean ok;
  1.1105  
  1.1106 -  if((ok = read_response(psb, SMTP_INITIAL_TIMEOUT))){
  1.1107 -    if((ok = check_init_response(psb))){
  1.1108 - 
  1.1109 -      if((ok = smtp_helo(psb, psb->helo_name))){
  1.1110 +	if ((ok = read_response(psb, SMTP_INITIAL_TIMEOUT))) {
  1.1111 +		if ((ok = check_init_response(psb))) {
  1.1112 +
  1.1113 +			if ((ok = smtp_helo(psb, psb->helo_name))) {
  1.1114  #ifdef ENABLE_AUTH
  1.1115 -	if(psb->auth_name && psb->use_auth){
  1.1116 -	  /* we completely disregard the response of server here. If
  1.1117 -             authentication fails, the server will complain later
  1.1118 -             anyway. I know, this is not polite... */
  1.1119 -	  smtp_out_auth(psb);
  1.1120 +				if (psb->auth_name && psb->use_auth) {
  1.1121 +					/* we completely disregard the response of server here. If
  1.1122 +					   authentication fails, the server will complain later
  1.1123 +					   anyway. I know, this is not polite... */
  1.1124 +					smtp_out_auth(psb);
  1.1125 +				}
  1.1126 +#endif
  1.1127 +			}
  1.1128 +		}
  1.1129  	}
  1.1130 -#endif
  1.1131 -      }
  1.1132 -    }
  1.1133 -  }
  1.1134 -  if(!ok)
  1.1135 -    smtp_out_log_failure(psb, NULL);
  1.1136 -  return ok;
  1.1137 +	if (!ok)
  1.1138 +		smtp_out_log_failure(psb, NULL);
  1.1139 +	return ok;
  1.1140  }
  1.1141  
  1.1142 -gint smtp_out_msg(smtp_base *psb,
  1.1143 -		  message *msg, address *return_path, GList *rcpt_list,
  1.1144 -		  GList *hdr_list)
  1.1145 +gint
  1.1146 +smtp_out_msg(smtp_base * psb, message * msg, address * return_path, GList * rcpt_list, GList * hdr_list)
  1.1147  {
  1.1148 -  gint i, size;
  1.1149 -  gboolean ok = TRUE;
  1.1150 -  int rcpt_cnt;
  1.1151 -  int rcpt_accept = 0;
  1.1152 +	gint i, size;
  1.1153 +	gboolean ok = TRUE;
  1.1154 +	int rcpt_cnt;
  1.1155 +	int rcpt_accept = 0;
  1.1156  
  1.1157 -  DEBUG(5) debugf("smtp_out_msg entered\n");
  1.1158 +	DEBUG(5) debugf("smtp_out_msg entered\n");
  1.1159  
  1.1160 -  /* defaults: */
  1.1161 -  if(return_path == NULL)
  1.1162 -    return_path = msg->return_path;
  1.1163 -  if(hdr_list == NULL)
  1.1164 -    hdr_list = msg->hdr_list;
  1.1165 -  if(rcpt_list == NULL)
  1.1166 -    rcpt_list = msg->rcpt_list;
  1.1167 -  rcpt_cnt = g_list_length(rcpt_list);
  1.1168 +	/* defaults: */
  1.1169 +	if (return_path == NULL)
  1.1170 +		return_path = msg->return_path;
  1.1171 +	if (hdr_list == NULL)
  1.1172 +		hdr_list = msg->hdr_list;
  1.1173 +	if (rcpt_list == NULL)
  1.1174 +		rcpt_list = msg->rcpt_list;
  1.1175 +	rcpt_cnt = g_list_length(rcpt_list);
  1.1176  
  1.1177 -  size = msg_calc_size(msg, TRUE);
  1.1178 +	size = msg_calc_size(msg, TRUE);
  1.1179  
  1.1180 -  /* respect maximum size given by server: */
  1.1181 -  if((psb->max_size > 0) && (size > psb->max_size)){
  1.1182 -    logwrite(LOG_WARNING,
  1.1183 -	     "%s == host=%s message size (%d) > fixed maximum message size of server (%d)",
  1.1184 -	     msg->uid, psb->remote_host, size, psb->max_size);
  1.1185 -    psb->error = smtp_cancel;
  1.1186 -    ok = FALSE;
  1.1187 -  }
  1.1188 +	/* respect maximum size given by server: */
  1.1189 +	if ((psb->max_size > 0) && (size > psb->max_size)) {
  1.1190 +		logwrite(LOG_WARNING, "%s == host=%s message size (%d) > fixed maximum message size of server (%d)",
  1.1191 +		         msg->uid, psb->remote_host, size, psb->max_size);
  1.1192 +		psb->error = smtp_cancel;
  1.1193 +		ok = FALSE;
  1.1194 +	}
  1.1195  
  1.1196 -  if(ok){
  1.1197 -    smtp_cmd_mailfrom(psb, return_path,
  1.1198 -		      psb->use_size ? 
  1.1199 -		      size + SMTP_SIZE_ADD : 0);
  1.1200 -    
  1.1201 -    if(!psb->use_pipelining){
  1.1202 -      if((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
  1.1203 -	ok = check_response(psb, FALSE);
  1.1204 -    }
  1.1205 -  }
  1.1206 -  if(ok){
  1.1207 -    GList *rcpt_node;
  1.1208 -    rcpt_accept = 0;
  1.1209 +	if (ok) {
  1.1210 +		smtp_cmd_mailfrom(psb, return_path, psb->use_size ? size + SMTP_SIZE_ADD : 0);
  1.1211  
  1.1212 -    for(rcpt_node = g_list_first(rcpt_list);
  1.1213 -	rcpt_node != NULL;
  1.1214 -	rcpt_node = g_list_next(rcpt_node)){
  1.1215 -      address *rcpt = (address *)(rcpt_node->data);
  1.1216 -      smtp_cmd_rcptto(psb, rcpt);
  1.1217 -      if(!psb->use_pipelining){
  1.1218 -	if((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
  1.1219 -	  if(check_response(psb, FALSE)){
  1.1220 -	    rcpt_accept++;
  1.1221 -	    addr_mark_delivered(rcpt);
  1.1222 -	  }
  1.1223 -	  else{
  1.1224 -	    /* if server returned an error for one recp. we
  1.1225 -	       may still try the others. But if it is a timeout, eof
  1.1226 -	       or unexpected response, it is more serious and we should
  1.1227 -	       give up. */
  1.1228 -	    if((psb->error != smtp_trylater) &&
  1.1229 -	       (psb->error != smtp_fail)){
  1.1230 -	      ok = FALSE;
  1.1231 -	      break;
  1.1232 -	    }else{
  1.1233 -	      logwrite(LOG_NOTICE, "%s == %s host=%s failed: %s",
  1.1234 -		       msg->uid, addr_string(rcpt),
  1.1235 -		       psb->remote_host, psb->buffer);
  1.1236 -	      if(psb->error == smtp_trylater){
  1.1237 -		addr_mark_defered(rcpt);
  1.1238 -	      }else{
  1.1239 -		addr_mark_failed(rcpt);
  1.1240 -	      }
  1.1241 -	    }
  1.1242 -	  }
  1.1243 -	else
  1.1244 -	  break;
  1.1245 -      }
  1.1246 -    }
  1.1247 +		if (!psb->use_pipelining) {
  1.1248 +			if ((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
  1.1249 +				ok = check_response(psb, FALSE);
  1.1250 +		}
  1.1251 +	}
  1.1252 +	if (ok) {
  1.1253 +		GList *rcpt_node;
  1.1254 +		rcpt_accept = 0;
  1.1255  
  1.1256 -    /* There is no point in going on if no recp.s were accpted.
  1.1257 -       But we can check that at this point only if not pipelining: */
  1.1258 -    ok = (ok && (psb->use_pipelining || (rcpt_accept > 0)));
  1.1259 -    if(ok){
  1.1260 +		for (rcpt_node = g_list_first(rcpt_list); rcpt_node != NULL; rcpt_node = g_list_next(rcpt_node)) {
  1.1261 +			address *rcpt = (address *) (rcpt_node->data);
  1.1262 +			smtp_cmd_rcptto(psb, rcpt);
  1.1263 +			if (!psb->use_pipelining) {
  1.1264 +				if ((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
  1.1265 +					if (check_response(psb, FALSE)) {
  1.1266 +						rcpt_accept++;
  1.1267 +						addr_mark_delivered(rcpt);
  1.1268 +					} else {
  1.1269 +						/* if server returned an error for one recp. we
  1.1270 +						   may still try the others. But if it is a timeout, eof
  1.1271 +						   or unexpected response, it is more serious and we should
  1.1272 +						   give up. */
  1.1273 +						if ((psb->error != smtp_trylater) && (psb->error != smtp_fail)) {
  1.1274 +							ok = FALSE;
  1.1275 +							break;
  1.1276 +						} else {
  1.1277 +							logwrite(LOG_NOTICE, "%s == %s host=%s failed: %s", msg->uid, addr_string(rcpt), psb->remote_host, psb->buffer);
  1.1278 +							if (psb->error == smtp_trylater) {
  1.1279 +								addr_mark_defered(rcpt);
  1.1280 +							} else {
  1.1281 +								addr_mark_failed(rcpt);
  1.1282 +							}
  1.1283 +						}
  1.1284 +				} else
  1.1285 +					break;
  1.1286 +			}
  1.1287 +		}
  1.1288  
  1.1289 -      fprintf(psb->out, "DATA\r\n"); fflush(psb->out);
  1.1290 +		/* There is no point in going on if no recp.s were accpted.
  1.1291 +		   But we can check that at this point only if not pipelining: */
  1.1292 +		ok = (ok && (psb->use_pipelining || (rcpt_accept > 0)));
  1.1293 +		if (ok) {
  1.1294  
  1.1295 -      DEBUG(4) debugf("DATA\r\n");
  1.1296 -	
  1.1297 -      if(psb->use_pipelining){
  1.1298 -	/* the first pl'ed command was MAIL FROM
  1.1299 -	   the last was DATA, whose response can be handled by the 'normal' code
  1.1300 -	   all in between were RCPT TO:
  1.1301 -	*/
  1.1302 -	/* response to MAIL FROM: */
  1.1303 -	if((ok = read_response(psb, SMTP_CMD_TIMEOUT))){
  1.1304 -	  if((ok = check_response(psb, FALSE))){
  1.1305 +			fprintf(psb->out, "DATA\r\n");
  1.1306 +			fflush(psb->out);
  1.1307  
  1.1308 -	    /* response(s) to RCPT TO:
  1.1309 -	       this is very similar to the sequence above for no pipeline
  1.1310 -	    */
  1.1311 -	    for(i = 0; i < rcpt_cnt; i++){
  1.1312 -	      if((ok = read_response(psb, SMTP_CMD_TIMEOUT))){
  1.1313 -		address *rcpt = g_list_nth_data(rcpt_list, i);
  1.1314 -		if(check_response(psb, FALSE)){
  1.1315 -		  rcpt_accept++;
  1.1316 -		  addr_mark_delivered(rcpt);
  1.1317 +			DEBUG(4) debugf("DATA\r\n");
  1.1318 +
  1.1319 +			if (psb->use_pipelining) {
  1.1320 +				/* the first pl'ed command was MAIL FROM
  1.1321 +				   the last was DATA, whose response can be handled by the 'normal' code
  1.1322 +				   all in between were RCPT TO:
  1.1323 +				 */
  1.1324 +				/* response to MAIL FROM: */
  1.1325 +				if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
  1.1326 +					if ((ok = check_response(psb, FALSE))) {
  1.1327 +
  1.1328 +						/* response(s) to RCPT TO:
  1.1329 +						   this is very similar to the sequence above for no pipeline
  1.1330 +						 */
  1.1331 +						for (i = 0; i < rcpt_cnt; i++) {
  1.1332 +							if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
  1.1333 +								address *rcpt = g_list_nth_data(rcpt_list, i);
  1.1334 +								if (check_response(psb, FALSE)) {
  1.1335 +									rcpt_accept++;
  1.1336 +									addr_mark_delivered(rcpt);
  1.1337 +								} else {
  1.1338 +									/* if server returned an error 4xx or 5xx for one recp. we
  1.1339 +									   may still try the others. But if it is a timeout, eof
  1.1340 +									   or unexpected response, it is more serious and we
  1.1341 +									   should give up. */
  1.1342 +									if ((psb->error != smtp_trylater) &&
  1.1343 +										(psb->error != smtp_fail)) {
  1.1344 +										ok = FALSE;
  1.1345 +										break;
  1.1346 +									} else {
  1.1347 +										logwrite(LOG_NOTICE, "%s == %s host=%s failed: %s", msg->uid,
  1.1348 +										         addr_string(rcpt), psb->remote_host, psb->buffer);
  1.1349 +										if (psb->error == smtp_trylater) {
  1.1350 +											addr_mark_defered(rcpt);
  1.1351 +										} else {
  1.1352 +											addr_mark_failed(rcpt);
  1.1353 +										}
  1.1354 +									}
  1.1355 +								}
  1.1356 +							} else {
  1.1357 +								DEBUG(5) debugf("check_response failed after RCPT TO\n");
  1.1358 +								break;
  1.1359 +							}
  1.1360 +						}
  1.1361 +						if (rcpt_accept == 0)
  1.1362 +							ok = FALSE;
  1.1363 +					} else {
  1.1364 +						DEBUG(5) debugf("check_response failed after MAIL FROM\n");
  1.1365 +					}
  1.1366 +				} else {
  1.1367 +					DEBUG(5)
  1.1368 +						debugf("read_response failed after MAIL FROM\n");
  1.1369 +				}
  1.1370 +			}
  1.1371 +
  1.1372 +			/* if(psb->use_pipelining) */
  1.1373 +			/* response to the DATA cmd */
  1.1374 +			if (ok) {
  1.1375 +				if (read_response(psb, SMTP_DATA_TIMEOUT)) {
  1.1376 +					if (check_response(psb, TRUE)) {
  1.1377 +						send_header(psb, hdr_list);
  1.1378 +						send_data(psb, msg);
  1.1379 +
  1.1380 +						if (read_response(psb, SMTP_FINAL_TIMEOUT))
  1.1381 +							ok = check_response(psb, FALSE);
  1.1382 +					}
  1.1383 +				}
  1.1384 +			}
  1.1385  		}
  1.1386 -		else{
  1.1387 -		  /* if server returned an error 4xx or 5xx for one recp. we
  1.1388 -		     may still try the others. But if it is a timeout, eof
  1.1389 -		     or unexpected response, it is more serious and we
  1.1390 -		     should give up. */
  1.1391 -		  if((psb->error != smtp_trylater) &&
  1.1392 -		     (psb->error != smtp_fail)){
  1.1393 -		    ok = FALSE;
  1.1394 -		    break;
  1.1395 -		  }else{
  1.1396 -		    logwrite(LOG_NOTICE, "%s == %s host=%s failed: %s",
  1.1397 -			     msg->uid, addr_string(rcpt),
  1.1398 -			     psb->remote_host, psb->buffer);
  1.1399 -		    if(psb->error == smtp_trylater){
  1.1400 -		      addr_mark_defered(rcpt);
  1.1401 -		    }else{
  1.1402 -		      addr_mark_failed(rcpt);
  1.1403 -		    }
  1.1404 -		  }
  1.1405 +	}
  1.1406 +
  1.1407 +	DEBUG(5) {
  1.1408 +		debugf("psb->error = %d\n", psb->error);
  1.1409 +		debugf("ok = %d\n", ok);
  1.1410 +		debugf("rcpt_accept = %d\n", rcpt_accept);
  1.1411 +	}
  1.1412 +
  1.1413 +	if (psb->error == smtp_ok) {
  1.1414 +		GList *rcpt_node;
  1.1415 +		for (rcpt_node = g_list_first(rcpt_list); rcpt_node; rcpt_node = g_list_next(rcpt_node)) {
  1.1416 +			address *rcpt = (address *) (rcpt_node->data);
  1.1417 +			if (addr_is_delivered(rcpt))
  1.1418 +				logwrite(LOG_NOTICE, "%s => %s host=%s with %s\n", msg->uid, addr_string(rcpt),
  1.1419 +				         psb->remote_host, psb->use_esmtp ? "esmtp" : "smtp");
  1.1420  		}
  1.1421 -	      }else{
  1.1422 -		DEBUG(5) debugf("check_response failed after RCPT TO\n");
  1.1423 -		break;
  1.1424 -	      }
  1.1425 -	    }
  1.1426 -	    if(rcpt_accept == 0)
  1.1427 -	      ok = FALSE;
  1.1428 -	  }else{
  1.1429 -	    DEBUG(5) debugf("check_response failed after MAIL FROM\n");
  1.1430 -	  }
  1.1431 -	}else{
  1.1432 -	  DEBUG(5) debugf("read_response failed after MAIL FROM\n");
  1.1433 +	} else {
  1.1434 +		/* if something went wrong,
  1.1435 +		   we have to unmark the rcpts prematurely marked as delivered
  1.1436 +		   and mark the status */
  1.1437 +		smtp_out_mark_rcpts(psb, rcpt_list);
  1.1438 +
  1.1439 +		/* log the failure: */
  1.1440 +		smtp_out_log_failure(psb, msg);
  1.1441  	}
  1.1442 -      } /* if(psb->use_pipelining) */
  1.1443 -
  1.1444 -      /* response to the DATA cmd */
  1.1445 -      if(ok){
  1.1446 -	if(read_response(psb, SMTP_DATA_TIMEOUT)){
  1.1447 -	  if(check_response(psb, TRUE)){
  1.1448 -	    send_header(psb, hdr_list);
  1.1449 -	    send_data(psb, msg);
  1.1450 -	      
  1.1451 -	    if(read_response(psb, SMTP_FINAL_TIMEOUT))
  1.1452 -	      ok = check_response(psb, FALSE);
  1.1453 -	  }
  1.1454 -	}
  1.1455 -      }
  1.1456 -    }
  1.1457 -  }
  1.1458 -
  1.1459 -  DEBUG(5){
  1.1460 -    debugf("psb->error = %d\n", psb->error);
  1.1461 -    debugf("ok = %d\n", ok);
  1.1462 -    debugf("rcpt_accept = %d\n", rcpt_accept);
  1.1463 -  }
  1.1464 -
  1.1465 -  if(psb->error == smtp_ok){
  1.1466 -    GList *rcpt_node;
  1.1467 -    for(rcpt_node = g_list_first(rcpt_list);
  1.1468 -	rcpt_node;
  1.1469 -	rcpt_node = g_list_next(rcpt_node)){
  1.1470 -      address *rcpt = (address *)(rcpt_node->data);
  1.1471 -      if(addr_is_delivered(rcpt))
  1.1472 -	logwrite(LOG_NOTICE, "%s => %s host=%s with %s\n",
  1.1473 -		 msg->uid, addr_string(rcpt), psb->remote_host,
  1.1474 -		 psb->use_esmtp ? "esmtp" : "smtp");
  1.1475 -    }
  1.1476 -  }else{
  1.1477 -    /* if something went wrong,
  1.1478 -       we have to unmark the rcpts prematurely marked as delivered
  1.1479 -       and mark the status */
  1.1480 -    smtp_out_mark_rcpts(psb, rcpt_list);
  1.1481 -
  1.1482 -    /* log the failure: */
  1.1483 -    smtp_out_log_failure(psb, msg);
  1.1484 -  }
  1.1485 -  return rcpt_accept;
  1.1486 +	return rcpt_accept;
  1.1487  }
  1.1488  
  1.1489 -gboolean smtp_out_quit(smtp_base *psb)
  1.1490 +gboolean
  1.1491 +smtp_out_quit(smtp_base * psb)
  1.1492  {
  1.1493 -  fprintf(psb->out, "QUIT\r\n"); fflush(psb->out);
  1.1494 -  
  1.1495 -  DEBUG(4) debugf("QUIT\n");
  1.1496 +	fprintf(psb->out, "QUIT\r\n");
  1.1497 +	fflush(psb->out);
  1.1498  
  1.1499 -  signal(SIGALRM, SIG_DFL);
  1.1500 +	DEBUG(4) debugf("QUIT\n");
  1.1501  
  1.1502 -  return TRUE;
  1.1503 +	signal(SIGALRM, SIG_DFL);
  1.1504 +
  1.1505 +	return TRUE;
  1.1506  }
  1.1507 -  
  1.1508 -gint smtp_deliver(gchar *host, gint port, GList *resolve_list,
  1.1509 -		  message *msg,
  1.1510 -		  address *return_path,
  1.1511 -		  GList *rcpt_list)
  1.1512 +
  1.1513 +gint
  1.1514 +smtp_deliver(gchar * host, gint port, GList * resolve_list, message * msg, address * return_path, GList * rcpt_list)
  1.1515  {
  1.1516 -  smtp_base *psb;
  1.1517 -  smtp_error err;
  1.1518 +	smtp_base *psb;
  1.1519 +	smtp_error err;
  1.1520  
  1.1521 -  DEBUG(5) debugf("smtp_deliver entered\n");
  1.1522 +	DEBUG(5) debugf("smtp_deliver entered\n");
  1.1523  
  1.1524 -  if(return_path == NULL)
  1.1525 -    return_path = msg->return_path;
  1.1526 +	if (return_path == NULL)
  1.1527 +		return_path = msg->return_path;
  1.1528  
  1.1529 -  if((psb = smtp_out_open(host, port, resolve_list))){
  1.1530 -    set_heloname(psb, return_path->domain, TRUE);
  1.1531 -    /* initiate connection, send message and quit: */
  1.1532 -    if(smtp_out_init(psb)){
  1.1533 -      smtp_out_msg(psb, msg, return_path, rcpt_list, NULL);
  1.1534 -      if(psb->error == smtp_ok ||
  1.1535 -	 (psb->error == smtp_fail) ||
  1.1536 -	 (psb->error == smtp_trylater) ||
  1.1537 -	 (psb->error == smtp_syntax) ||
  1.1538 -	 (psb->error == smtp_cancel))
  1.1539 -	
  1.1540 -	smtp_out_quit(psb);
  1.1541 -    }
  1.1542 -    
  1.1543 -    err = psb->error;
  1.1544 -    destroy_smtpbase(psb);
  1.1545 -    
  1.1546 -    return err;
  1.1547 -  }
  1.1548 -  return -1;
  1.1549 +	if ((psb = smtp_out_open(host, port, resolve_list))) {
  1.1550 +		set_heloname(psb, return_path->domain, TRUE);
  1.1551 +		/* initiate connection, send message and quit: */
  1.1552 +		if (smtp_out_init(psb)) {
  1.1553 +			smtp_out_msg(psb, msg, return_path, rcpt_list, NULL);
  1.1554 +			if (psb->error == smtp_ok || (psb->error == smtp_fail) || (psb->error == smtp_trylater)
  1.1555 +			    || (psb->error == smtp_syntax) || (psb->error == smtp_cancel))
  1.1556 +				smtp_out_quit(psb);
  1.1557 +		}
  1.1558 +
  1.1559 +		err = psb->error;
  1.1560 +		destroy_smtpbase(psb);
  1.1561 +
  1.1562 +		return err;
  1.1563 +	}
  1.1564 +	return -1;
  1.1565  }