Mercurial > masqmail
annotate src/address.c @ 355:ddb7b3fd3d08
found further appearences of ``localnet'' in the code
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Sun, 04 Sep 2011 11:33:31 +0200 |
parents | 55b7bde95d37 |
children | 41958685480d |
rev | line source |
---|---|
0 | 1 /* MasqMail |
2 Copyright (C) 1999-2001 Oliver Kurth | |
3 | |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 2 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program; if not, write to the Free Software | |
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 */ | |
18 | |
19 #include "masqmail.h" | |
20 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
21 address* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
22 create_address(gchar * path, gboolean is_rfc821) |
0 | 23 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
24 address *addr; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
25 addr = _create_address(path, NULL, is_rfc821); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
26 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
27 if (addr != NULL) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
28 addr_unmark_delivered(addr); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
29 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
30 return addr; |
0 | 31 } |
32 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
33 address* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
34 create_address_qualified(gchar * path, gboolean is_rfc821, gchar * domain) |
0 | 35 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
36 address *addr = create_address(path, is_rfc821); |
23
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
37 |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
38 if (addr != NULL && addr->domain == NULL) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
39 addr->domain = g_strdup(domain); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
40 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
41 return addr; |
0 | 42 } |
43 | |
13 | 44 /* nothing special about pipes here, but its only called for that purpose */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
45 address* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
46 create_address_pipe(gchar * path) |
0 | 47 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
48 address *addr = g_malloc(sizeof(address)); |
0 | 49 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
50 if (addr) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
51 memset(addr, 0, sizeof(address)); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
52 addr->address = g_strchomp(g_strdup(path)); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
53 addr->local_part = g_strdup(addr->address); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
54 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
55 addr->domain = g_strdup("localhost"); /* quick hack */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
56 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
57 return addr; |
0 | 58 } |
59 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
60 void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
61 destroy_address(address * addr) |
0 | 62 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
63 DEBUG(6) debugf("destroy_address entered\n"); |
0 | 64 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
65 g_free(addr->address); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
66 g_free(addr->local_part); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
67 g_free(addr->domain); |
0 | 68 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
69 g_free(addr); |
0 | 70 } |
71 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
72 address* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
73 copy_modify_address(const address * orig, gchar * l_part, gchar * dom) |
0 | 74 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
75 address *addr = NULL; |
0 | 76 |
23
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
77 if (!orig) { |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
78 return NULL; |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
79 } |
0 | 80 |
23
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
81 if ((addr = g_malloc(sizeof(address))) == NULL) { |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
82 return NULL; |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
83 } |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
84 |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
85 addr->address = g_strdup(orig->address); |
0 | 86 |
23
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
87 if (l_part == NULL) |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
88 addr->local_part = g_strdup(orig->local_part); |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
89 else |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
90 addr->local_part = g_strdup(l_part); |
0 | 91 |
23
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
92 if (dom == NULL) |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
93 addr->domain = g_strdup(orig->domain); |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
94 else |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
95 addr->domain = g_strdup(dom); |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
96 |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
97 addr->flags = 0; |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
98 addr->children = NULL; |
4a3bc3a7afbe
refactoring: early exit instead of deep if levels
meillo@marmaro.de
parents:
14
diff
changeset
|
99 addr->parent = NULL; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
100 return addr; |
0 | 101 } |
102 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
103 gboolean |
242
bc9d9cd9ee8e
made addr_isequal() and addr_isequal_parent() more flexible
markus schnalke <meillo@marmaro.de>
parents:
23
diff
changeset
|
104 addr_isequal(address * addr1, address * addr2, int (*cmpfunc) (const char*, const char*)) |
0 | 105 { |
242
bc9d9cd9ee8e
made addr_isequal() and addr_isequal_parent() more flexible
markus schnalke <meillo@marmaro.de>
parents:
23
diff
changeset
|
106 return (cmpfunc(addr1->local_part, addr2->local_part) == 0) |
13 | 107 && (strcasecmp(addr1->domain, addr2->domain) == 0); |
0 | 108 } |
109 | |
110 /* searches in ancestors of addr1 */ | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
111 gboolean |
242
bc9d9cd9ee8e
made addr_isequal() and addr_isequal_parent() more flexible
markus schnalke <meillo@marmaro.de>
parents:
23
diff
changeset
|
112 addr_isequal_parent(address* addr1, address* addr2, int (*cmpfunc) (const char*, const char*)) |
0 | 113 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
114 address *addr; |
0 | 115 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
116 for (addr = addr1; addr; addr = addr->parent) |
242
bc9d9cd9ee8e
made addr_isequal() and addr_isequal_parent() more flexible
markus schnalke <meillo@marmaro.de>
parents:
23
diff
changeset
|
117 if (addr_isequal(addr, addr2, cmpfunc)) |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
118 return TRUE; |
0 | 119 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
120 return FALSE; |
0 | 121 } |
122 | |
123 /* careful, this is recursive */ | |
124 /* returns TRUE if ALL children have been delivered */ | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
125 gboolean |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
126 addr_is_delivered_children(address * addr) |
0 | 127 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
128 GList *addr_node; |
0 | 129 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
130 if (addr->children == NULL) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
131 return addr_is_delivered(addr); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
132 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
133 foreach(addr->children, addr_node) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
134 address *addr = (address *) (addr_node->data); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
135 if (!addr_is_delivered_children(addr)) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
136 return FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
137 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
138 return TRUE; |
0 | 139 } |
140 | |
141 /* careful, this is recursive */ | |
142 /* returns TRUE if ALL children have been either delivered or have failed */ | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
143 gboolean |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
144 addr_is_finished_children(address * addr) |
0 | 145 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
146 GList *addr_node; |
0 | 147 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
148 if (addr->children == NULL) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
149 return (addr_is_failed(addr) || addr_is_delivered(addr)); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
150 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
151 foreach(addr->children, addr_node) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
152 address *addr = (address *) (addr_node->data); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
153 if (!addr_is_finished_children(addr)) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
154 return FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
155 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
156 return TRUE; |
0 | 157 } |
158 | |
159 /* find original address */ | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
160 address* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
161 addr_find_ancestor(address * addr) |
0 | 162 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
163 while (addr->parent) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
164 addr = addr->parent; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
165 return addr; |
0 | 166 } |
167 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
168 gchar* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
169 addr_string(address * addr) |
0 | 170 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
171 static gchar *buffer = NULL; |
0 | 172 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
173 if (addr == NULL) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
174 g_free(buffer); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
175 buffer = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
176 return NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
177 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
178 if (buffer) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
179 g_free(buffer); |
0 | 180 |
14
a8f3424347dc
replaced number 0 with character \0 where appropriate
meillo@marmaro.de
parents:
13
diff
changeset
|
181 if (addr->local_part[0] == '\0') { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
182 buffer = g_strdup("<>"); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
183 } else { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
184 buffer = g_strdup_printf("<%s@%s>", addr->local_part ? addr->local_part : "", addr->domain ? addr->domain : ""); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
185 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
186 return buffer; |
0 | 187 } |