Mercurial > masqmail
comparison src/deliver.c @ 321:412385b57dc4
refactoring
author | meillo@marmaro.de |
---|---|
date | Thu, 28 Apr 2011 16:48:23 +0200 |
parents | 55b7bde95d37 |
children | 9149d893eb52 |
comparison
equal
deleted
inserted
replaced
320:4c705c34182f | 321:412385b57dc4 |
---|---|
287 foreach(rcpt_list, rcpt_node) { | 287 foreach(rcpt_list, rcpt_node) { |
288 address *rcpt = (address *) (rcpt_node->data); | 288 address *rcpt = (address *) (rcpt_node->data); |
289 gchar *cmd = g_malloc(256); | 289 gchar *cmd = g_malloc(256); |
290 GList *var_table = var_table_rcpt(var_table_msg(NULL, msg), rcpt); | 290 GList *var_table = var_table_rcpt(var_table_msg(NULL, msg), rcpt); |
291 | 291 |
292 DEBUG(1) debugf("attempting to deliver %s to %s@%s with pipe\n", msg->uid, rcpt->local_part, rcpt->domain); | 292 DEBUG(1) debugf("attempting to deliver %s to %s@%s with pipe\n", |
293 msg->uid, rcpt->local_part, rcpt->domain); | |
293 | 294 |
294 if (!expand(var_table, route->pipe, cmd, 256)) { | 295 if (!expand(var_table, route->pipe, cmd, 256)) { |
295 logwrite(LOG_ALERT, "could not expand string %s\n", route->pipe); | 296 logwrite(LOG_ALERT, "could not expand string `%s'\n", route->pipe); |
297 destroy_table(var_table); | |
298 continue; | |
299 } | |
300 | |
301 if (pipe_out(msg, msg->hdr_list, rcpt, cmd, (route->pipe_fromline ? MSGSTR_FROMLINE : 0) | |
302 | (route->pipe_fromhack ? MSGSTR_FROMHACK : 0))) { | |
303 logwrite(LOG_NOTICE, "%s => %s@%s with pipe (cmd = '%s')\n", | |
304 msg->uid, rcpt->local_part, rcpt->domain, cmd); | |
305 addr_mark_delivered(rcpt); | |
306 ok = TRUE; | |
296 } else { | 307 } else { |
297 | 308 logwrite(LOG_ALERT, "pipe_out '%s' failed\n", route->pipe); |
298 if (pipe_out(msg, msg->hdr_list, rcpt, cmd, (route->pipe_fromline ? MSGSTR_FROMLINE : 0) | 309 |
299 | (route->pipe_fromhack ? MSGSTR_FROMHACK : 0))) { | 310 if (route->connect_error_fail) { |
300 logwrite(LOG_NOTICE, "%s => %s@%s with pipe (cmd = '%s')\n", | 311 addr_mark_failed(rcpt); |
301 msg->uid, rcpt->local_part, rcpt->domain, cmd); | |
302 addr_mark_delivered(rcpt); | |
303 ok = TRUE; | |
304 } else { | 312 } else { |
305 logwrite(LOG_ALERT, "pipe_out '%s' failed\n", route->pipe); | 313 addr_mark_defered(rcpt); |
306 | |
307 if (route->connect_error_fail) { | |
308 addr_mark_failed(rcpt); | |
309 } else { | |
310 addr_mark_defered(rcpt); | |
311 } | |
312 } | 314 } |
313 } | 315 } |
314 | 316 |
315 destroy_table(var_table); | 317 destroy_table(var_table); |
316 } | 318 } |
350 host = route->mail_host->address; | 352 host = route->mail_host->address; |
351 port = route->mail_host->port; | 353 port = route->mail_host->port; |
352 } | 354 } |
353 | 355 |
354 if (route->wrapper) { | 356 if (route->wrapper) { |
355 psb = smtp_out_open_child(route->wrapper); | 357 psb = smtp_out_open_child(route->wrapper, host); |
356 } else { | 358 } else { |
357 psb = smtp_out_open(host, port, res_list); | 359 psb = smtp_out_open(host, port, res_list); |
358 } | 360 } |
359 | 361 |
360 if (!psb) { | 362 if (!psb) { |
386 } | 388 } |
387 } | 389 } |
388 return ok; | 390 return ok; |
389 } | 391 } |
390 | 392 |
391 | |
392 if (route->wrapper) { | |
393 /* it seems as if the remote_host is only set for logging | |
394 /* XXX: this could probably be moved into smtp_out_open_child() */ | |
395 psb->remote_host = host; | |
396 } | |
397 | |
398 set_heloname(psb, route->helo_name ? route->helo_name : conf.host_name, route->do_correct_helo); | 393 set_heloname(psb, route->helo_name ? route->helo_name : conf.host_name, route->do_correct_helo); |
399 | 394 |
400 #ifdef ENABLE_AUTH | 395 #ifdef ENABLE_AUTH |
401 if ((route->auth_name) && (route->auth_login) && (route->auth_secret)) { | 396 if (route->auth_name && route->auth_login && route->auth_secret) { |
402 set_auth(psb, route->auth_name, route->auth_login, route->auth_secret); | 397 set_auth(psb, route->auth_name, route->auth_login, route->auth_secret); |
403 } | 398 } |
404 #endif | 399 #endif |
405 if (!smtp_out_init(psb, route->instant_helo)) { | 400 if (!smtp_out_init(psb, route->instant_helo)) { |
406 /* smtp_out_init() failed */ | 401 /* smtp_out_init() failed */ |
690 deliver_msgout_list_online(GList * msgout_list) | 685 deliver_msgout_list_online(GList * msgout_list) |
691 { | 686 { |
692 GList *rf_list = NULL; | 687 GList *rf_list = NULL; |
693 gchar *connect_name = NULL; | 688 gchar *connect_name = NULL; |
694 gboolean ok = FALSE; | 689 gboolean ok = FALSE; |
690 GList *route_node; | |
691 GList *route_list; | |
695 | 692 |
696 connect_name = online_query(); | 693 connect_name = online_query(); |
697 if (!connect_name) { | 694 if (!connect_name) { |
698 return FALSE; | 695 return FALSE; |
699 } | 696 } |
705 if (!rf_list) { | 702 if (!rf_list) { |
706 logwrite(LOG_ALERT, "route list with name '%s' not found.\n", connect_name); | 703 logwrite(LOG_ALERT, "route list with name '%s' not found.\n", connect_name); |
707 return FALSE; | 704 return FALSE; |
708 } | 705 } |
709 | 706 |
710 GList *route_list = read_route_list(rf_list, FALSE); | 707 route_list = read_route_list(rf_list, FALSE); |
711 if (!route_list) { | 708 if (!route_list) { |
712 logwrite(LOG_ALERT, "could not read route list '%s'\n", connect_name); | 709 logwrite(LOG_ALERT, "could not read route list '%s'\n", connect_name); |
713 return FALSE; | 710 return FALSE; |
714 } | 711 } |
715 | 712 |
716 GList *route_node; | 713 /* TODO: Should we stop if the mail was delivered? Dig deeper! */ |
717 foreach(route_list, route_node) { | 714 foreach(route_list, route_node) { |
718 connect_route *route = (connect_route *) (route_node->data); | 715 connect_route *route = (connect_route *) (route_node->data); |
719 /* TODO: ok gets overwritten */ | 716 /* TODO: ok gets overwritten */ |
720 ok = deliver_route_msg_list(route, msgout_list); | 717 ok = deliver_route_msg_list(route, msgout_list); |
721 } | 718 } |
722 destroy_route_list(route_list); | 719 destroy_route_list(route_list); |
723 return ok; | 720 return ok; |
724 } | 721 } |
725 | 722 |
723 /* | |
724 This function searches in the list of rcpt addresses | |
725 for local and 'local net' addresses. Remote addresses | |
726 which are reachable only when online are treated specially | |
727 in another function. | |
728 */ | |
726 gboolean | 729 gboolean |
727 deliver_msg_list(GList * msg_list, guint flags) | 730 deliver_msg_list(GList * msg_list, guint flags) |
728 { | 731 { |
729 GList *msgout_list = create_msg_out_list(msg_list); | 732 GList *msgout_list = create_msg_out_list(msg_list); |
730 GList *local_msgout_list = NULL; | 733 GList *local_msgout_list = NULL; |
852 destroy_msg_out_list(msgout_list); | 855 destroy_msg_out_list(msgout_list); |
853 | 856 |
854 return ok; | 857 return ok; |
855 } | 858 } |
856 | 859 |
857 /* This function searches in the list of rcpt addresses | 860 /* |
858 for local and 'local net' addresses. Remote addresses | |
859 which are reachable only when online are treated specially | |
860 in another function. | |
861 | |
862 deliver() is called when a message has just been received and should | 861 deliver() is called when a message has just been received and should |
863 be delivered immediately. | 862 be delivered immediately. |
864 */ | 863 */ |
865 gboolean | 864 gboolean |
866 deliver(message * msg) | 865 deliver(message * msg) |