comparison src/deliver.c @ 354:08932c629849

reworked the route concept; removed the idea of the localnet Renamed to reflect the actual meaning more clearly: s/online_routes/query_routes/g s/local_net_route/permanent_routes/g Removed local_nets, which are now represented by allowed_recipients in a permanent route. (See. examples/localnet.route) There is no more abiguity between `local' and `local net'. Run admin/config-transition on your config to learn how to update it.
author markus schnalke <meillo@marmaro.de>
date Sun, 04 Sep 2011 11:25:38 +0200
parents 332999b1303f
children 41958685480d
comparison
equal deleted inserted replaced
353:48ff59cf0b34 354:08932c629849
665 665
666 DEBUG(2) debugf("spool header for %s written back.\n", msg->uid); 666 DEBUG(2) debugf("spool header for %s written back.\n", msg->uid);
667 return TRUE; 667 return TRUE;
668 } 668 }
669 669
670 gboolean 670 int
671 deliver_msgout_list_online(GList * msgout_list) 671 deliver_remote(GList* remote_msgout_list)
672 { 672 {
673 int ok = TRUE;
674 GList *route_list = NULL;
675 GList *route_node;
673 GList *rf_list = NULL; 676 GList *rf_list = NULL;
674 gchar *connect_name = NULL; 677 gchar *connect_name = NULL;
675 gboolean ok = FALSE; 678
676 GList *route_node; 679 if (!remote_msgout_list) {
677 GList *route_list; 680 return FALSE;
678 681 }
682
683 /* perma routes */
684 if (conf.perma_routes) {
685 DEBUG(5) debugf("processing perma_routes\n");
686
687 route_list = read_route_list(conf.perma_routes, TRUE);
688 foreach(route_list, route_node) {
689 connect_route *route = (connect_route *) (route_node->data);
690 if (!deliver_route_msg_list(route, remote_msgout_list)) {
691 ok = FALSE;
692 }
693 }
694 destroy_route_list(route_list);
695 }
696
697 /* query routes */
679 connect_name = online_query(); 698 connect_name = online_query();
680 if (!connect_name) { 699 if (!connect_name) {
681 DEBUG(5) debugf("online query returned false\n"); 700 DEBUG(5) debugf("online query returned false\n");
682 return FALSE; 701 return FALSE;
683 } 702 }
684 703
685 /* we are online! */ 704 /* we are online! */
686 DEBUG(5) debugf("processing query_routes\n"); 705 DEBUG(5) debugf("processing query_routes\n");
687 logwrite(LOG_NOTICE, "detected online configuration `%s'\n", connect_name); 706 logwrite(LOG_NOTICE, "detected online configuration `%s'\n", connect_name);
688 707
689 rf_list = (GList *) table_find(conf.connect_routes, connect_name); 708 rf_list = (GList *) table_find(conf.query_routes, connect_name);
690 if (!rf_list) { 709 if (!rf_list) {
691 logwrite(LOG_ALERT, "route list with name '%s' not found.\n", connect_name); 710 logwrite(LOG_ALERT, "route list with name '%s' not found.\n", connect_name);
692 return FALSE; 711 return FALSE;
693 } 712 }
694 713
699 } 718 }
700 719
701 foreach(route_list, route_node) { 720 foreach(route_list, route_node) {
702 connect_route *route = (connect_route *) (route_node->data); 721 connect_route *route = (connect_route *) (route_node->data);
703 /* TODO: ok gets overwritten */ 722 /* TODO: ok gets overwritten */
704 ok = deliver_route_msg_list(route, msgout_list); 723 ok = deliver_route_msg_list(route, remote_msgout_list);
705 } 724 }
706 destroy_route_list(route_list); 725 destroy_route_list(route_list);
707 726
708 return ok; 727 return ok;
709 } 728 }
710 729
711 /* 730 /*
712 This function searches in the list of rcpt addresses 731 This function splits the list of rcpt addresses
713 for local and 'local net' addresses. Remote addresses 732 into local and remote addresses and processes them accordingly.
714 which are reachable only when online are treated specially
715 in another function.
716 */ 733 */
717 gboolean 734 gboolean
718 deliver_msg_list(GList * msg_list, guint flags) 735 deliver_msg_list(GList * msg_list, guint flags)
719 { 736 {
720 GList *msgout_list = NULL; 737 GList *msgout_list = NULL;
721 GList *msg_node; 738 GList *msg_node;
722 GList *local_msgout_list = NULL; 739 GList *local_msgout_list = NULL;
723 GList *localnet_msgout_list = NULL; 740 GList *remote_msgout_list = NULL;
724 GList *other_msgout_list = NULL;
725 GList *msgout_node; 741 GList *msgout_node;
726 GList *alias_table = NULL; 742 GList *alias_table = NULL;
727 gboolean ok = TRUE; 743 gboolean ok = TRUE;
728 744
729 /* create msgout_list */ 745 /* create msgout_list */
730 foreach(msg_list, msg_node) { 746 foreach(msg_list, msg_node) {
731 message *msg = (message *) msg_node->data; 747 message *msg = (message *) msg_node->data;
732 msgout_list = g_list_append(msgout_list, create_msg_out(msg)); 748 msgout_list = g_list_append(msgout_list, create_msg_out(msg));
733 } 749 }
734
735 750
736 if (conf.alias_file) { 751 if (conf.alias_file) {
737 alias_table = table_read(conf.alias_file, ':'); 752 alias_table = table_read(conf.alias_file, ':');
738 } 753 }
739 754
740 /* sort messages for different deliveries */ 755 /* sort messages for different deliveries */
741 foreach(msgout_list, msgout_node) { 756 foreach(msgout_list, msgout_node) {
742 msg_out *msgout = (msg_out *) (msgout_node->data); 757 msg_out *msgout = (msg_out *) (msgout_node->data);
743 GList *rcpt_list; 758 GList *rcpt_list;
744 GList *local_rcpt_list = NULL; 759 GList *local_rcpt_list = NULL;
745 GList *localnet_rcpt_list = NULL;
746 GList *other_rcpt_list = NULL; 760 GList *other_rcpt_list = NULL;
747 761
748 if (!spool_lock(msgout->msg->uid)) { 762 if (!spool_lock(msgout->msg->uid)) {
749 DEBUG(5) debugf("spool_lock(%s) failed.\n", msgout->msg->uid); 763 DEBUG(5) debugf("spool_lock(%s) failed.\n", msgout->msg->uid);
750 continue; 764 continue;
765 aliased_rcpt_list = alias_expand(alias_table, rcpt_list, msgout->msg->non_rcpt_list); 779 aliased_rcpt_list = alias_expand(alias_table, rcpt_list, msgout->msg->non_rcpt_list);
766 g_list_free(rcpt_list); 780 g_list_free(rcpt_list);
767 rcpt_list = aliased_rcpt_list; 781 rcpt_list = aliased_rcpt_list;
768 } 782 }
769 783
770 split_rcpts(rcpt_list, conf.local_nets, &local_rcpt_list, &localnet_rcpt_list, &other_rcpt_list); 784 /* split_rcpts(rcpt_list, NULL, &local_rcpt_list, * NULL, &other_rcpt_list); */
785 local_rcpt_list = local_rcpts(rcpt_list);
786 other_rcpt_list = remote_rcpts(rcpt_list);
771 g_list_free(rcpt_list); 787 g_list_free(rcpt_list);
772 788
773 /* local recipients */ 789 /* local recipients */
774 if ((flags & DLVR_LOCAL) && local_rcpt_list) { 790 if ((flags & DLVR_LOCAL) && local_rcpt_list) {
775 msg_out *local_msgout = clone_msg_out(msgout); 791 msg_out *local_msgout = clone_msg_out(msgout);
776 local_msgout->rcpt_list = local_rcpt_list; 792 local_msgout->rcpt_list = local_rcpt_list;
777 local_msgout_list = g_list_append(local_msgout_list, local_msgout); 793 local_msgout_list = g_list_append(local_msgout_list, local_msgout);
778 } 794 }
779 795
780 /* local net recipients */ 796 /* remote recipients, requires online delivery */
781 if ((flags & DLVR_LAN) && localnet_rcpt_list) {
782 msg_out *localnet_msgout = clone_msg_out(msgout);
783 localnet_msgout->rcpt_list = localnet_rcpt_list;
784 localnet_msgout_list = g_list_append(localnet_msgout_list, localnet_msgout);
785 }
786
787 /* remote recipients (the rest), requires online delivery */
788 if ((flags & DLVR_ONLINE) && other_rcpt_list) { 797 if ((flags & DLVR_ONLINE) && other_rcpt_list) {
789 msg_out *other_msgout = clone_msg_out(msgout); 798 msg_out *remote_msgout = clone_msg_out(msgout);
790 other_msgout->rcpt_list = other_rcpt_list; 799 remote_msgout->rcpt_list = other_rcpt_list;
791 other_msgout_list = g_list_append(other_msgout_list, other_msgout); 800 remote_msgout_list = g_list_append(remote_msgout_list, remote_msgout);
792 } 801 }
793 } 802 }
794 803
795 if (alias_table) { 804 if (alias_table) {
796 destroy_table(alias_table); 805 destroy_table(alias_table);
797 } 806 }
798 807
799 /* actual delivery */ 808 /* process local/remote msgout lists -> delivery */
800 809
801 if (local_msgout_list) { 810 if (local_msgout_list) {
802 DEBUG(5) debugf("local_msgout_list\n"); 811 DEBUG(5) debugf("local_msgout_list\n");
803 foreach(local_msgout_list, msgout_node) { 812 foreach(local_msgout_list, msgout_node) {
804 msg_out *msgout = (msg_out *) (msgout_node->data); 813 msg_out *msgout = (msg_out *) (msgout_node->data);
807 } 816 }
808 } 817 }
809 destroy_msg_out_list(local_msgout_list); 818 destroy_msg_out_list(local_msgout_list);
810 } 819 }
811 820
812 if (localnet_msgout_list) { 821 if (remote_msgout_list) {
813 GList *route_list = NULL; 822 DEBUG(5) debugf("remote_msgout_list\n");
814 GList *route_node; 823 deliver_remote(remote_msgout_list);
815 824 destroy_msg_out_list(remote_msgout_list);
816 DEBUG(5) debugf("localnet_msgout_list\n");
817 if (conf.local_net_routes) {
818 route_list = read_route_list(conf.local_net_routes, TRUE);
819 } else {
820 route_list = g_list_append(NULL, create_local_route());
821 }
822
823 foreach(route_list, route_node) {
824 connect_route *route = (connect_route *) (route_node->data);
825 if (!deliver_route_msg_list(route, localnet_msgout_list)) {
826 ok = FALSE;
827 }
828 }
829 destroy_msg_out_list(localnet_msgout_list);
830 destroy_route_list(route_list);
831 }
832
833 if (other_msgout_list) {
834 DEBUG(5) debugf("other_msgout_list\n");
835 if (!deliver_msgout_list_online(other_msgout_list)) {
836 ok = FALSE;
837 }
838 destroy_msg_out_list(other_msgout_list);
839 } 825 }
840 826
841 /* unlock spool files */ 827 /* unlock spool files */
842 foreach(msgout_list, msgout_node) { 828 foreach(msgout_list, msgout_node) {
843 msg_out *msgout = (msg_out *) (msgout_node->data); 829 msg_out *msgout = (msg_out *) (msgout_node->data);