Mercurial > masqmail
annotate src/alias.c @ 241:87df0aa99cc7
added myself to the copyright notice of route.c
see the earlier changes about split_rcpts()
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Mon, 25 Oct 2010 15:41:48 -0300 |
parents | 31ee44f45787 |
children | bc9d9cd9ee8e |
rev | line source |
---|---|
0 | 1 /* MasqMail |
2 Copyright (C) 2000-2001 Oliver Kurth | |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
3 Copyright (C) 2010 markus schnalke <meillo@marmaro.de> |
0 | 4 |
5 This program is free software; you can redistribute it and/or modify | |
6 it under the terms of the GNU General Public License as published by | |
7 the Free Software Foundation; either version 2 of the License, or | |
8 (at your option) any later version. | |
9 | |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
16 along with this program; if not, write to the Free Software | |
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 */ | |
19 | |
20 #include "masqmail.h" | |
21 #include <fnmatch.h> | |
22 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
23 gboolean |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
24 addr_is_local(address * addr) |
0 | 25 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
26 GList *dom_node; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
27 GList *addr_node; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
28 address *a; |
0 | 29 |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
30 if (addr->domain == NULL) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
31 return TRUE; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
32 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
33 foreach(conf.local_hosts, dom_node) { |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
34 /* Note: FNM_CASEFOLD is a GNU extension */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
35 if (fnmatch(dom_node->data, addr->domain, FNM_CASEFOLD) != 0) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
36 /* no match, try next */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
37 continue; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
38 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
39 foreach(conf.not_local_addresses, addr_node) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
40 a = create_address_qualified(addr_node->data, TRUE, conf.host_name); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
41 DEBUG(6) debugf("not_local_addresses: addr_node->data=%s a->address=%s\n", |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
42 addr_node->data, a->address); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
43 if (addr_isequal(a, addr)) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
44 destroy_address(a); |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
45 /* in local_hosts but also in not_local_addresses */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
46 return FALSE; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
47 } |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
48 destroy_address(a); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
49 } |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
50 /* in local_hosts */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
51 return TRUE; |
0 | 52 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
53 foreach(conf.local_addresses, addr_node) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
54 a = create_address_qualified(addr_node->data, TRUE, conf.host_name); |
114 | 55 DEBUG(6) debugf("local_addresses: addr_node->data=%s a->address=%s\n", |
56 addr_node->data, a->address); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
57 if (addr_isequal(a, addr)) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
58 destroy_address(a); |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
59 /* in local_addresses */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
60 return TRUE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
61 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
62 destroy_address(a); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
63 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
64 return FALSE; |
0 | 65 } |
66 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
67 static gboolean |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
68 addr_isequal_alias(address * addr1, address * addr2) |
0 | 69 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
70 return (conf.alias_local_cmp(addr1->local_part, addr2->local_part) == 0) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
71 && (strcasecmp(addr1->domain, addr2->domain) == 0); |
0 | 72 } |
73 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
74 static GList* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
75 parse_list(gchar * line) |
0 | 76 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
77 GList *list = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
78 gchar buf[256]; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
79 gchar *p, *q; |
0 | 80 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
81 p = line; |
14
a8f3424347dc
replaced number 0 with character \0 where appropriate
meillo@marmaro.de
parents:
10
diff
changeset
|
82 while (*p != '\0') { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
83 q = buf; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
84 while (isspace(*p)) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
85 p++; |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
86 if (*p != '"') { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
87 while (*p && (*p != ',') && (q < buf + 255)) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
88 *(q++) = *(p++); |
14
a8f3424347dc
replaced number 0 with character \0 where appropriate
meillo@marmaro.de
parents:
10
diff
changeset
|
89 *q = '\0'; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
90 } else { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
91 gboolean escape = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
92 p++; |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
93 while (*p && (*p != '"' || escape) && (q < buf + 255)) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
94 if ((*p == '\\') && !escape) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
95 escape = TRUE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
96 else { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
97 escape = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
98 *(q++) = *p; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
99 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
100 p++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
101 } |
14
a8f3424347dc
replaced number 0 with character \0 where appropriate
meillo@marmaro.de
parents:
10
diff
changeset
|
102 *q = '\0'; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
103 while (*p && (*p != ',')) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
104 p++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
105 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
106 list = g_list_append(list, g_strdup(g_strchomp(buf))); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
107 if (*p) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
108 p++; |
0 | 109 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
110 return list; |
0 | 111 } |
112 | |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
113 /* |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
114 addr is assumed to be local and no pipe address nor not-to-expand |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
115 */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
116 static GList* |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
117 expand_one(GList* alias_table, address* addr) |
0 | 118 { |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
119 GList *val_list; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
120 GList *val_node; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
121 GList *alias_list = NULL; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
122 GList *alias_node; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
123 gchar *val; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
124 address* alias_addr; |
0 | 125 |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
126 /* expand the local alias */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
127 DEBUG(6) debugf("alias: '%s' is local and will get expanded\n", addr->local_part); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
128 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
129 if (strcasecmp(addr->local_part, "postmaster") == 0) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
130 /* postmaster must always be matched caseless |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
131 see RFC 822 and RFC 5321 */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
132 val = (gchar *) table_find_func(alias_table, addr->local_part, strcasecmp); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
133 } else { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
134 val = (gchar *) table_find_func(alias_table, addr->local_part, conf.alias_local_cmp); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
135 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
136 if (!val) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
137 DEBUG(5) debugf("alias: '%s' is fully expanded, hence completed\n", |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
138 addr->local_part); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
139 return g_list_append(NULL, addr); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
140 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
141 |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
142 DEBUG(5) debugf("alias: '%s' -> '%s'\n", addr->local_part, val); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
143 val_list = parse_list(val); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
144 alias_list = NULL; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
145 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
146 foreach(val_list, val_node) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
147 gchar *val = (gchar *) (val_node->data); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
148 address *alias_addr; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
149 address *addr_parent = NULL; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
150 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
151 DEBUG(6) debugf("alias: processing '%s'\n", val); |
0 | 152 |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
153 if (val[0] == '\\') { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
154 DEBUG(5) debugf("alias: '%s' is marked as final, hence completed\n", val); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
155 alias_addr = create_address_qualified(val+1, TRUE, conf.host_name); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
156 g_free(val); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
157 DEBUG(6) debugf("alias: address generated: '%s'\n", |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
158 alias_addr->local_part); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
159 alias_list = g_list_append(alias_list, alias_addr); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
160 continue; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
161 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
162 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
163 if (val[0] == '|') { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
164 DEBUG(5) debugf("alias: '%s' is a pipe address\n", val); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
165 alias_addr = create_address_pipe(val+1); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
166 g_free(val); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
167 DEBUG(6) debugf("alias: pipe generated: %s\n", |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
168 alias_addr->local_part); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
169 alias_list = g_list_append(alias_list, alias_addr); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
170 continue; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
171 } |
0 | 172 |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
173 alias_addr = create_address_qualified(val, TRUE, conf.host_name); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
174 g_free(val); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
175 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
176 if (!addr_is_local(alias_addr)) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
177 DEBUG(5) debugf("alias: '%s@%s' is non-local, hence completed\n", |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
178 alias_addr->local_part, alias_addr->domain); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
179 alias_list = g_list_append(alias_list, alias_addr); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
180 continue; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
181 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
182 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
183 /* addr is local, so let's go into recursion and expand again, |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
184 but first ... search in parents for loops: */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
185 for (addr_parent=addr; addr_parent; addr_parent=addr_parent->parent) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
186 if (addr_isequal_alias(alias_addr, addr_parent)) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
187 break; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
188 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
189 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
190 if (addr_parent) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
191 /* loop detected, ignore this path */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
192 logwrite(LOG_ALERT, |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
193 "alias: detected loop (%s -> %s), hence ignoring\n", |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
194 addr_parent->local_part, addr->local_part); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
195 continue; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
196 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
197 alias_addr->parent = addr; |
0 | 198 |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
199 /* recurse */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
200 DEBUG(6) debugf("alias: >>\n"); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
201 alias_node = expand_one(alias_table, alias_addr); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
202 DEBUG(6) debugf("alias: <<\n"); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
203 if (alias_node) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
204 alias_list = g_list_concat(alias_list, alias_node); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
205 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
206 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
207 g_list_free(val_list); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
208 addr->children = g_list_copy(alias_list); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
209 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
210 return alias_list; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
211 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
212 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
213 GList* |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
214 alias_expand(GList* alias_table, GList* rcpt_list, GList* non_rcpt_list) |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
215 { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
216 GList *rcpt_node = NULL; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
217 GList *alias_list = NULL; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
218 GList *done_list = NULL; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
219 GList *rcpt_node_next = NULL; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
220 address *addr = NULL; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
221 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
222 for (rcpt_node=g_list_copy(rcpt_list); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
223 rcpt_node; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
224 rcpt_node=g_list_next(rcpt_node)) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
225 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
226 addr = (address *) (rcpt_node->data); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
227 if (addr_is_local(addr)) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
228 DEBUG(5) debugf("alias: (orig rcpt addr) expand local '%s'\n", |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
229 addr->local_part); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
230 alias_list = expand_one(alias_table, addr); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
231 if (alias_list) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
232 done_list = g_list_concat(done_list, alias_list); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
233 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
234 } else { |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
235 DEBUG(5) debugf("alias: (orig rcpt addr) don't expand non-local '%s@%s'\n", |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
236 addr->local_part, addr->domain); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
237 done_list = g_list_append(done_list, addr); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
238 } |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
239 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
240 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
241 /* we're done if we don't have to remove rcpts */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
242 if (!non_rcpt_list) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
243 return done_list; |
0 | 244 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
245 |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
246 /* delete addresses of non_rcpt_list from done_list */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
247 for (rcpt_node = g_list_first(done_list); rcpt_node; rcpt_node = rcpt_node_next) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
248 address *addr = (address *) (rcpt_node->data); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
249 GList *non_node; |
0 | 250 |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
251 rcpt_node_next = g_list_next(rcpt_node); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
252 foreach(non_rcpt_list, non_node) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
253 address *non_addr = (address *) (non_node->data); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
254 if (addr_isequal(addr, non_addr)) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
255 done_list = g_list_remove_link(done_list, rcpt_node); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
256 g_list_free_1(rcpt_node); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
257 /* this address is still in the children lists |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
258 of the original address, simply mark them delivered */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
259 addr_mark_delivered(addr); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
260 break; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
261 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
262 } |
0 | 263 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
264 return done_list; |
0 | 265 } |