comparison 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
comparison
equal deleted inserted replaced
9:31cc8a89cb74 10:26e34ae9a3e3
17 */ 17 */
18 18
19 #include "masqmail.h" 19 #include "masqmail.h"
20 #include <fnmatch.h> 20 #include <fnmatch.h>
21 21
22 msgout_perhost *create_msgout_perhost(gchar *host) 22 msgout_perhost*
23 { 23 create_msgout_perhost(gchar * host)
24 msgout_perhost *mo_ph = g_malloc(sizeof(msgout_perhost)); 24 {
25 if(mo_ph){ 25 msgout_perhost *mo_ph = g_malloc(sizeof(msgout_perhost));
26 mo_ph->host = g_strdup(host); 26 if (mo_ph) {
27 mo_ph->msgout_list = NULL; 27 mo_ph->host = g_strdup(host);
28 } 28 mo_ph->msgout_list = NULL;
29 return mo_ph; 29 }
30 } 30 return mo_ph;
31 31 }
32 void destroy_msgout_perhost(msgout_perhost *mo_ph) 32
33 { 33 void
34 GList *mo_node; 34 destroy_msgout_perhost(msgout_perhost * mo_ph)
35 35 {
36 foreach(mo_ph->msgout_list, mo_node){ 36 GList *mo_node;
37 msg_out *mo = (msg_out *)(mo_node->data); 37
38 /* the rcpt_list is owned by the msgout's, 38 foreach(mo_ph->msgout_list, mo_node) {
39 but not the rcpt's themselves */ 39 msg_out *mo = (msg_out *) (mo_node->data);
40 g_list_free(mo->rcpt_list); 40 /* the rcpt_list is owned by the msgout's, but not the rcpt's themselves */
41 g_free(mo); 41 g_list_free(mo->rcpt_list);
42 } 42 g_free(mo);
43 g_list_free(mo_ph->msgout_list); 43 }
44 g_free(mo_ph); 44 g_list_free(mo_ph->msgout_list);
45 } 45 g_free(mo_ph);
46 46 }
47 void rewrite_headers(msg_out *msgout, connect_route *route) 47
48 { 48 void
49 /* if set_h_from_domain is set, replace domain in all 49 rewrite_headers(msg_out * msgout, connect_route * route)
50 From: headers. 50 {
51 */ 51 /* if set_h_from_domain is set, replace domain in all
52 msgout->hdr_list = g_list_copy(msgout->msg->hdr_list); 52 From: headers.
53 53 */
54 /* map from addresses */ 54 msgout->hdr_list = g_list_copy(msgout->msg->hdr_list);
55 if(route->map_h_from_addresses != NULL){ 55
56 GList *hdr_node; 56 /* map from addresses */
57 foreach(msgout->hdr_list, hdr_node){ 57 if (route->map_h_from_addresses != NULL) {
58 header *hdr = (header *)(hdr_node->data); 58 GList *hdr_node;
59 if(hdr->id == HEAD_FROM){ 59 foreach(msgout->hdr_list, hdr_node) {
60 header *new_hdr = copy_header(hdr); 60 header *hdr = (header *) (hdr_node->data);
61 if(map_address_header(new_hdr, route->map_h_from_addresses)){ 61 if (hdr->id == HEAD_FROM) {
62 hdr_node->data = new_hdr; 62 header *new_hdr = copy_header(hdr);
63 /* we need this list only to carefully free the extra headers: */ 63 if (map_address_header(new_hdr, route->map_h_from_addresses)) {
64 msgout->xtra_hdr_list = 64 hdr_node->data = new_hdr;
65 g_list_append(msgout->xtra_hdr_list, new_hdr); 65 /* we need this list only to carefully free the extra headers: */
66 }else 66 msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
67 g_free(new_hdr); 67 } else
68 } 68 g_free(new_hdr);
69 } 69 }
70 }else{ 70 }
71 /* replace from domain */ 71 } else {
72 if(route->set_h_from_domain != NULL){ 72 /* replace from domain */
73 GList *hdr_node; 73 if (route->set_h_from_domain != NULL) {
74 74 GList *hdr_node;
75 foreach(msgout->hdr_list, hdr_node){ 75
76 header *hdr = (header *)(hdr_node->data); 76 foreach(msgout->hdr_list, hdr_node) {
77 if(hdr->id == HEAD_FROM){ 77 header *hdr = (header *) (hdr_node->data);
78 header *new_hdr = copy_header(hdr); 78 if (hdr->id == HEAD_FROM) {
79 79 header *new_hdr = copy_header(hdr);
80 DEBUG(5) debugf("setting From: domain to %s\n", 80
81 route->set_h_from_domain); 81 DEBUG(5) debugf("setting From: domain to %s\n", route->set_h_from_domain);
82 if(set_address_header_domain(new_hdr, route->set_h_from_domain)){ 82 if (set_address_header_domain(new_hdr, route->set_h_from_domain)) {
83 hdr_node->data = new_hdr; 83 hdr_node->data = new_hdr;
84 /* we need this list only to carefully free the extra headers: */ 84 /* we need this list only to carefully free the extra headers: */
85 DEBUG(6) debugf("header = %s\n", 85 DEBUG(6) debugf("header = %s\n", new_hdr->header);
86 new_hdr->header); 86 msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
87 msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr); 87 } else {
88 }else{ 88 logwrite(LOG_ALERT, "error in set_address_header_domain(%s, %s)\n", new_hdr->value, route->set_h_from_domain);
89 logwrite(LOG_ALERT, "error in set_address_header_domain(%s, %s)\n", 89 }
90 new_hdr->value, route->set_h_from_domain); 90 }
91 } 91 }
92 } 92 }
93 } 93 }
94 } 94
95 } 95 /* map reply-to addresses */
96 96 if (route->map_h_reply_to_addresses != NULL) {
97 /* map reply-to addresses */ 97 GList *hdr_node;
98 if(route->map_h_reply_to_addresses != NULL){ 98 foreach(msgout->hdr_list, hdr_node) {
99 GList *hdr_node; 99 header *hdr = (header *) (hdr_node->data);
100 foreach(msgout->hdr_list, hdr_node){ 100 if (hdr->id == HEAD_REPLY_TO) {
101 header *hdr = (header *)(hdr_node->data); 101 header *new_hdr = copy_header(hdr);
102 if(hdr->id == HEAD_REPLY_TO){ 102 if (map_address_header
103 header *new_hdr = copy_header(hdr); 103 (new_hdr, route->map_h_reply_to_addresses)) {
104 if(map_address_header(new_hdr, route->map_h_reply_to_addresses)){ 104 hdr_node->data = new_hdr;
105 hdr_node->data = new_hdr; 105 /* we need this list only to carefully free the extra headers: */
106 /* we need this list only to carefully free the extra headers: */ 106 msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
107 msgout->xtra_hdr_list = 107 } else
108 g_list_append(msgout->xtra_hdr_list, new_hdr); 108 g_free(new_hdr);
109 }else 109 }
110 g_free(new_hdr); 110 }
111 } 111 } else {
112 } 112 /* replace Reply-to domain */
113 }else{ 113 if (route->set_h_reply_to_domain != NULL) {
114 /* replace Reply-to domain */ 114 GList *hdr_node;
115 if(route->set_h_reply_to_domain != NULL){ 115
116 GList *hdr_node; 116 foreach(msgout->hdr_list, hdr_node) {
117 117 header *hdr = (header *) (hdr_node->data);
118 foreach(msgout->hdr_list, hdr_node){ 118 if (hdr->id == HEAD_REPLY_TO) {
119 header *hdr = (header *)(hdr_node->data); 119 header *new_hdr = copy_header(hdr);
120 if(hdr->id == HEAD_REPLY_TO){ 120
121 header *new_hdr = copy_header(hdr); 121 set_address_header_domain(new_hdr, route-> set_h_reply_to_domain);
122 122 hdr_node->data = new_hdr;
123 set_address_header_domain(new_hdr, route->set_h_reply_to_domain); 123 /* we need this list only to carefully free the extra headers: */
124 hdr_node->data = new_hdr; 124 msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
125 /* we need this list only to carefully free the extra headers: */ 125 }
126 msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr); 126 }
127 } 127 }
128 } 128 }
129 } 129
130 } 130 /* map Mail-Followup-To addresses */
131 131 if (route->map_h_mail_followup_to_addresses != NULL) {
132 /* map Mail-Followup-To addresses */ 132 GList *hdr_node;
133 if(route->map_h_mail_followup_to_addresses != NULL){ 133 foreach(msgout->hdr_list, hdr_node) {
134 GList *hdr_node; 134 header *hdr = (header *) (hdr_node->data);
135 foreach(msgout->hdr_list, hdr_node){ 135 if (strncasecmp(hdr->header, "Mail-Followup-To", 16) == 0) {
136 header *hdr = (header *)(hdr_node->data); 136 header *new_hdr = copy_header(hdr);
137 if(strncasecmp(hdr->header, "Mail-Followup-To", 16) == 0){ 137 if (map_address_header(new_hdr, route->map_h_mail_followup_to_addresses)) {
138 header *new_hdr = copy_header(hdr); 138 hdr_node->data = new_hdr;
139 if(map_address_header(new_hdr, route->map_h_mail_followup_to_addresses)){ 139 /* we need this list only to carefully free the extra headers: */
140 hdr_node->data = new_hdr; 140 msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
141 /* we need this list only to carefully free the extra headers: */ 141 } else
142 msgout->xtra_hdr_list = 142 g_free(new_hdr);
143 g_list_append(msgout->xtra_hdr_list, new_hdr); 143 }
144 }else 144 }
145 g_free(new_hdr); 145 }
146 } 146
147 } 147 /* set Sender: domain to return_path->domain */
148 } 148 if (route->expand_h_sender_domain) {
149 149 GList *hdr_node;
150 /* set Sender: domain to return_path->domain */ 150
151 if(route->expand_h_sender_domain){ 151 foreach(msgout->hdr_list, hdr_node) {
152 GList *hdr_node; 152 header *hdr = (header *) (hdr_node->data);
153 153 if (hdr->id == HEAD_SENDER) {
154 foreach(msgout->hdr_list, hdr_node){ 154 header *new_hdr = copy_header(hdr);
155 header *hdr = (header *)(hdr_node->data); 155
156 if(hdr->id == HEAD_SENDER){ 156 set_address_header_domain(new_hdr, msgout->return_path->domain);
157 header *new_hdr = copy_header(hdr); 157 hdr_node->data = new_hdr;
158 158 /* we need this list only to carefully free the extra headers: */
159 set_address_header_domain(new_hdr, msgout->return_path->domain); 159 msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
160 hdr_node->data = new_hdr; 160 }
161 /* we need this list only to carefully free the extra headers: */ 161 }
162 msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr); 162 }
163 } 163
164 } 164 /* set Sender: domain to return_path->domain */
165 } 165 if (route->expand_h_sender_address) {
166 166 GList *hdr_node;
167 /* set Sender: domain to return_path->domain */ 167
168 if(route->expand_h_sender_address){ 168 foreach(msgout->hdr_list, hdr_node) {
169 GList *hdr_node; 169 header *hdr = (header *) (hdr_node->data);
170 170 if (hdr->id == HEAD_SENDER) {
171 foreach(msgout->hdr_list, hdr_node){ 171 header *new_hdr;
172 header *hdr = (header *)(hdr_node->data); 172
173 if(hdr->id == HEAD_SENDER){ 173 new_hdr = create_header(HEAD_SENDER, "Sender: %s@%s\n", msgout->return_path->local_part, msgout->return_path->domain);
174 header *new_hdr; 174 hdr_node->data = new_hdr;
175 175 /* we need this list only to carefully free the extra headers: */
176 new_hdr = 176 msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
177 create_header(HEAD_SENDER, "Sender: %s@%s\n", 177 }
178 msgout->return_path->local_part, msgout->return_path->domain); 178 }
179 hdr_node->data = new_hdr; 179 }
180 /* we need this list only to carefully free the extra headers: */ 180
181 msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr); 181 if (msgout->xtra_hdr_list == NULL) {
182 } 182 /* nothing was changed */
183 } 183 g_list_free(msgout->hdr_list);
184 } 184 msgout->hdr_list = NULL;
185 185 }
186 if(msgout->xtra_hdr_list == NULL){ 186 DEBUG(5) debugf("rewrite_headers() returning\n");
187 /* nothing was changed */ 187 }
188 g_list_free(msgout->hdr_list); 188
189 msgout->hdr_list = NULL; 189 void
190 } 190 rcptlist_with_one_of_hostlist(GList * rcpt_list, GList * host_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list)
191 DEBUG(5) debugf("rewrite_headers() returning\n"); 191 {
192 } 192 GList *rcpt_node;
193 193
194 void rcptlist_with_one_of_hostlist(GList *rcpt_list, GList *host_list, 194 if (rcpt_list == NULL)
195 GList **p_rcpt_list, GList **p_non_rcpt_list) 195 return;
196 { 196
197 GList *rcpt_node; 197 foreach(rcpt_list, rcpt_node) {
198 198 address *rcpt = (address *) (rcpt_node->data);
199 if(rcpt_list == NULL) 199 GList *host_node = NULL;
200 return; 200
201 201 foreach(host_list, host_node) {
202 foreach(rcpt_list, rcpt_node){ 202 gchar *host = (gchar *) (host_node->data);
203 address *rcpt = (address *)(rcpt_node->data); 203 if (fnmatch(host, rcpt->domain, FNM_CASEFOLD) == 0)
204 GList *host_node = NULL; 204 break;
205 205 }
206 foreach(host_list, host_node){ 206 if (host_node) {
207 gchar *host = (gchar *)(host_node->data); 207 if (p_rcpt_list)
208 if(fnmatch(host, rcpt->domain, FNM_CASEFOLD) == 0) 208 *p_rcpt_list = g_list_append(*p_rcpt_list, rcpt);
209 break; 209 } else {
210 } 210 if (p_non_rcpt_list)
211 if(host_node){ 211 *p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt);
212 if(p_rcpt_list) 212 }
213 *p_rcpt_list = g_list_append(*p_rcpt_list, rcpt); 213
214 }else{ 214 }
215 if(p_non_rcpt_list) 215 }
216 *p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt); 216
217 } 217 void
218 218 rcptlist_with_addr_is_local(GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list)
219 } 219 {
220 } 220 GList *rcpt_node;
221 221
222 void rcptlist_with_addr_is_local(GList *rcpt_list, 222 if (rcpt_list == NULL)
223 GList **p_rcpt_list, GList **p_non_rcpt_list) 223 return;
224 { 224
225 GList *rcpt_node; 225 foreach(rcpt_list, rcpt_node) {
226 226 address *rcpt = (address *) (rcpt_node->data);
227 if(rcpt_list == NULL) 227 if (addr_is_local(rcpt)) {
228 return; 228 if (p_rcpt_list)
229 229 *p_rcpt_list = g_list_append(*p_rcpt_list, rcpt);
230 foreach(rcpt_list, rcpt_node){ 230 } else {
231 address *rcpt = (address *)(rcpt_node->data); 231 if (p_non_rcpt_list)
232 if(addr_is_local(rcpt)){ 232 *p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt);
233 if(p_rcpt_list) 233 }
234 *p_rcpt_list = g_list_append(*p_rcpt_list, rcpt); 234
235 }else{ 235 }
236 if(p_non_rcpt_list) 236 }
237 *p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt); 237
238 } 238 static gint
239 239 _g_list_addrcmp(gconstpointer a, gconstpointer b)
240 } 240 {
241 } 241 return addr_match((address *) a, (address *) b);
242 242 }
243 static gint _g_list_addrcmp(gconstpointer a, gconstpointer b) 243
244 { 244 gboolean
245 return addr_match((address *)a, (address *)b); 245 route_is_allowed_return_path(connect_route * route, address * ret_path)
246 } 246 {
247 247 if (route->not_allowed_return_paths != NULL) {
248 gboolean route_is_allowed_return_path(connect_route *route, address *ret_path) 248 if (g_list_find_custom(route->not_allowed_return_paths, ret_path, _g_list_addrcmp) != NULL) {
249 { 249 return FALSE;
250 if(route->not_allowed_return_paths != NULL){ 250 }
251 if(g_list_find_custom(route->not_allowed_return_paths, ret_path, 251 }
252 _g_list_addrcmp) != NULL){ 252 if (route->allowed_return_paths != NULL) {
253 return FALSE; 253 if (g_list_find_custom(route->allowed_return_paths, ret_path, _g_list_addrcmp) != NULL) {
254 } 254 return TRUE;
255 } 255 } else {
256 if(route->allowed_return_paths != NULL){ 256 return FALSE;
257 if(g_list_find_custom(route->allowed_return_paths, ret_path, 257 }
258 _g_list_addrcmp) != NULL){ 258 }
259 return TRUE; 259 return TRUE;
260 }else{ 260 }
261 return FALSE; 261
262 } 262 static gint
263 } 263 _g_list_strcmp(gconstpointer a, gconstpointer b)
264 return TRUE; 264 {
265 } 265 return (gint) strcmp(a, b);
266 266 }
267 static gint _g_list_strcmp(gconstpointer a, gconstpointer b) 267
268 { 268 gboolean
269 return (gint)strcmp(a, b); 269 route_is_allowed_mail_local(connect_route * route, address * ret_path)
270 } 270 {
271 271 gchar *loc_part = ret_path->local_part;
272 gboolean route_is_allowed_mail_local(connect_route *route, address *ret_path) 272
273 { 273 if (route->not_allowed_mail_locals != NULL) {
274 gchar *loc_part = ret_path->local_part; 274 if (g_list_find_custom(route->not_allowed_mail_locals, loc_part, _g_list_strcmp) != NULL)
275 275 return FALSE;
276 if(route->not_allowed_mail_locals != NULL){ 276 }
277 if(g_list_find_custom(route->not_allowed_mail_locals, loc_part, 277 if (route->allowed_mail_locals != NULL) {
278 _g_list_strcmp) != NULL) 278 if (g_list_find_custom(route->allowed_mail_locals, loc_part, _g_list_strcmp) != NULL)
279 return FALSE; 279 return TRUE;
280 } 280 else
281 if(route->allowed_mail_locals != NULL){ 281 return FALSE;
282 if(g_list_find_custom(route->allowed_mail_locals, loc_part, 282 }
283 _g_list_strcmp) != NULL) 283 return TRUE;
284 return TRUE; 284 }
285 else 285
286 return FALSE; 286 /*
287 }
288 return TRUE;
289 }
290
291 /*
292 Make lists of matching/not matching rcpts. 287 Make lists of matching/not matching rcpts.
293 Local domains are NOT regared here, these should be sorted out previously 288 Local domains are NOT regared here, these should be sorted out previously
294 */ 289 */
295 void msg_rcptlist_route(connect_route *route, GList *rcpt_list, 290 void
296 GList **p_rcpt_list, GList **p_non_rcpt_list) 291 msg_rcptlist_route(connect_route * route, GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list)
297 { 292 {
298 GList *tmp_list = NULL; 293 GList *tmp_list = NULL;
299 /* sort out those domains that can be sent over this connection: */ 294 /* sort out those domains that can be sent over this connection: */
300 if(route->allowed_rcpt_domains){ 295 if (route->allowed_rcpt_domains) {
301 DEBUG(5) debugf("testing for route->allowed_rcpt_domains\n"); 296 DEBUG(5) debugf("testing for route->allowed_rcpt_domains\n");
302 rcptlist_with_one_of_hostlist(rcpt_list, route->allowed_rcpt_domains, &tmp_list, p_non_rcpt_list); 297 rcptlist_with_one_of_hostlist(rcpt_list, route->allowed_rcpt_domains, &tmp_list, p_non_rcpt_list);
303 }else{ 298 } else {
304 DEBUG(5) debugf("route->allowed_rcpt_domains == NULL\n"); 299 DEBUG(5) debugf("route->allowed_rcpt_domains == NULL\n");
305 tmp_list = g_list_copy(rcpt_list); 300 tmp_list = g_list_copy(rcpt_list);
306 } 301 }
307 302
308 /* sort out those domains that cannot be sent over this connection: */ 303 /* sort out those domains that cannot be sent over this connection: */
309 rcptlist_with_one_of_hostlist(tmp_list, route->not_allowed_rcpt_domains, p_non_rcpt_list, p_rcpt_list); 304 rcptlist_with_one_of_hostlist(tmp_list, route->not_allowed_rcpt_domains, p_non_rcpt_list, p_rcpt_list);
310 g_list_free(tmp_list); 305 g_list_free(tmp_list);
311 } 306 }
312 307
313 msg_out *route_prepare_msgout(connect_route *route, msg_out *msgout) 308 msg_out*
314 { 309 route_prepare_msgout(connect_route * route, msg_out * msgout)
315 message *msg = msgout->msg; 310 {
316 GList *rcpt_list = msgout->rcpt_list; 311 message *msg = msgout->msg;
317 312 GList *rcpt_list = msgout->rcpt_list;
318 if(rcpt_list != NULL){ 313
319 /* found a few */ 314 if (rcpt_list != NULL) {
320 DEBUG(5){ 315 /* found a few */
321 GList *node; 316 DEBUG(5) {
322 debugf("rcpts for routed delivery, route = %s, id = %s\n", route->name, msg->uid); 317 GList *node;
323 foreach(rcpt_list, node){ 318 debugf("rcpts for routed delivery, route = %s, id = %s\n", route->name, msg->uid);
324 address *rcpt = (address *)(node->data); 319 foreach(rcpt_list, node) {
325 debugf("rcpt for routed delivery: <%s@%s>\n", 320 address *rcpt = (address *) (node->data);
326 rcpt->local_part, rcpt->domain); 321 debugf("rcpt for routed delivery: <%s@%s>\n", rcpt->local_part, rcpt->domain);
327 } 322 }
328 } 323 }
329 324
330 /* rewrite return path 325 /* rewrite return path
331 if there is a table, use that 326 if there is a table, use that
332 if an address is found and if it has a domain, use that 327 if an address is found and if it has a domain, use that
333 */ 328 */
334 if(route->map_return_path_addresses){ 329 if (route->map_return_path_addresses) {
335 address *ret_path = NULL; 330 address *ret_path = NULL;
336 DEBUG(5) debugf("looking up %s in map_return_path_addresses\n", 331 DEBUG(5) debugf("looking up %s in map_return_path_addresses\n", msg->return_path->local_part);
337 msg->return_path->local_part); 332 ret_path = (address *) table_find_fnmatch(route->map_return_path_addresses, msg->return_path->local_part);
338 ret_path = 333 if (ret_path) {
339 (address *)table_find_fnmatch(route->map_return_path_addresses, 334 DEBUG(5) debugf("found <%s@%s>\n", ret_path->local_part, ret_path->domain);
340 msg->return_path->local_part); 335 if (ret_path->domain == NULL)
341 if(ret_path){ 336 ret_path->domain = route->set_return_path_domain
342 DEBUG(5) debugf("found <%s@%s>\n", 337 ? route->set_return_path_domain
343 ret_path->local_part, ret_path->domain); 338 : msg->return_path->domain;
344 if(ret_path->domain == NULL) 339 msgout->return_path = copy_address(ret_path);
345 ret_path->domain = 340 }
346 route->set_return_path_domain ? 341 }
347 route->set_return_path_domain : msg->return_path->domain; 342 if (msgout->return_path == NULL) {
348 msgout->return_path = copy_address(ret_path); 343 DEBUG(5) debugf("setting return path to %s\n", route->set_return_path_domain);
349 } 344 msgout->return_path = copy_modify_address(msg->return_path, NULL, route->set_return_path_domain);
350 } 345 }
351 if(msgout->return_path == NULL){ 346 rewrite_headers(msgout, route);
352 DEBUG(5) debugf("setting return path to %s\n", 347
353 route->set_return_path_domain); 348 return msgout;
354 msgout->return_path = 349 }
355 copy_modify_address(msg->return_path, 350 return NULL;
356 NULL, route->set_return_path_domain);
357 }
358 rewrite_headers(msgout, route);
359
360 return msgout;
361 }
362 return NULL;
363 } 351 }
364 352
365 /* put msgout's is msgout_list into bins (msgout_perhost structs) for each 353 /* put msgout's is msgout_list into bins (msgout_perhost structs) for each
366 host. Used if there is no mail_host. 354 host. Used if there is no mail_host.
367 route param is not used, we leave it here because that may change. 355 route param is not used, we leave it here because that may change.
368 */ 356 */
369 357
370 GList *route_msgout_list(connect_route *route, GList *msgout_list) 358 GList*
371 { 359 route_msgout_list(connect_route * route, GList * msgout_list)
372 GList *mo_ph_list = NULL; 360 {
373 GList *msgout_node; 361 GList *mo_ph_list = NULL;
374 362 GList *msgout_node;
375 foreach(msgout_list, msgout_node){ 363
376 msg_out *msgout = (msg_out *)(msgout_node->data); 364 foreach(msgout_list, msgout_node) {
377 msg_out *msgout_new; 365 msg_out *msgout = (msg_out *) (msgout_node->data);
378 GList *rcpt_list = msgout->rcpt_list; 366 msg_out *msgout_new;
379 GList *rcpt_node; 367 GList *rcpt_list = msgout->rcpt_list;
380 368 GList *rcpt_node;
381 foreach(rcpt_list, rcpt_node){ 369
382 address *rcpt = rcpt_node->data; 370 foreach(rcpt_list, rcpt_node) {
383 msgout_perhost *mo_ph = NULL; 371 address *rcpt = rcpt_node->data;
384 GList *mo_ph_node = NULL; 372 msgout_perhost *mo_ph = NULL;
385 373 GList *mo_ph_node = NULL;
386 /* search host in mo_ph_list */ 374
387 foreach(mo_ph_list, mo_ph_node){ 375 /* search host in mo_ph_list */
388 mo_ph = (msgout_perhost *)(mo_ph_node->data); 376 foreach(mo_ph_list, mo_ph_node) {
389 if(strcasecmp(mo_ph->host, rcpt->domain) == 0) 377 mo_ph = (msgout_perhost *) (mo_ph_node->data);
390 break; 378 if (strcasecmp(mo_ph->host, rcpt->domain) == 0)
391 } 379 break;
392 if(mo_ph_node != NULL){ 380 }
393 /* there is already a rcpt for this host */ 381 if (mo_ph_node != NULL) {
394 msg_out *msgout_last = 382 /* there is already a rcpt for this host */
395 (msg_out *)((g_list_last(mo_ph->msgout_list))->data); 383 msg_out *msgout_last = (msg_out *) ((g_list_last(mo_ph->msgout_list))->data);
396 if(msgout_last->msg == msgout->msg){ 384 if (msgout_last->msg == msgout->msg) {
397 /* if it is also the same message, it must be the last one 385 /* if it is also the same message, it must be the last one
398 appended to mo_ph->msgout_list (since outer loop goes through 386 appended to mo_ph->msgout_list (since outer loop goes through
399 msgout_list) */ 387 msgout_list) */
400 msgout_last->rcpt_list = 388 msgout_last->rcpt_list = g_list_append(msgout_last->rcpt_list, rcpt);
401 g_list_append(msgout_last->rcpt_list, rcpt); 389 } else {
402 }else{ 390 /* if not, we append a new msgout */
403 /* if not, we append a new msgout */ 391 /* make a copy of msgout */
404 /* make a copy of msgout */ 392 msgout_new = create_msg_out(msgout->msg);
405 msgout_new = create_msg_out(msgout->msg); 393 msgout_new->return_path = msgout->return_path;
406 msgout_new->return_path = msgout->return_path; 394 msgout_new->hdr_list = msgout->hdr_list;
407 msgout_new->hdr_list = msgout->hdr_list; 395
408 396 /* append our rcpt to it */
409 /* append our rcpt to it */ 397 /* It is the 1st rcpt for this msg to this host, therefore we safely give NULL */
410 /* It is the 1st rcpt for this msg to this host, 398 msgout_new->rcpt_list = g_list_append(NULL, rcpt);
411 therefore we safely give NULL */ 399 mo_ph->msgout_list = g_list_append(mo_ph->msgout_list, msgout_new);
412 msgout_new->rcpt_list = g_list_append(NULL, rcpt); 400 }
413 mo_ph->msgout_list = 401 } else {
414 g_list_append(mo_ph->msgout_list, msgout_new); 402 /* this rcpt to goes to another host */
415 } 403 mo_ph = create_msgout_perhost(rcpt->domain);
416 }else{ 404 mo_ph_list = g_list_append(mo_ph_list, mo_ph);
417 /* this rcpt to goes to another host */ 405
418 mo_ph = create_msgout_perhost(rcpt->domain); 406 /* make a copy of msgout */
419 mo_ph_list = g_list_append(mo_ph_list, mo_ph); 407 msgout_new = create_msg_out(msgout->msg);
420 408 msgout_new->return_path = msgout->return_path;
421 /* make a copy of msgout */ 409 msgout_new->hdr_list = msgout->hdr_list;
422 msgout_new = create_msg_out(msgout->msg); 410
423 msgout_new->return_path = msgout->return_path; 411 /* append our rcpt to it */
424 msgout_new->hdr_list = msgout->hdr_list; 412 /* It is the 1st rcpt for this msg to this host, therefore we safely give NULL */
425 413 msgout_new->rcpt_list = g_list_append(NULL, rcpt);
426 /* append our rcpt to it */ 414 mo_ph->msgout_list = g_list_append(mo_ph->msgout_list, msgout_new);
427 /* It is the 1st rcpt for this msg to this host, 415 } /* if mo_ph != NULL */
428 therefore we safely give NULL */ 416 } /* foreach(rcpt_list, ... */
429 msgout_new->rcpt_list = g_list_append(NULL, rcpt); 417 } /* foreach(msgout_list, ... */
430 mo_ph->msgout_list = g_list_append(mo_ph->msgout_list, msgout_new); 418
431 }/* if mo_ph != NULL */ 419 return mo_ph_list;
432 }/* foreach(rcpt_list, ... */ 420 }
433 }/* foreach(msgout_list, ... */
434
435 return mo_ph_list;
436 }