comparison src/deliver.c @ 404:899c97e877a5

Broke long lines.
author markus schnalke <meillo@marmaro.de>
date Wed, 29 Feb 2012 10:21:58 +0100
parents 7954b82040b3
children 8fedb93e9b72
comparison
equal deleted inserted replaced
403:7954b82040b3 404:899c97e877a5
417 foreach(msgout_list, msgout_node) { 417 foreach(msgout_list, msgout_node) {
418 msg_out *msgout = (msg_out *) (msgout_node->data); 418 msg_out *msgout = (msg_out *) (msgout_node->data);
419 GList *rcpt_node; 419 GList *rcpt_node;
420 420
421 for (rcpt_node = g_list_first(msgout->rcpt_list); 421 for (rcpt_node = g_list_first(msgout->rcpt_list);
422 rcpt_node; 422 rcpt_node;
423 rcpt_node = g_list_next(rcpt_node)) { 423 rcpt_node = g_list_next(rcpt_node)) {
424 address *rcpt = (address *) (rcpt_node->data); 424 address *rcpt = (address *) (rcpt_node->data);
425 gboolean ret = FALSE; 425 gboolean ret = FALSE;
426 426
427 addr_unmark_delivered(rcpt); 427 addr_unmark_delivered(rcpt);
428 if (route->connect_error_fail) { 428 if (route->connect_error_fail) {
429 addr_mark_failed(rcpt); 429 addr_mark_failed(rcpt);
430 } else { 430 } else {
431 addr_mark_defered(rcpt); 431 addr_mark_defered(rcpt);
432 } 432 }
433 if (route->wrapper) { 433 if (route->wrapper) {
434 ret = delivery_failures(msgout->msg, msgout->rcpt_list, "could not open wrapper:\n\t%s", strerror(errno)); 434 ret = delivery_failures(msgout->msg,
435 msgout->rcpt_list,
436 "could not open "
437 "wrapper:\n\t%s",
438 strerror(errno));
435 } else { 439 } else {
436 ret = delivery_failures(msgout->msg, msgout->rcpt_list, "could not open connection to %s:%d :\n\t%s", host, port, h_errno != 0 ? hstrerror(h_errno) : strerror(errno)); 440 ret = delivery_failures(msgout->msg,
441 msgout->rcpt_list,
442 "could not open "
443 "connection to %s:%d "
444 ":\n\t%s", host, port,
445 h_errno != 0 ?
446 hstrerror(h_errno) :
447 strerror(errno));
437 } 448 }
438 if (ret) { 449 if (ret) {
439 deliver_finish(msgout); 450 deliver_finish(msgout);
440 } 451 }
441 } 452 }
442 } 453 }
443 return ok; 454 return ok;
444 } 455 }
445 456
446 set_heloname(psb, route->helo_name ? route->helo_name : conf.host_name, route->do_correct_helo); 457 set_heloname(psb, route->helo_name ? route->helo_name : conf.host_name,
458 route->do_correct_helo);
447 459
448 #ifdef ENABLE_AUTH 460 #ifdef ENABLE_AUTH
449 if (route->auth_name && route->auth_login && route->auth_secret) { 461 if (route->auth_name && route->auth_login && route->auth_secret) {
450 set_auth(psb, route->auth_name, route->auth_login, route->auth_secret); 462 set_auth(psb, route->auth_name, route->auth_login,
463 route->auth_secret);
451 } 464 }
452 #endif 465 #endif
453 if (!smtp_out_init(psb, route->instant_helo)) { 466 if (!smtp_out_init(psb, route->instant_helo)) {
454 /* smtp_out_init() failed */ 467 /* smtp_out_init() failed */
455 if ((psb->error==smtp_fail) || (psb->error==smtp_trylater) || (psb->error==smtp_syntax)) { 468 if ((psb->error==smtp_fail) || (psb->error==smtp_trylater) ||
469 (psb->error==smtp_syntax)) {
456 smtp_out_quit(psb); 470 smtp_out_quit(psb);
457 471
458 foreach(msgout_list, msgout_node) { 472 foreach(msgout_list, msgout_node) {
459 msg_out *msgout = (msg_out *) (msgout_node->data); 473 msg_out *msgout =
474 (msg_out *)(msgout_node->data);
460 smtp_out_mark_rcpts(psb, msgout->rcpt_list); 475 smtp_out_mark_rcpts(psb, msgout->rcpt_list);
461 476
462 if (delivery_failures(msgout->msg, msgout->rcpt_list, "while connected with %s, the server replied\n\t%s", (route->wrapper) ? "<wrapper>" : host, psb->buffer)) { 477 if (delivery_failures(msgout->msg,
478 msgout->rcpt_list,
479 "while connected with %s, "
480 "the server replied\n\t%s",
481 (route->wrapper) ?
482 "<wrapper>" : host,
483 psb->buffer)) {
463 deliver_finish(msgout); 484 deliver_finish(msgout);
464 } 485 }
465 } 486 }
466 } 487 }
467 destroy_smtpbase(psb); 488 destroy_smtpbase(psb);
475 foreach(msgout_list, msgout_node) { 496 foreach(msgout_list, msgout_node) {
476 msg_out *msgout = (msg_out *) (msgout_node->data); 497 msg_out *msgout = (msg_out *) (msgout_node->data);
477 gboolean flag, ok_msg = FALSE, ok_fail = FALSE; 498 gboolean flag, ok_msg = FALSE, ok_fail = FALSE;
478 message *msg = msgout->msg; 499 message *msg = msgout->msg;
479 500
480 /* we may have to read the data at this point and remember if we did */ 501 /* we may have to read the data at this point
502 ** and remember if we did */
481 flag = (msg->data_list == NULL); 503 flag = (msg->data_list == NULL);
482 if (flag && !spool_read_data(msg)) { 504 if (flag && !spool_read_data(msg)) {
483 logwrite(LOG_ALERT, "could not open data spool file %s\n", msg->uid); 505 logwrite(LOG_ALERT, "could not open data spool "
506 "file %s\n", msg->uid);
484 break; 507 break;
485 } 508 }
486 509
487 smtp_out_msg(psb, msg, msgout->return_path, msgout->rcpt_list, msgout->hdr_list); 510 smtp_out_msg(psb, msg, msgout->return_path, msgout->rcpt_list,
488 511 msgout->hdr_list);
489 ok_fail = delivery_failures(msg, msgout->rcpt_list, "while connected with %s, the server replied\n\t%s", (route->wrapper) ? "<wrapper>" : host, psb->buffer); 512
513 ok_fail = delivery_failures(msg, msgout->rcpt_list,
514 "while connected with %s, the server "
515 "replied\n\t%s", (route->wrapper) ?
516 "<wrapper>" : host, psb->buffer);
490 517
491 if ((psb->error == smtp_eof) || (psb->error == smtp_timeout)) { 518 if ((psb->error == smtp_eof) || (psb->error == smtp_timeout)) {
492 /* connection lost */ 519 /* connection lost */
493 break; 520 break;
494 } else if (psb->error != smtp_ok) { 521 } else if (psb->error != smtp_ok) {
506 } 533 }
507 if (ok_msg || ok_fail) { 534 if (ok_msg || ok_fail) {
508 deliver_finish(msgout); 535 deliver_finish(msgout);
509 } 536 }
510 } 537 }
511 if (psb->error == smtp_ok || (psb->error == smtp_fail) 538 if (psb->error == smtp_ok || (psb->error == smtp_fail) ||
512 || (psb->error == smtp_trylater) || (psb->error == smtp_syntax)) { 539 (psb->error == smtp_trylater) ||
540 (psb->error == smtp_syntax)) {
513 smtp_out_quit(psb); 541 smtp_out_quit(psb);
514 } 542 }
515 destroy_smtpbase(psb); 543 destroy_smtpbase(psb);
516 return ok; 544 return ok;
517 } 545 }
521 GList *res_list) 549 GList *res_list)
522 { 550 {
523 551
524 if (route->pipe) { 552 if (route->pipe) {
525 DEBUG(5) debugf("with pipe\n"); 553 DEBUG(5) debugf("with pipe\n");
526 return deliver_msglist_host_pipe(route, msgout_list, host, res_list); 554 return deliver_msglist_host_pipe(route, msgout_list,
555 host, res_list);
527 } else { 556 } else {
528 DEBUG(5) debugf("with smtp\n"); 557 DEBUG(5) debugf("with smtp\n");
529 return deliver_msglist_host_smtp(route, msgout_list, host, res_list); 558 return deliver_msglist_host_smtp(route, msgout_list,
559 host, res_list);
530 } 560 }
531 } 561 }
532 562
533 /* 563 /*
534 ** delivers messages in msgout_list using route 564 ** delivers messages in msgout_list using route
538 { 568 {
539 gboolean ok = FALSE; 569 gboolean ok = FALSE;
540 GList *mo_ph_list; 570 GList *mo_ph_list;
541 GList *mo_ph_node; 571 GList *mo_ph_node;
542 572
543 DEBUG(5) debugf("deliver_route_msgout_list entered, route->name = %s\n", route->name); 573 DEBUG(5) debugf("deliver_route_msgout_list entered, route->name=%s\n",
574 route->name);
544 575
545 if (route->mail_host) { 576 if (route->mail_host) {
546 /* this is easy... deliver everything to a smart host for relay */ 577 /* easy: deliver everything to a smart host for relay */
547 return deliver_msglist_host(route, msgout_list, NULL, 578 return deliver_msglist_host(route, msgout_list, NULL,
548 route->resolve_list); 579 route->resolve_list);
549 } 580 }
550 581
551 /* this is not easy... */ 582 /* this is not easy... */
602 address *rcpt = (address *) (rcpt_node->data); 633 address *rcpt = (address *) (rcpt_node->data);
603 /* 634 /*
604 ** failed addresses already have been bounced; 635 ** failed addresses already have been bounced;
605 ** there should be a better way to handle those. 636 ** there should be a better way to handle those.
606 */ 637 */
607 if (!addr_is_delivered(rcpt) && !addr_is_failed(rcpt) 638 if (!addr_is_delivered(rcpt) &&
608 && !(rcpt->flags & ADDR_FLAG_LAST_ROUTE)) { 639 !addr_is_failed(rcpt) &&
640 !(rcpt->flags & ADDR_FLAG_LAST_ROUTE)){
609 rcpt_list_non_delivered = g_list_append(rcpt_list_non_delivered, rcpt); 641 rcpt_list_non_delivered = g_list_append(rcpt_list_non_delivered, rcpt);
610 } 642 }
611 } 643 }
612 g_list_free(msgout_cloned->rcpt_list); 644 g_list_free(msgout_cloned->rcpt_list);
613 msgout_cloned->rcpt_list = rcpt_list_non_delivered; 645 msgout_cloned->rcpt_list = rcpt_list_non_delivered;
616 destroy_msg_out(msgout_cloned); 648 destroy_msg_out(msgout_cloned);
617 continue; 649 continue;
618 } 650 }
619 651
620 /* filter by allowed envelope sender */ 652 /* filter by allowed envelope sender */
621 if (!route_sender_is_allowed(route, msgout->msg->return_path)) { 653 if (!route_sender_is_allowed(route, msgout->msg->return_path)){
622 DEBUG(6) debugf("sender `%s' is not allowed for this route\n", msgout->msg->return_path); 654 DEBUG(6) debugf("sender `%s' is not allowed for this "
655 "route\n", msgout->msg->return_path);
623 destroy_msg_out(msgout_cloned); 656 destroy_msg_out(msgout_cloned);
624 continue; 657 continue;
625 } 658 }
626 659
627 /* filter by allowed envelope rcpts */ 660 /* filter by allowed envelope rcpts */
647 rcpt->flags |= ADDR_FLAG_LAST_ROUTE; 680 rcpt->flags |= ADDR_FLAG_LAST_ROUTE;
648 } 681 }
649 } 682 }
650 683
651 route_prepare_msgout(route, msgout_cloned); 684 route_prepare_msgout(route, msgout_cloned);
652 msgout_list_deliver = g_list_append(msgout_list_deliver, msgout_cloned); 685 msgout_list_deliver = g_list_append(msgout_list_deliver,
686 msgout_cloned);
653 } 687 }
654 688
655 if (msgout_list_deliver) { 689 if (msgout_list_deliver) {
656 if (deliver_route_msgout_list(route, msgout_list_deliver)) { 690 if (deliver_route_msgout_list(route, msgout_list_deliver)) {
657 ok = TRUE; 691 ok = TRUE;
672 message *msg = msgout->msg; 706 message *msg = msgout->msg;
673 707
674 foreach(msgout->rcpt_list, rcpt_node) { 708 foreach(msgout->rcpt_list, rcpt_node) {
675 address *rcpt = (address *) (rcpt_node->data); 709 address *rcpt = (address *) (rcpt_node->data);
676 if (addr_is_delivered(rcpt) || addr_is_failed(rcpt)) { 710 if (addr_is_delivered(rcpt) || addr_is_failed(rcpt)) {
677 msg->non_rcpt_list = g_list_append(msg->non_rcpt_list, rcpt); 711 msg->non_rcpt_list = g_list_append(msg->non_rcpt_list,
712 rcpt);
678 } 713 }
679 } 714 }
680 } 715 }
681 716
682 /* 717 /*
727 return FALSE; 762 return FALSE;
728 } 763 }
729 764
730 /* one not delivered address was found */ 765 /* one not delivered address was found */
731 if (!spool_write(msg, FALSE)) { 766 if (!spool_write(msg, FALSE)) {
732 logwrite(LOG_ALERT, "could not write back spool header for %s\n", msg->uid); 767 logwrite(LOG_ALERT, "could not write back spool header "
768 "for %s\n", msg->uid);
733 return FALSE; 769 return FALSE;
734 } 770 }
735 771
736 DEBUG(2) debugf("spool header for %s written back.\n", msg->uid); 772 DEBUG(2) debugf("spool header for %s written back.\n", msg->uid);
737 return TRUE; 773 return TRUE;
754 if (conf.perma_routes) { 790 if (conf.perma_routes) {
755 DEBUG(5) debugf("processing perma_routes\n"); 791 DEBUG(5) debugf("processing perma_routes\n");
756 792
757 route_list = read_route_list(conf.perma_routes, TRUE); 793 route_list = read_route_list(conf.perma_routes, TRUE);
758 foreach(route_list, route_node) { 794 foreach(route_list, route_node) {
759 connect_route *route = (connect_route *) (route_node->data); 795 connect_route *route =
760 if (!deliver_route_msg_list(route, remote_msgout_list)) { 796 (connect_route *) (route_node->data);
797 if (!deliver_route_msg_list(route,
798 remote_msgout_list)) {
761 ok = FALSE; 799 ok = FALSE;
762 } 800 }
763 } 801 }
764 destroy_route_list(route_list); 802 destroy_route_list(route_list);
765 } 803 }
771 return FALSE; 809 return FALSE;
772 } 810 }
773 811
774 /* we are online! */ 812 /* we are online! */
775 DEBUG(5) debugf("processing query_routes\n"); 813 DEBUG(5) debugf("processing query_routes\n");
776 logwrite(LOG_NOTICE, "detected online configuration `%s'\n", connect_name); 814 logwrite(LOG_NOTICE, "detected online configuration `%s'\n",
815 connect_name);
777 816
778 rf_list = (GList *) table_find(conf.query_routes, connect_name); 817 rf_list = (GList *) table_find(conf.query_routes, connect_name);
779 if (!rf_list) { 818 if (!rf_list) {
780 logwrite(LOG_ALERT, "route list with name '%s' not found.\n", connect_name); 819 logwrite(LOG_ALERT, "route list with name '%s' not found.\n",
820 connect_name);
781 return FALSE; 821 return FALSE;
782 } 822 }
783 823
784 route_list = read_route_list(rf_list, FALSE); 824 route_list = read_route_list(rf_list, FALSE);
785 if (!route_list) { 825 if (!route_list) {
786 logwrite(LOG_ALERT, "could not read route list '%s'\n", connect_name); 826 logwrite(LOG_ALERT, "could not read route list '%s'\n",
827 connect_name);
787 return FALSE; 828 return FALSE;
788 } 829 }
789 830
790 foreach(route_list, route_node) { 831 foreach(route_list, route_node) {
791 connect_route *route = (connect_route *) (route_node->data); 832 connect_route *route = (connect_route *) (route_node->data);
832 GList *rcpt_list; 873 GList *rcpt_list;
833 GList *local_rcpt_list = NULL; 874 GList *local_rcpt_list = NULL;
834 GList *other_rcpt_list = NULL; 875 GList *other_rcpt_list = NULL;
835 876
836 if (!spool_lock(msgout->msg->uid)) { 877 if (!spool_lock(msgout->msg->uid)) {
837 DEBUG(5) debugf("spool_lock(%s) failed.\n", msgout->msg->uid); 878 DEBUG(5) debugf("spool_lock(%s) failed.\n",
879 msgout->msg->uid);
838 continue; 880 continue;
839 } 881 }
840 DEBUG(5) debugf("spool_lock(%s)\n", msgout->msg->uid); 882 DEBUG(5) debugf("spool_lock(%s)\n", msgout->msg->uid);
841 883
842 rcpt_list = g_list_copy(msgout->msg->rcpt_list); 884 rcpt_list = g_list_copy(msgout->msg->rcpt_list);
843 if (conf.log_user) { 885 if (conf.log_user) {
844 address *addr = create_address_qualified(conf.log_user, TRUE, conf.host_name); 886 address *addr = create_address_qualified(conf.log_user,
887 TRUE, conf.host_name);
845 if (addr) { 888 if (addr) {
846 rcpt_list = g_list_prepend(rcpt_list, addr); 889 rcpt_list = g_list_prepend(rcpt_list, addr);
847 } else { 890 } else {
848 logwrite(LOG_ALERT, "invalid log_user address `%s', ignoring\n", conf.log_user); 891 logwrite(LOG_ALERT, "invalid log_user "
892 "address `%s', ignoring\n",
893 conf.log_user);
849 } 894 }
850 } 895 }
851 if (globalias_table) { 896 if (globalias_table) {
852 GList *globaliased_rcpt_list; 897 GList *globaliased_rcpt_list;
853 globaliased_rcpt_list = alias_expand(globalias_table, 898 globaliased_rcpt_list = alias_expand(globalias_table,
863 msgout->msg->non_rcpt_list, 0); 908 msgout->msg->non_rcpt_list, 0);
864 g_list_free(rcpt_list); 909 g_list_free(rcpt_list);
865 rcpt_list = aliased_rcpt_list; 910 rcpt_list = aliased_rcpt_list;
866 } 911 }
867 912
868 /* split_rcpts(rcpt_list, NULL, &local_rcpt_list, NULL, &other_rcpt_list); */ 913 /* split_rcpts(rcpt_list, NULL, &local_rcpt_list, NULL,
914 ** &other_rcpt_list); */
869 local_rcpt_list = local_rcpts(rcpt_list); 915 local_rcpt_list = local_rcpts(rcpt_list);
870 other_rcpt_list = remote_rcpts(rcpt_list); 916 other_rcpt_list = remote_rcpts(rcpt_list);
871 g_list_free(rcpt_list); 917 g_list_free(rcpt_list);
872 918
873 /* local recipients */ 919 /* local recipients */
874 if ((flags & DLVR_LOCAL) && local_rcpt_list) { 920 if ((flags & DLVR_LOCAL) && local_rcpt_list) {
875 msg_out *local_msgout = clone_msg_out(msgout); 921 msg_out *local_msgout = clone_msg_out(msgout);
876 local_msgout->rcpt_list = local_rcpt_list; 922 local_msgout->rcpt_list = local_rcpt_list;
877 local_msgout_list = g_list_append(local_msgout_list, local_msgout); 923 local_msgout_list = g_list_append(local_msgout_list,
924 local_msgout);
878 } 925 }
879 926
880 /* remote recipients, requires online delivery */ 927 /* remote recipients, requires online delivery */
881 if ((flags & DLVR_ONLINE) && other_rcpt_list) { 928 if ((flags & DLVR_ONLINE) && other_rcpt_list) {
882 msg_out *remote_msgout = clone_msg_out(msgout); 929 msg_out *remote_msgout = clone_msg_out(msgout);
883 remote_msgout->rcpt_list = other_rcpt_list; 930 remote_msgout->rcpt_list = other_rcpt_list;
884 remote_msgout_list = g_list_append(remote_msgout_list, remote_msgout); 931 remote_msgout_list = g_list_append(remote_msgout_list,
932 remote_msgout);
885 } 933 }
886 } 934 }
887 935
888 if (alias_table) { 936 if (alias_table) {
889 destroy_table(alias_table); 937 destroy_table(alias_table);
913 961
914 /* unlock spool files */ 962 /* unlock spool files */
915 foreach(msgout_list, msgout_node) { 963 foreach(msgout_list, msgout_node) {
916 msg_out *msgout = (msg_out *) (msgout_node->data); 964 msg_out *msgout = (msg_out *) (msgout_node->data);
917 if (spool_unlock(msgout->msg->uid)) { 965 if (spool_unlock(msgout->msg->uid)) {
918 DEBUG(5) debugf("spool_unlock(%s)\n", msgout->msg->uid); 966 DEBUG(5) debugf("spool_unlock(%s)\n",
967 msgout->msg->uid);
919 } else { 968 } else {
920 DEBUG(5) debugf("spool_unlock(%s) failed.\n", msgout->msg->uid); 969 DEBUG(5) debugf("spool_unlock(%s) failed.\n",
970 msgout->msg->uid);
921 } 971 }
922 } 972 }
923 destroy_msg_out_list(msgout_list); 973 destroy_msg_out_list(msgout_list);
924 974
925 return ok; 975 return ok;