masqmail

diff src/deliver.c @ 321:412385b57dc4

refactoring
author meillo@marmaro.de
date Thu, 28 Apr 2011 16:48:23 +0200
parents 55b7bde95d37
children 9149d893eb52
line diff
     1.1 --- a/src/deliver.c	Thu Apr 28 16:43:38 2011 +0200
     1.2 +++ b/src/deliver.c	Thu Apr 28 16:48:23 2011 +0200
     1.3 @@ -289,26 +289,28 @@
     1.4  			gchar *cmd = g_malloc(256);
     1.5  			GList *var_table = var_table_rcpt(var_table_msg(NULL, msg), rcpt);
     1.6  
     1.7 -			DEBUG(1) debugf("attempting to deliver %s to %s@%s with pipe\n", msg->uid, rcpt->local_part, rcpt->domain);
     1.8 +			DEBUG(1) debugf("attempting to deliver %s to %s@%s with pipe\n",
     1.9 +			                msg->uid, rcpt->local_part, rcpt->domain);
    1.10  
    1.11  			if (!expand(var_table, route->pipe, cmd, 256)) {
    1.12 -				logwrite(LOG_ALERT, "could not expand string %s\n", route->pipe);
    1.13 +				logwrite(LOG_ALERT, "could not expand string `%s'\n", route->pipe);
    1.14 +				destroy_table(var_table);
    1.15 +				continue;
    1.16 +			}
    1.17 +
    1.18 +			if (pipe_out(msg, msg->hdr_list, rcpt, cmd, (route->pipe_fromline ? MSGSTR_FROMLINE : 0)
    1.19 +			    | (route->pipe_fromhack ? MSGSTR_FROMHACK : 0))) {
    1.20 +				logwrite(LOG_NOTICE, "%s => %s@%s with pipe (cmd = '%s')\n",
    1.21 +					 msg->uid, rcpt->local_part, rcpt->domain, cmd);
    1.22 +				addr_mark_delivered(rcpt);
    1.23 +				ok = TRUE;
    1.24  			} else {
    1.25 +				logwrite(LOG_ALERT, "pipe_out '%s' failed\n", route->pipe);
    1.26  
    1.27 -				if (pipe_out(msg, msg->hdr_list, rcpt, cmd, (route->pipe_fromline ? MSGSTR_FROMLINE : 0)
    1.28 -				    | (route->pipe_fromhack ? MSGSTR_FROMHACK : 0))) {
    1.29 -					logwrite(LOG_NOTICE, "%s => %s@%s with pipe (cmd = '%s')\n",
    1.30 -					         msg->uid, rcpt->local_part, rcpt->domain, cmd);
    1.31 -					addr_mark_delivered(rcpt);
    1.32 -					ok = TRUE;
    1.33 +				if (route->connect_error_fail) {
    1.34 +					addr_mark_failed(rcpt);
    1.35  				} else {
    1.36 -					logwrite(LOG_ALERT, "pipe_out '%s' failed\n", route->pipe);
    1.37 -
    1.38 -					if (route->connect_error_fail) {
    1.39 -						addr_mark_failed(rcpt);
    1.40 -					} else {
    1.41 -						addr_mark_defered(rcpt);
    1.42 -					}
    1.43 +					addr_mark_defered(rcpt);
    1.44  				}
    1.45  			}
    1.46  
    1.47 @@ -352,7 +354,7 @@
    1.48  	}
    1.49  
    1.50  	if (route->wrapper) {
    1.51 -		psb = smtp_out_open_child(route->wrapper);
    1.52 +		psb = smtp_out_open_child(route->wrapper, host);
    1.53  	} else {
    1.54  		psb = smtp_out_open(host, port, res_list);
    1.55  	}
    1.56 @@ -388,17 +390,10 @@
    1.57  		return ok;
    1.58  	}
    1.59  
    1.60 -
    1.61 -	if (route->wrapper) {
    1.62 -		/* it seems as if the remote_host is only set for logging
    1.63 -		/* XXX: this could probably be moved into smtp_out_open_child() */
    1.64 -		psb->remote_host = host;
    1.65 -	}
    1.66 -
    1.67  	set_heloname(psb, route->helo_name ? route->helo_name : conf.host_name, route->do_correct_helo);
    1.68  
    1.69  #ifdef ENABLE_AUTH
    1.70 -	if ((route->auth_name) && (route->auth_login) && (route->auth_secret)) {
    1.71 +	if (route->auth_name && route->auth_login && route->auth_secret) {
    1.72  		set_auth(psb, route->auth_name, route->auth_login, route->auth_secret);
    1.73  	}
    1.74  #endif
    1.75 @@ -692,6 +687,8 @@
    1.76  	GList *rf_list = NULL;
    1.77  	gchar *connect_name = NULL;
    1.78  	gboolean ok = FALSE;
    1.79 +	GList *route_node;
    1.80 +	GList *route_list;
    1.81  
    1.82  	connect_name = online_query();
    1.83  	if (!connect_name) {
    1.84 @@ -707,13 +704,13 @@
    1.85  		return FALSE;
    1.86  	}
    1.87  
    1.88 -	GList *route_list = read_route_list(rf_list, FALSE);
    1.89 +	route_list = read_route_list(rf_list, FALSE);
    1.90  	if (!route_list) {
    1.91  		logwrite(LOG_ALERT, "could not read route list '%s'\n", connect_name);
    1.92  		return FALSE;
    1.93  	}
    1.94  
    1.95 -	GList *route_node;
    1.96 +	/* TODO: Should we stop if the mail was delivered? Dig deeper! */
    1.97  	foreach(route_list, route_node) {
    1.98  		connect_route *route = (connect_route *) (route_node->data);
    1.99  		/* TODO: ok gets overwritten */
   1.100 @@ -723,6 +720,12 @@
   1.101  	return ok;
   1.102  }
   1.103  
   1.104 +/*
   1.105 +   This function searches in the list of rcpt addresses
   1.106 +   for local and 'local net' addresses. Remote addresses
   1.107 +   which are reachable only when online are treated specially
   1.108 +   in another function.
   1.109 +*/
   1.110  gboolean
   1.111  deliver_msg_list(GList * msg_list, guint flags)
   1.112  {
   1.113 @@ -854,11 +857,7 @@
   1.114  	return ok;
   1.115  }
   1.116  
   1.117 -/* This function searches in the list of rcpt addresses
   1.118 -   for local and 'local net' addresses. Remote addresses
   1.119 -   which are reachable only when online are treated specially
   1.120 -   in another function.
   1.121 -
   1.122 +/*
   1.123     deliver() is called when a message has just been received and should
   1.124     be delivered immediately.
   1.125  */