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