masqmail

view src/address.c @ 336:2d4aa516ba0e

updated ChangeLog and NEWS
author markus schnalke <meillo@marmaro.de>
date Sat, 27 Aug 2011 18:38:55 +0200
parents bc9d9cd9ee8e
children 41958685480d
line source
1 /* MasqMail
2 Copyright (C) 1999-2001 Oliver Kurth
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.
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.
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 */
19 #include "masqmail.h"
21 address*
22 create_address(gchar * path, gboolean is_rfc821)
23 {
24 address *addr;
25 addr = _create_address(path, NULL, is_rfc821);
27 if (addr != NULL) {
28 addr_unmark_delivered(addr);
29 }
30 return addr;
31 }
33 address*
34 create_address_qualified(gchar * path, gboolean is_rfc821, gchar * domain)
35 {
36 address *addr = create_address(path, is_rfc821);
38 if (addr != NULL && addr->domain == NULL) {
39 addr->domain = g_strdup(domain);
40 }
41 return addr;
42 }
44 /* nothing special about pipes here, but its only called for that purpose */
45 address*
46 create_address_pipe(gchar * path)
47 {
48 address *addr = g_malloc(sizeof(address));
50 if (addr) {
51 memset(addr, 0, sizeof(address));
52 addr->address = g_strchomp(g_strdup(path));
53 addr->local_part = g_strdup(addr->address);
55 addr->domain = g_strdup("localhost"); /* quick hack */
56 }
57 return addr;
58 }
60 void
61 destroy_address(address * addr)
62 {
63 DEBUG(6) debugf("destroy_address entered\n");
65 g_free(addr->address);
66 g_free(addr->local_part);
67 g_free(addr->domain);
69 g_free(addr);
70 }
72 address*
73 copy_modify_address(const address * orig, gchar * l_part, gchar * dom)
74 {
75 address *addr = NULL;
77 if (!orig) {
78 return NULL;
79 }
81 if ((addr = g_malloc(sizeof(address))) == NULL) {
82 return NULL;
83 }
85 addr->address = g_strdup(orig->address);
87 if (l_part == NULL)
88 addr->local_part = g_strdup(orig->local_part);
89 else
90 addr->local_part = g_strdup(l_part);
92 if (dom == NULL)
93 addr->domain = g_strdup(orig->domain);
94 else
95 addr->domain = g_strdup(dom);
97 addr->flags = 0;
98 addr->children = NULL;
99 addr->parent = NULL;
100 return addr;
101 }
103 gboolean
104 addr_isequal(address * addr1, address * addr2, int (*cmpfunc) (const char*, const char*))
105 {
106 return (cmpfunc(addr1->local_part, addr2->local_part) == 0)
107 && (strcasecmp(addr1->domain, addr2->domain) == 0);
108 }
110 /* searches in ancestors of addr1 */
111 gboolean
112 addr_isequal_parent(address* addr1, address* addr2, int (*cmpfunc) (const char*, const char*))
113 {
114 address *addr;
116 for (addr = addr1; addr; addr = addr->parent)
117 if (addr_isequal(addr, addr2, cmpfunc))
118 return TRUE;
120 return FALSE;
121 }
123 /* careful, this is recursive */
124 /* returns TRUE if ALL children have been delivered */
125 gboolean
126 addr_is_delivered_children(address * addr)
127 {
128 GList *addr_node;
130 if (addr->children == NULL)
131 return addr_is_delivered(addr);
133 foreach(addr->children, addr_node) {
134 address *addr = (address *) (addr_node->data);
135 if (!addr_is_delivered_children(addr))
136 return FALSE;
137 }
138 return TRUE;
139 }
141 /* careful, this is recursive */
142 /* returns TRUE if ALL children have been either delivered or have failed */
143 gboolean
144 addr_is_finished_children(address * addr)
145 {
146 GList *addr_node;
148 if (addr->children == NULL)
149 return (addr_is_failed(addr) || addr_is_delivered(addr));
151 foreach(addr->children, addr_node) {
152 address *addr = (address *) (addr_node->data);
153 if (!addr_is_finished_children(addr))
154 return FALSE;
155 }
156 return TRUE;
157 }
159 /* find original address */
160 address*
161 addr_find_ancestor(address * addr)
162 {
163 while (addr->parent)
164 addr = addr->parent;
165 return addr;
166 }
168 gchar*
169 addr_string(address * addr)
170 {
171 static gchar *buffer = NULL;
173 if (addr == NULL) {
174 g_free(buffer);
175 buffer = NULL;
176 return NULL;
177 }
178 if (buffer)
179 g_free(buffer);
181 if (addr->local_part[0] == '\0') {
182 buffer = g_strdup("<>");
183 } else {
184 buffer = g_strdup_printf("<%s@%s>", addr->local_part ? addr->local_part : "", addr->domain ? addr->domain : "");
185 }
186 return buffer;
187 }