Mercurial > masqmail
annotate src/alias.c @ 304:d5ce2ba71e7b
manual formating of Received: hdrs; changed hdr for local receival
Now the Received: headers are much friendlier to read.
About folding: We must fold any line at 998 chars before transfer.
We should fold the lines we produce at 78 chars. That is what RFC
2821 requests. We should think about it, somewhen.
The header for locally (i.e. non-SMTP) received mail is changed
to the format postfix uses. This matches RFC 2821 better. The
`from' clause should contain a domain or IP, not a user name. Also,
the `with' clause should contain a registered standard protocol
name, which ``local'' is not.
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Thu, 09 Dec 2010 18:28:11 -0300 |
parents | 7082044c05c6 |
children | 273f6c9eb6a2 |
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); |
244
7082044c05c6
renamed `alias_local_cmp' to `localpartcmp'
markus schnalke <meillo@marmaro.de>
parents:
242
diff
changeset
|
43 if (addr_isequal(a, addr, conf.localpartcmp)) { |
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); | |
244
7082044c05c6
renamed `alias_local_cmp' to `localpartcmp'
markus schnalke <meillo@marmaro.de>
parents:
242
diff
changeset
|
57 if (addr_isequal(a, addr, conf.localpartcmp)) { |
10
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 GList* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
68 parse_list(gchar * line) |
0 | 69 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
70 GList *list = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
71 gchar buf[256]; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
72 gchar *p, *q; |
0 | 73 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
74 p = line; |
14
a8f3424347dc
replaced number 0 with character \0 where appropriate
meillo@marmaro.de
parents:
10
diff
changeset
|
75 while (*p != '\0') { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
76 q = buf; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
77 while (isspace(*p)) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
78 p++; |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
79 if (*p != '"') { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
80 while (*p && (*p != ',') && (q < buf + 255)) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
81 *(q++) = *(p++); |
14
a8f3424347dc
replaced number 0 with character \0 where appropriate
meillo@marmaro.de
parents:
10
diff
changeset
|
82 *q = '\0'; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
83 } else { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
84 gboolean escape = FALSE; |
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 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
|
87 if ((*p == '\\') && !escape) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
88 escape = TRUE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
89 else { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
90 escape = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
91 *(q++) = *p; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
92 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
93 p++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
94 } |
14
a8f3424347dc
replaced number 0 with character \0 where appropriate
meillo@marmaro.de
parents:
10
diff
changeset
|
95 *q = '\0'; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
96 while (*p && (*p != ',')) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
97 p++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
98 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
99 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
|
100 if (*p) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
101 p++; |
0 | 102 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
103 return list; |
0 | 104 } |
105 | |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
106 /* |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
107 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
|
108 */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
109 static GList* |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
110 expand_one(GList* alias_table, address* addr) |
0 | 111 { |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
112 GList *val_list; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
113 GList *val_node; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
114 GList *alias_list = NULL; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
115 GList *alias_node; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
116 gchar *val; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
117 address* alias_addr; |
0 | 118 |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
119 /* expand the local alias */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
120 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
|
121 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
122 if (strcasecmp(addr->local_part, "postmaster") == 0) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
123 /* postmaster must always be matched caseless |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
124 see RFC 822 and RFC 5321 */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
125 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
|
126 } else { |
244
7082044c05c6
renamed `alias_local_cmp' to `localpartcmp'
markus schnalke <meillo@marmaro.de>
parents:
242
diff
changeset
|
127 val = (gchar *) table_find_func(alias_table, addr->local_part, conf.localpartcmp); |
239
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 (!val) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
130 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
|
131 addr->local_part); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
132 return g_list_append(NULL, addr); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
133 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
134 |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
135 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
|
136 val_list = parse_list(val); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
137 alias_list = NULL; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
138 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
139 foreach(val_list, val_node) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
140 gchar *val = (gchar *) (val_node->data); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
141 address *alias_addr; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
142 address *addr_parent = NULL; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
143 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
144 DEBUG(6) debugf("alias: processing '%s'\n", val); |
0 | 145 |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
146 if (val[0] == '\\') { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
147 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
|
148 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
|
149 g_free(val); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
150 DEBUG(6) debugf("alias: address generated: '%s'\n", |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
151 alias_addr->local_part); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
152 alias_list = g_list_append(alias_list, alias_addr); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
153 continue; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
154 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
155 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
156 if (val[0] == '|') { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
157 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
|
158 alias_addr = create_address_pipe(val+1); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
159 g_free(val); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
160 DEBUG(6) debugf("alias: pipe generated: %s\n", |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
161 alias_addr->local_part); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
162 alias_list = g_list_append(alias_list, alias_addr); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
163 continue; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
164 } |
0 | 165 |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
166 alias_addr = create_address_qualified(val, TRUE, conf.host_name); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
167 g_free(val); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
168 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
169 if (!addr_is_local(alias_addr)) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
170 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
|
171 alias_addr->local_part, alias_addr->domain); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
172 alias_list = g_list_append(alias_list, alias_addr); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
173 continue; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
174 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
175 |
242
bc9d9cd9ee8e
made addr_isequal() and addr_isequal_parent() more flexible
markus schnalke <meillo@marmaro.de>
parents:
239
diff
changeset
|
176 /* addr is local and to expand at this point */ |
bc9d9cd9ee8e
made addr_isequal() and addr_isequal_parent() more flexible
markus schnalke <meillo@marmaro.de>
parents:
239
diff
changeset
|
177 /* but first ... search in parents for loops: */ |
244
7082044c05c6
renamed `alias_local_cmp' to `localpartcmp'
markus schnalke <meillo@marmaro.de>
parents:
242
diff
changeset
|
178 if (addr_isequal_parent(addr, alias_addr, conf.localpartcmp)) { |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
179 /* loop detected, ignore this path */ |
242
bc9d9cd9ee8e
made addr_isequal() and addr_isequal_parent() more flexible
markus schnalke <meillo@marmaro.de>
parents:
239
diff
changeset
|
180 logwrite(LOG_ALERT, "alias: detected loop, hence ignoring '%s'\n", |
bc9d9cd9ee8e
made addr_isequal() and addr_isequal_parent() more flexible
markus schnalke <meillo@marmaro.de>
parents:
239
diff
changeset
|
181 alias_addr->local_part); |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
182 continue; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
183 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
184 alias_addr->parent = addr; |
0 | 185 |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
186 /* recurse */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
187 DEBUG(6) debugf("alias: >>\n"); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
188 alias_node = expand_one(alias_table, alias_addr); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
189 DEBUG(6) debugf("alias: <<\n"); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
190 if (alias_node) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
191 alias_list = g_list_concat(alias_list, alias_node); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
192 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
193 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
194 g_list_free(val_list); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
195 addr->children = g_list_copy(alias_list); |
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 return alias_list; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
198 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
199 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
200 GList* |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
201 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
|
202 { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
203 GList *rcpt_node = NULL; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
204 GList *alias_list = NULL; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
205 GList *done_list = NULL; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
206 GList *rcpt_node_next = NULL; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
207 address *addr = NULL; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
208 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
209 for (rcpt_node=g_list_copy(rcpt_list); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
210 rcpt_node; |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
211 rcpt_node=g_list_next(rcpt_node)) { |
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 addr = (address *) (rcpt_node->data); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
214 if (addr_is_local(addr)) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
215 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
|
216 addr->local_part); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
217 alias_list = expand_one(alias_table, addr); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
218 if (alias_list) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
219 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
|
220 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
221 } else { |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
222 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
|
223 addr->local_part, addr->domain); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
224 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
|
225 } |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
226 } |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
227 |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
228 /* 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
|
229 if (!non_rcpt_list) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
230 return done_list; |
0 | 231 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
232 |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
233 /* delete addresses of non_rcpt_list from done_list */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
234 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
|
235 address *addr = (address *) (rcpt_node->data); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
236 GList *non_node; |
0 | 237 |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
238 rcpt_node_next = g_list_next(rcpt_node); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
239 foreach(non_rcpt_list, non_node) { |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
240 address *non_addr = (address *) (non_node->data); |
244
7082044c05c6
renamed `alias_local_cmp' to `localpartcmp'
markus schnalke <meillo@marmaro.de>
parents:
242
diff
changeset
|
241 if (addr_isequal(addr, non_addr, conf.localpartcmp)) { |
239
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
242 done_list = g_list_remove_link(done_list, rcpt_node); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
243 g_list_free_1(rcpt_node); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
244 /* this address is still in the children lists |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
245 of the original address, simply mark them delivered */ |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
246 addr_mark_delivered(addr); |
31ee44f45787
refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents:
233
diff
changeset
|
247 break; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
248 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
249 } |
0 | 250 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
251 return done_list; |
0 | 252 } |