masqmail

diff src/route.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/route.c	Mon Oct 27 16:21:27 2008 +0100
     1.2 +++ b/src/route.c	Mon Oct 27 16:23:10 2008 +0100
     1.3 @@ -19,347 +19,335 @@
     1.4  #include "masqmail.h"
     1.5  #include <fnmatch.h>
     1.6  
     1.7 -msgout_perhost *create_msgout_perhost(gchar *host)
     1.8 +msgout_perhost*
     1.9 +create_msgout_perhost(gchar * host)
    1.10  {
    1.11 -  msgout_perhost *mo_ph = g_malloc(sizeof(msgout_perhost));
    1.12 -  if(mo_ph){
    1.13 -    mo_ph->host = g_strdup(host);
    1.14 -    mo_ph->msgout_list = NULL;
    1.15 -  }
    1.16 -  return mo_ph;
    1.17 +	msgout_perhost *mo_ph = g_malloc(sizeof(msgout_perhost));
    1.18 +	if (mo_ph) {
    1.19 +		mo_ph->host = g_strdup(host);
    1.20 +		mo_ph->msgout_list = NULL;
    1.21 +	}
    1.22 +	return mo_ph;
    1.23  }
    1.24  
    1.25 -void destroy_msgout_perhost(msgout_perhost *mo_ph)
    1.26 +void
    1.27 +destroy_msgout_perhost(msgout_perhost * mo_ph)
    1.28  {
    1.29 -  GList *mo_node;
    1.30 +	GList *mo_node;
    1.31  
    1.32 -  foreach(mo_ph->msgout_list, mo_node){
    1.33 -    msg_out *mo = (msg_out *)(mo_node->data);
    1.34 -    /* the rcpt_list is owned by the msgout's,
    1.35 -       but not the rcpt's themselves */
    1.36 -    g_list_free(mo->rcpt_list);
    1.37 -    g_free(mo);
    1.38 -  }
    1.39 -  g_list_free(mo_ph->msgout_list);
    1.40 -  g_free(mo_ph);
    1.41 +	foreach(mo_ph->msgout_list, mo_node) {
    1.42 +		msg_out *mo = (msg_out *) (mo_node->data);
    1.43 +		/* the rcpt_list is owned by the msgout's, but not the rcpt's themselves */
    1.44 +		g_list_free(mo->rcpt_list);
    1.45 +		g_free(mo);
    1.46 +	}
    1.47 +	g_list_free(mo_ph->msgout_list);
    1.48 +	g_free(mo_ph);
    1.49  }
    1.50  
    1.51 -void rewrite_headers(msg_out *msgout, connect_route *route)
    1.52 +void
    1.53 +rewrite_headers(msg_out * msgout, connect_route * route)
    1.54  {
    1.55 -  /* if set_h_from_domain is set, replace domain in all
    1.56 -     From: headers.
    1.57 -  */
    1.58 -  msgout->hdr_list = g_list_copy(msgout->msg->hdr_list);
    1.59 +	/* if set_h_from_domain is set, replace domain in all
    1.60 +	   From: headers.
    1.61 +	 */
    1.62 +	msgout->hdr_list = g_list_copy(msgout->msg->hdr_list);
    1.63  
    1.64 -  /* map from addresses */
    1.65 -  if(route->map_h_from_addresses != NULL){
    1.66 -    GList *hdr_node;
    1.67 -    foreach(msgout->hdr_list, hdr_node){
    1.68 -      header *hdr = (header *)(hdr_node->data);
    1.69 -      if(hdr->id == HEAD_FROM){
    1.70 -	header *new_hdr = copy_header(hdr);
    1.71 -	if(map_address_header(new_hdr, route->map_h_from_addresses)){
    1.72 -	  hdr_node->data = new_hdr;
    1.73 -	  /* we need this list only to carefully free the extra headers: */
    1.74 -	  msgout->xtra_hdr_list =
    1.75 -	    g_list_append(msgout->xtra_hdr_list, new_hdr);
    1.76 -	}else
    1.77 -	  g_free(new_hdr);
    1.78 -      }
    1.79 -    }
    1.80 -  }else{
    1.81 -    /* replace from domain */
    1.82 -    if(route->set_h_from_domain != NULL){
    1.83 -      GList *hdr_node;
    1.84 -      
    1.85 -      foreach(msgout->hdr_list, hdr_node){
    1.86 -	header *hdr = (header *)(hdr_node->data);
    1.87 -	if(hdr->id == HEAD_FROM){
    1.88 -	  header *new_hdr = copy_header(hdr);
    1.89 -	  
    1.90 -	  DEBUG(5) debugf("setting From: domain to %s\n",
    1.91 -			  route->set_h_from_domain);
    1.92 -	  if(set_address_header_domain(new_hdr, route->set_h_from_domain)){
    1.93 -	    hdr_node->data = new_hdr;
    1.94 -	    /* we need this list only to carefully free the extra headers: */
    1.95 -	    DEBUG(6) debugf("header = %s\n",
    1.96 -			    new_hdr->header);
    1.97 -	    msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
    1.98 -	  }else{
    1.99 -	    logwrite(LOG_ALERT, "error in set_address_header_domain(%s, %s)\n",
   1.100 -		     new_hdr->value, route->set_h_from_domain);
   1.101 -	  }
   1.102 +	/* map from addresses */
   1.103 +	if (route->map_h_from_addresses != NULL) {
   1.104 +		GList *hdr_node;
   1.105 +		foreach(msgout->hdr_list, hdr_node) {
   1.106 +			header *hdr = (header *) (hdr_node->data);
   1.107 +			if (hdr->id == HEAD_FROM) {
   1.108 +				header *new_hdr = copy_header(hdr);
   1.109 +				if (map_address_header(new_hdr, route->map_h_from_addresses)) {
   1.110 +					hdr_node->data = new_hdr;
   1.111 +					/* we need this list only to carefully free the extra headers: */
   1.112 +					msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
   1.113 +				} else
   1.114 +					g_free(new_hdr);
   1.115 +			}
   1.116 +		}
   1.117 +	} else {
   1.118 +		/* replace from domain */
   1.119 +		if (route->set_h_from_domain != NULL) {
   1.120 +			GList *hdr_node;
   1.121 +
   1.122 +			foreach(msgout->hdr_list, hdr_node) {
   1.123 +				header *hdr = (header *) (hdr_node->data);
   1.124 +				if (hdr->id == HEAD_FROM) {
   1.125 +					header *new_hdr = copy_header(hdr);
   1.126 +
   1.127 +					DEBUG(5) debugf("setting From: domain to %s\n", route->set_h_from_domain);
   1.128 +					if (set_address_header_domain(new_hdr, route->set_h_from_domain)) {
   1.129 +						hdr_node->data = new_hdr;
   1.130 +						/* we need this list only to carefully free the extra headers: */
   1.131 +						DEBUG(6) debugf("header = %s\n", new_hdr->header);
   1.132 +						msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
   1.133 +					} else {
   1.134 +						logwrite(LOG_ALERT, "error in set_address_header_domain(%s, %s)\n", new_hdr->value, route->set_h_from_domain);
   1.135 +					}
   1.136 +				}
   1.137 +			}
   1.138 +		}
   1.139  	}
   1.140 -      }
   1.141 -    }
   1.142 -  }
   1.143  
   1.144 -  /* map reply-to addresses */
   1.145 -  if(route->map_h_reply_to_addresses != NULL){
   1.146 -    GList *hdr_node;
   1.147 -    foreach(msgout->hdr_list, hdr_node){
   1.148 -      header *hdr = (header *)(hdr_node->data);
   1.149 -      if(hdr->id == HEAD_REPLY_TO){
   1.150 -	header *new_hdr = copy_header(hdr);
   1.151 -	if(map_address_header(new_hdr, route->map_h_reply_to_addresses)){
   1.152 -	  hdr_node->data = new_hdr;
   1.153 -	  /* we need this list only to carefully free the extra headers: */
   1.154 -	  msgout->xtra_hdr_list =
   1.155 -	    g_list_append(msgout->xtra_hdr_list, new_hdr);
   1.156 -	}else
   1.157 -	  g_free(new_hdr);
   1.158 -      }
   1.159 -    }
   1.160 -  }else{
   1.161 -    /* replace Reply-to domain */
   1.162 -    if(route->set_h_reply_to_domain != NULL){
   1.163 -      GList *hdr_node;
   1.164 -      
   1.165 -      foreach(msgout->hdr_list, hdr_node){
   1.166 -	header *hdr = (header *)(hdr_node->data);
   1.167 -	if(hdr->id == HEAD_REPLY_TO){
   1.168 -	  header *new_hdr = copy_header(hdr);
   1.169 -	  
   1.170 -	  set_address_header_domain(new_hdr, route->set_h_reply_to_domain);
   1.171 -	  hdr_node->data = new_hdr;
   1.172 -	  /* we need this list only to carefully free the extra headers: */
   1.173 -	  msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
   1.174 +	/* map reply-to addresses */
   1.175 +	if (route->map_h_reply_to_addresses != NULL) {
   1.176 +		GList *hdr_node;
   1.177 +		foreach(msgout->hdr_list, hdr_node) {
   1.178 +			header *hdr = (header *) (hdr_node->data);
   1.179 +			if (hdr->id == HEAD_REPLY_TO) {
   1.180 +				header *new_hdr = copy_header(hdr);
   1.181 +				if (map_address_header
   1.182 +					(new_hdr, route->map_h_reply_to_addresses)) {
   1.183 +					hdr_node->data = new_hdr;
   1.184 +					/* we need this list only to carefully free the extra headers: */
   1.185 +					msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
   1.186 +				} else
   1.187 +					g_free(new_hdr);
   1.188 +			}
   1.189 +		}
   1.190 +	} else {
   1.191 +		/* replace Reply-to domain */
   1.192 +		if (route->set_h_reply_to_domain != NULL) {
   1.193 +			GList *hdr_node;
   1.194 +
   1.195 +			foreach(msgout->hdr_list, hdr_node) {
   1.196 +				header *hdr = (header *) (hdr_node->data);
   1.197 +				if (hdr->id == HEAD_REPLY_TO) {
   1.198 +					header *new_hdr = copy_header(hdr);
   1.199 +
   1.200 +					set_address_header_domain(new_hdr, route-> set_h_reply_to_domain);
   1.201 +					hdr_node->data = new_hdr;
   1.202 +					/* we need this list only to carefully free the extra headers: */
   1.203 +					msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
   1.204 +				}
   1.205 +			}
   1.206 +		}
   1.207  	}
   1.208 -      }
   1.209 -    }
   1.210 -  }
   1.211  
   1.212 -  /* map Mail-Followup-To addresses */
   1.213 -  if(route->map_h_mail_followup_to_addresses != NULL){
   1.214 -    GList *hdr_node;
   1.215 -    foreach(msgout->hdr_list, hdr_node){
   1.216 -      header *hdr = (header *)(hdr_node->data);
   1.217 -      if(strncasecmp(hdr->header, "Mail-Followup-To", 16) == 0){
   1.218 -	header *new_hdr = copy_header(hdr);
   1.219 -	if(map_address_header(new_hdr, route->map_h_mail_followup_to_addresses)){
   1.220 -	  hdr_node->data = new_hdr;
   1.221 -	  /* we need this list only to carefully free the extra headers: */
   1.222 -	  msgout->xtra_hdr_list =
   1.223 -	    g_list_append(msgout->xtra_hdr_list, new_hdr);
   1.224 -	}else
   1.225 -	  g_free(new_hdr);
   1.226 -      }
   1.227 -    }
   1.228 -  }
   1.229 +	/* map Mail-Followup-To addresses */
   1.230 +	if (route->map_h_mail_followup_to_addresses != NULL) {
   1.231 +		GList *hdr_node;
   1.232 +		foreach(msgout->hdr_list, hdr_node) {
   1.233 +			header *hdr = (header *) (hdr_node->data);
   1.234 +			if (strncasecmp(hdr->header, "Mail-Followup-To", 16) == 0) {
   1.235 +				header *new_hdr = copy_header(hdr);
   1.236 +				if (map_address_header(new_hdr, route->map_h_mail_followup_to_addresses)) {
   1.237 +					hdr_node->data = new_hdr;
   1.238 +					/* we need this list only to carefully free the extra headers: */
   1.239 +					msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
   1.240 +				} else
   1.241 +					g_free(new_hdr);
   1.242 +			}
   1.243 +		}
   1.244 +	}
   1.245  
   1.246 -  /* set Sender: domain to return_path->domain */
   1.247 -  if(route->expand_h_sender_domain){
   1.248 -    GList *hdr_node;
   1.249 +	/* set Sender: domain to return_path->domain */
   1.250 +	if (route->expand_h_sender_domain) {
   1.251 +		GList *hdr_node;
   1.252  
   1.253 -    foreach(msgout->hdr_list, hdr_node){
   1.254 -      header *hdr = (header *)(hdr_node->data);
   1.255 -      if(hdr->id == HEAD_SENDER){
   1.256 -	header *new_hdr = copy_header(hdr);
   1.257 +		foreach(msgout->hdr_list, hdr_node) {
   1.258 +			header *hdr = (header *) (hdr_node->data);
   1.259 +			if (hdr->id == HEAD_SENDER) {
   1.260 +				header *new_hdr = copy_header(hdr);
   1.261  
   1.262 -	set_address_header_domain(new_hdr, msgout->return_path->domain);
   1.263 -	hdr_node->data = new_hdr;
   1.264 -	/* we need this list only to carefully free the extra headers: */
   1.265 -	msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
   1.266 -      }
   1.267 -    }
   1.268 -  }
   1.269 +				set_address_header_domain(new_hdr, msgout->return_path->domain);
   1.270 +				hdr_node->data = new_hdr;
   1.271 +				/* we need this list only to carefully free the extra headers: */
   1.272 +				msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
   1.273 +			}
   1.274 +		}
   1.275 +	}
   1.276  
   1.277 -  /* set Sender: domain to return_path->domain */
   1.278 -  if(route->expand_h_sender_address){
   1.279 -    GList *hdr_node;
   1.280 +	/* set Sender: domain to return_path->domain */
   1.281 +	if (route->expand_h_sender_address) {
   1.282 +		GList *hdr_node;
   1.283  
   1.284 -    foreach(msgout->hdr_list, hdr_node){
   1.285 -      header *hdr = (header *)(hdr_node->data);
   1.286 -      if(hdr->id == HEAD_SENDER){
   1.287 -	header *new_hdr;
   1.288 +		foreach(msgout->hdr_list, hdr_node) {
   1.289 +			header *hdr = (header *) (hdr_node->data);
   1.290 +			if (hdr->id == HEAD_SENDER) {
   1.291 +				header *new_hdr;
   1.292  
   1.293 -	new_hdr =
   1.294 -	  create_header(HEAD_SENDER, "Sender: %s@%s\n",
   1.295 -			msgout->return_path->local_part, msgout->return_path->domain);
   1.296 -	hdr_node->data = new_hdr;
   1.297 -	/* we need this list only to carefully free the extra headers: */
   1.298 -	msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
   1.299 -      }
   1.300 -    }
   1.301 -  }
   1.302 +				new_hdr = create_header(HEAD_SENDER, "Sender: %s@%s\n", msgout->return_path->local_part, msgout->return_path->domain);
   1.303 +				hdr_node->data = new_hdr;
   1.304 +				/* we need this list only to carefully free the extra headers: */
   1.305 +				msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
   1.306 +			}
   1.307 +		}
   1.308 +	}
   1.309  
   1.310 -  if(msgout->xtra_hdr_list == NULL){
   1.311 -    /* nothing was changed */
   1.312 -    g_list_free(msgout->hdr_list);
   1.313 -    msgout->hdr_list = NULL;
   1.314 -  }
   1.315 -  DEBUG(5) debugf("rewrite_headers() returning\n");
   1.316 +	if (msgout->xtra_hdr_list == NULL) {
   1.317 +		/* nothing was changed */
   1.318 +		g_list_free(msgout->hdr_list);
   1.319 +		msgout->hdr_list = NULL;
   1.320 +	}
   1.321 +	DEBUG(5) debugf("rewrite_headers() returning\n");
   1.322  }
   1.323  
   1.324 -void rcptlist_with_one_of_hostlist(GList *rcpt_list, GList *host_list,
   1.325 -				   GList **p_rcpt_list, GList **p_non_rcpt_list)
   1.326 +void
   1.327 +rcptlist_with_one_of_hostlist(GList * rcpt_list, GList * host_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list)
   1.328  {
   1.329 -  GList *rcpt_node;
   1.330 +	GList *rcpt_node;
   1.331  
   1.332 -  if(rcpt_list == NULL)
   1.333 -    return;
   1.334 +	if (rcpt_list == NULL)
   1.335 +		return;
   1.336  
   1.337 -  foreach(rcpt_list, rcpt_node){
   1.338 -    address *rcpt = (address *)(rcpt_node->data);
   1.339 -    GList *host_node = NULL;
   1.340 +	foreach(rcpt_list, rcpt_node) {
   1.341 +		address *rcpt = (address *) (rcpt_node->data);
   1.342 +		GList *host_node = NULL;
   1.343  
   1.344 -    foreach(host_list, host_node){
   1.345 -      gchar *host = (gchar *)(host_node->data);
   1.346 -      if(fnmatch(host, rcpt->domain, FNM_CASEFOLD) == 0)
   1.347 -	break;
   1.348 -    }
   1.349 -    if(host_node){
   1.350 -      if(p_rcpt_list)
   1.351 -	*p_rcpt_list = g_list_append(*p_rcpt_list, rcpt);
   1.352 -    }else{
   1.353 -      if(p_non_rcpt_list)
   1.354 -	*p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt);
   1.355 -    }
   1.356 +		foreach(host_list, host_node) {
   1.357 +			gchar *host = (gchar *) (host_node->data);
   1.358 +			if (fnmatch(host, rcpt->domain, FNM_CASEFOLD) == 0)
   1.359 +				break;
   1.360 +		}
   1.361 +		if (host_node) {
   1.362 +			if (p_rcpt_list)
   1.363 +				*p_rcpt_list = g_list_append(*p_rcpt_list, rcpt);
   1.364 +		} else {
   1.365 +			if (p_non_rcpt_list)
   1.366 +				*p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt);
   1.367 +		}
   1.368  
   1.369 -  }
   1.370 +	}
   1.371  }
   1.372  
   1.373 -void rcptlist_with_addr_is_local(GList *rcpt_list,
   1.374 -				 GList **p_rcpt_list, GList **p_non_rcpt_list)
   1.375 +void
   1.376 +rcptlist_with_addr_is_local(GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list)
   1.377  {
   1.378 -  GList *rcpt_node;
   1.379 +	GList *rcpt_node;
   1.380  
   1.381 -  if(rcpt_list == NULL)
   1.382 -    return;
   1.383 +	if (rcpt_list == NULL)
   1.384 +		return;
   1.385  
   1.386 -  foreach(rcpt_list, rcpt_node){
   1.387 -    address *rcpt = (address *)(rcpt_node->data);
   1.388 -    if(addr_is_local(rcpt)){
   1.389 -      if(p_rcpt_list)
   1.390 -	*p_rcpt_list = g_list_append(*p_rcpt_list, rcpt);
   1.391 -    }else{
   1.392 -      if(p_non_rcpt_list)
   1.393 -	*p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt);
   1.394 -    }
   1.395 +	foreach(rcpt_list, rcpt_node) {
   1.396 +		address *rcpt = (address *) (rcpt_node->data);
   1.397 +		if (addr_is_local(rcpt)) {
   1.398 +			if (p_rcpt_list)
   1.399 +				*p_rcpt_list = g_list_append(*p_rcpt_list, rcpt);
   1.400 +		} else {
   1.401 +			if (p_non_rcpt_list)
   1.402 +				*p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt);
   1.403 +		}
   1.404  
   1.405 -  }
   1.406 +	}
   1.407  }
   1.408  
   1.409 -static gint _g_list_addrcmp(gconstpointer a, gconstpointer b)
   1.410 +static gint
   1.411 +_g_list_addrcmp(gconstpointer a, gconstpointer b)
   1.412  {
   1.413 -  return addr_match((address *)a, (address *)b);
   1.414 +	return addr_match((address *) a, (address *) b);
   1.415  }
   1.416  
   1.417 -gboolean route_is_allowed_return_path(connect_route *route, address *ret_path)
   1.418 +gboolean
   1.419 +route_is_allowed_return_path(connect_route * route, address * ret_path)
   1.420  {
   1.421 -  if(route->not_allowed_return_paths != NULL){
   1.422 -    if(g_list_find_custom(route->not_allowed_return_paths, ret_path,
   1.423 -			  _g_list_addrcmp) != NULL){
   1.424 -      return FALSE;
   1.425 -    }
   1.426 -  }
   1.427 -  if(route->allowed_return_paths != NULL){
   1.428 -    if(g_list_find_custom(route->allowed_return_paths, ret_path,
   1.429 -			  _g_list_addrcmp) != NULL){
   1.430 -      return TRUE;
   1.431 -    }else{
   1.432 -      return FALSE;
   1.433 -    }
   1.434 -  }
   1.435 -  return TRUE;
   1.436 +	if (route->not_allowed_return_paths != NULL) {
   1.437 +		if (g_list_find_custom(route->not_allowed_return_paths, ret_path, _g_list_addrcmp) != NULL) {
   1.438 +			return FALSE;
   1.439 +		}
   1.440 +	}
   1.441 +	if (route->allowed_return_paths != NULL) {
   1.442 +		if (g_list_find_custom(route->allowed_return_paths, ret_path, _g_list_addrcmp) != NULL) {
   1.443 +			return TRUE;
   1.444 +		} else {
   1.445 +			return FALSE;
   1.446 +		}
   1.447 +	}
   1.448 +	return TRUE;
   1.449  }
   1.450  
   1.451 -static gint _g_list_strcmp(gconstpointer a, gconstpointer b)
   1.452 +static gint
   1.453 +_g_list_strcmp(gconstpointer a, gconstpointer b)
   1.454  {
   1.455 -  return (gint)strcmp(a, b);
   1.456 +	return (gint) strcmp(a, b);
   1.457  }
   1.458  
   1.459 -gboolean route_is_allowed_mail_local(connect_route *route, address *ret_path)
   1.460 +gboolean
   1.461 +route_is_allowed_mail_local(connect_route * route, address * ret_path)
   1.462  {
   1.463 -  gchar *loc_part = ret_path->local_part;
   1.464 +	gchar *loc_part = ret_path->local_part;
   1.465  
   1.466 -  if(route->not_allowed_mail_locals != NULL){
   1.467 -    if(g_list_find_custom(route->not_allowed_mail_locals, loc_part,
   1.468 -			 _g_list_strcmp) != NULL)
   1.469 -      return FALSE;
   1.470 -  }
   1.471 -  if(route->allowed_mail_locals != NULL){
   1.472 -    if(g_list_find_custom(route->allowed_mail_locals, loc_part,
   1.473 -			  _g_list_strcmp) != NULL)
   1.474 -      return TRUE;
   1.475 -    else
   1.476 -      return FALSE;
   1.477 -  }
   1.478 -  return TRUE;
   1.479 +	if (route->not_allowed_mail_locals != NULL) {
   1.480 +		if (g_list_find_custom(route->not_allowed_mail_locals, loc_part, _g_list_strcmp) != NULL)
   1.481 +			return FALSE;
   1.482 +	}
   1.483 +	if (route->allowed_mail_locals != NULL) {
   1.484 +		if (g_list_find_custom(route->allowed_mail_locals, loc_part, _g_list_strcmp) != NULL)
   1.485 +			return TRUE;
   1.486 +		else
   1.487 +			return FALSE;
   1.488 +	}
   1.489 +	return TRUE;
   1.490  }
   1.491  
   1.492 -/* 
   1.493 +/*
   1.494     Make lists of matching/not matching rcpts.
   1.495     Local domains are NOT regared here, these should be sorted out previously
   1.496  */
   1.497 -void msg_rcptlist_route(connect_route *route, GList *rcpt_list,
   1.498 -			GList **p_rcpt_list, GList **p_non_rcpt_list)
   1.499 +void
   1.500 +msg_rcptlist_route(connect_route * route, GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list)
   1.501  {
   1.502 -  GList *tmp_list = NULL;
   1.503 -  /* sort out those domains that can be sent over this connection: */
   1.504 -  if(route->allowed_rcpt_domains){
   1.505 -    DEBUG(5) debugf("testing for route->allowed_rcpt_domains\n");
   1.506 -    rcptlist_with_one_of_hostlist(rcpt_list, route->allowed_rcpt_domains, &tmp_list, p_non_rcpt_list);
   1.507 -  }else{
   1.508 -    DEBUG(5) debugf("route->allowed_rcpt_domains == NULL\n");
   1.509 -    tmp_list = g_list_copy(rcpt_list);
   1.510 -  }
   1.511 +	GList *tmp_list = NULL;
   1.512 +	/* sort out those domains that can be sent over this connection: */
   1.513 +	if (route->allowed_rcpt_domains) {
   1.514 +		DEBUG(5) debugf("testing for route->allowed_rcpt_domains\n");
   1.515 +		rcptlist_with_one_of_hostlist(rcpt_list, route->allowed_rcpt_domains, &tmp_list, p_non_rcpt_list);
   1.516 +	} else {
   1.517 +		DEBUG(5) debugf("route->allowed_rcpt_domains == NULL\n");
   1.518 +		tmp_list = g_list_copy(rcpt_list);
   1.519 +	}
   1.520  
   1.521 -  /* sort out those domains that cannot be sent over this connection: */
   1.522 -  rcptlist_with_one_of_hostlist(tmp_list, route->not_allowed_rcpt_domains, p_non_rcpt_list, p_rcpt_list);
   1.523 -  g_list_free(tmp_list);
   1.524 +	/* sort out those domains that cannot be sent over this connection: */
   1.525 +	rcptlist_with_one_of_hostlist(tmp_list, route->not_allowed_rcpt_domains, p_non_rcpt_list, p_rcpt_list);
   1.526 +	g_list_free(tmp_list);
   1.527  }
   1.528  
   1.529 -msg_out *route_prepare_msgout(connect_route *route, msg_out *msgout)
   1.530 +msg_out*
   1.531 +route_prepare_msgout(connect_route * route, msg_out * msgout)
   1.532  {
   1.533 -  message *msg = msgout->msg;
   1.534 -  GList *rcpt_list = msgout->rcpt_list;
   1.535 +	message *msg = msgout->msg;
   1.536 +	GList *rcpt_list = msgout->rcpt_list;
   1.537  
   1.538 -  if(rcpt_list != NULL){
   1.539 -    /* found a few */
   1.540 -    DEBUG(5){
   1.541 -      GList *node;
   1.542 -      debugf("rcpts for routed delivery, route = %s, id = %s\n", route->name, msg->uid);
   1.543 -      foreach(rcpt_list, node){
   1.544 -	address *rcpt = (address *)(node->data);
   1.545 -	debugf("rcpt for routed delivery: <%s@%s>\n",
   1.546 -	       rcpt->local_part, rcpt->domain);
   1.547 -      }
   1.548 -    }
   1.549 -      
   1.550 -    /* rewrite return path
   1.551 -       if there is a table, use that
   1.552 -       if an address is found and if it has a domain, use that
   1.553 -    */
   1.554 -    if(route->map_return_path_addresses){
   1.555 -      address *ret_path = NULL;
   1.556 -      DEBUG(5) debugf("looking up %s in map_return_path_addresses\n",
   1.557 -		      msg->return_path->local_part);
   1.558 -      ret_path =
   1.559 -	(address *)table_find_fnmatch(route->map_return_path_addresses,
   1.560 -			      msg->return_path->local_part);
   1.561 -      if(ret_path){
   1.562 -	DEBUG(5) debugf("found <%s@%s>\n",
   1.563 -			ret_path->local_part, ret_path->domain); 
   1.564 -	if(ret_path->domain == NULL)
   1.565 -	  ret_path->domain =
   1.566 -	    route->set_return_path_domain ?
   1.567 -	    route->set_return_path_domain : msg->return_path->domain;
   1.568 -	msgout->return_path = copy_address(ret_path);
   1.569 -      }
   1.570 -    }
   1.571 -    if(msgout->return_path == NULL){
   1.572 -      DEBUG(5) debugf("setting return path to %s\n",
   1.573 -		      route->set_return_path_domain);
   1.574 -      msgout->return_path =
   1.575 -	copy_modify_address(msg->return_path,
   1.576 -			    NULL, route->set_return_path_domain);
   1.577 -    }
   1.578 -    rewrite_headers(msgout, route);
   1.579 +	if (rcpt_list != NULL) {
   1.580 +		/* found a few */
   1.581 +		DEBUG(5) {
   1.582 +			GList *node;
   1.583 +			debugf("rcpts for routed delivery, route = %s, id = %s\n", route->name, msg->uid);
   1.584 +			foreach(rcpt_list, node) {
   1.585 +				address *rcpt = (address *) (node->data);
   1.586 +				debugf("rcpt for routed delivery: <%s@%s>\n", rcpt->local_part, rcpt->domain);
   1.587 +			}
   1.588 +		}
   1.589  
   1.590 -    return msgout;
   1.591 -  }
   1.592 -  return NULL;
   1.593 +		/* rewrite return path
   1.594 +		   if there is a table, use that
   1.595 +		   if an address is found and if it has a domain, use that
   1.596 +		 */
   1.597 +		if (route->map_return_path_addresses) {
   1.598 +			address *ret_path = NULL;
   1.599 +			DEBUG(5) debugf("looking up %s in map_return_path_addresses\n", msg->return_path->local_part);
   1.600 +			ret_path = (address *) table_find_fnmatch(route->map_return_path_addresses, msg->return_path->local_part);
   1.601 +			if (ret_path) {
   1.602 +				DEBUG(5) debugf("found <%s@%s>\n", ret_path->local_part, ret_path->domain);
   1.603 +				if (ret_path->domain == NULL)
   1.604 +					ret_path->domain = route->set_return_path_domain
   1.605 +					                   ? route->set_return_path_domain
   1.606 +					                   : msg->return_path->domain;
   1.607 +				msgout->return_path = copy_address(ret_path);
   1.608 +			}
   1.609 +		}
   1.610 +		if (msgout->return_path == NULL) {
   1.611 +			DEBUG(5) debugf("setting return path to %s\n", route->set_return_path_domain);
   1.612 +			msgout->return_path = copy_modify_address(msg->return_path, NULL, route->set_return_path_domain);
   1.613 +		}
   1.614 +		rewrite_headers(msgout, route);
   1.615 +
   1.616 +		return msgout;
   1.617 +	}
   1.618 +	return NULL;
   1.619  }
   1.620  
   1.621  /* put msgout's is msgout_list into bins (msgout_perhost structs) for each
   1.622 @@ -367,70 +355,66 @@
   1.623     route param is not used, we leave it here because that may change.
   1.624   */
   1.625  
   1.626 -GList *route_msgout_list(connect_route *route, GList *msgout_list)
   1.627 +GList*
   1.628 +route_msgout_list(connect_route * route, GList * msgout_list)
   1.629  {
   1.630 -  GList *mo_ph_list = NULL;
   1.631 -  GList *msgout_node;
   1.632 +	GList *mo_ph_list = NULL;
   1.633 +	GList *msgout_node;
   1.634  
   1.635 -  foreach(msgout_list, msgout_node){
   1.636 -    msg_out *msgout = (msg_out *)(msgout_node->data);
   1.637 -    msg_out *msgout_new;
   1.638 -    GList *rcpt_list = msgout->rcpt_list;
   1.639 -    GList *rcpt_node;
   1.640 +	foreach(msgout_list, msgout_node) {
   1.641 +		msg_out *msgout = (msg_out *) (msgout_node->data);
   1.642 +		msg_out *msgout_new;
   1.643 +		GList *rcpt_list = msgout->rcpt_list;
   1.644 +		GList *rcpt_node;
   1.645  
   1.646 -    foreach(rcpt_list, rcpt_node){
   1.647 -      address *rcpt = rcpt_node->data;
   1.648 -      msgout_perhost *mo_ph = NULL;
   1.649 -      GList *mo_ph_node = NULL;
   1.650 +		foreach(rcpt_list, rcpt_node) {
   1.651 +			address *rcpt = rcpt_node->data;
   1.652 +			msgout_perhost *mo_ph = NULL;
   1.653 +			GList *mo_ph_node = NULL;
   1.654  
   1.655 -      /* search host in mo_ph_list */
   1.656 -      foreach(mo_ph_list, mo_ph_node){
   1.657 -	mo_ph = (msgout_perhost *)(mo_ph_node->data);
   1.658 -	if(strcasecmp(mo_ph->host, rcpt->domain) == 0)
   1.659 -	  break;
   1.660 -      }
   1.661 -      if(mo_ph_node != NULL){
   1.662 -	/* there is already a rcpt for this host */
   1.663 -	msg_out *msgout_last =
   1.664 -	  (msg_out *)((g_list_last(mo_ph->msgout_list))->data);
   1.665 -	if(msgout_last->msg == msgout->msg){
   1.666 -	  /* if it is also the same message, it must be the last one
   1.667 -	     appended to mo_ph->msgout_list (since outer loop goes through
   1.668 -	     msgout_list) */
   1.669 -	  msgout_last->rcpt_list =
   1.670 -	    g_list_append(msgout_last->rcpt_list, rcpt);
   1.671 -	}else{
   1.672 -	  /* if not, we append a new msgout */
   1.673 -	  /* make a copy of msgout */
   1.674 -	  msgout_new = create_msg_out(msgout->msg);
   1.675 -	  msgout_new->return_path = msgout->return_path;
   1.676 -	  msgout_new->hdr_list = msgout->hdr_list;
   1.677 +			/* search host in mo_ph_list */
   1.678 +			foreach(mo_ph_list, mo_ph_node) {
   1.679 +				mo_ph = (msgout_perhost *) (mo_ph_node->data);
   1.680 +				if (strcasecmp(mo_ph->host, rcpt->domain) == 0)
   1.681 +					break;
   1.682 +			}
   1.683 +			if (mo_ph_node != NULL) {
   1.684 +				/* there is already a rcpt for this host */
   1.685 +				msg_out *msgout_last = (msg_out *) ((g_list_last(mo_ph->msgout_list))->data);
   1.686 +				if (msgout_last->msg == msgout->msg) {
   1.687 +					/* if it is also the same message, it must be the last one
   1.688 +					   appended to mo_ph->msgout_list (since outer loop goes through
   1.689 +					   msgout_list) */
   1.690 +					msgout_last->rcpt_list = g_list_append(msgout_last->rcpt_list, rcpt);
   1.691 +				} else {
   1.692 +					/* if not, we append a new msgout */
   1.693 +					/* make a copy of msgout */
   1.694 +					msgout_new = create_msg_out(msgout->msg);
   1.695 +					msgout_new->return_path = msgout->return_path;
   1.696 +					msgout_new->hdr_list = msgout->hdr_list;
   1.697  
   1.698 -	  /* append our rcpt to it */
   1.699 -	  /* It is the 1st rcpt for this msg to this host,
   1.700 -	     therefore we safely give NULL */
   1.701 -	  msgout_new->rcpt_list = g_list_append(NULL, rcpt);
   1.702 -	  mo_ph->msgout_list =
   1.703 -	    g_list_append(mo_ph->msgout_list, msgout_new);
   1.704 -	}
   1.705 -      }else{
   1.706 -	/* this rcpt to goes to another host */
   1.707 -	mo_ph = create_msgout_perhost(rcpt->domain);
   1.708 -	mo_ph_list = g_list_append(mo_ph_list, mo_ph);
   1.709 +					/* append our rcpt to it */
   1.710 +					/* It is the 1st rcpt for this msg to this host, therefore we safely give NULL */
   1.711 +					msgout_new->rcpt_list = g_list_append(NULL, rcpt);
   1.712 +					mo_ph->msgout_list = g_list_append(mo_ph->msgout_list, msgout_new);
   1.713 +				}
   1.714 +			} else {
   1.715 +				/* this rcpt to goes to another host */
   1.716 +				mo_ph = create_msgout_perhost(rcpt->domain);
   1.717 +				mo_ph_list = g_list_append(mo_ph_list, mo_ph);
   1.718  
   1.719 -	/* make a copy of msgout */
   1.720 -	msgout_new = create_msg_out(msgout->msg);
   1.721 -	msgout_new->return_path = msgout->return_path;
   1.722 -	msgout_new->hdr_list = msgout->hdr_list;
   1.723 -	    
   1.724 -	/* append our rcpt to it */
   1.725 -	/* It is the 1st rcpt for this msg to this host,
   1.726 -	   therefore we safely give NULL */
   1.727 -	msgout_new->rcpt_list = g_list_append(NULL, rcpt);
   1.728 -	mo_ph->msgout_list = g_list_append(mo_ph->msgout_list, msgout_new);
   1.729 -      }/* if mo_ph != NULL */
   1.730 -    }/* foreach(rcpt_list, ... */
   1.731 -  }/* foreach(msgout_list, ... */
   1.732 +				/* make a copy of msgout */
   1.733 +				msgout_new = create_msg_out(msgout->msg);
   1.734 +				msgout_new->return_path = msgout->return_path;
   1.735 +				msgout_new->hdr_list = msgout->hdr_list;
   1.736  
   1.737 -  return mo_ph_list;
   1.738 +				/* append our rcpt to it */
   1.739 +				/* It is the 1st rcpt for this msg to this host, therefore we safely give NULL */
   1.740 +				msgout_new->rcpt_list = g_list_append(NULL, rcpt);
   1.741 +				mo_ph->msgout_list = g_list_append(mo_ph->msgout_list, msgout_new);
   1.742 +			}  /* if mo_ph != NULL */
   1.743 +		}  /* foreach(rcpt_list, ... */
   1.744 +	}  /* foreach(msgout_list, ... */
   1.745 +
   1.746 +	return mo_ph_list;
   1.747  }