masqmail-0.2

view src/address.c @ 9:31cc8a89cb74

removed tests from configure script
author meillo@marmaro.de
date Mon, 27 Oct 2008 16:21:27 +0100
parents
children 26e34ae9a3e3
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"
20 #include <fnmatch.h>
22 address *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 *create_address_qualified(gchar *path, gboolean is_rfc821,
34 gchar *domain)
35 {
36 address *addr = create_address(path, is_rfc821);
37 if(addr != NULL){
38 if(addr->domain == NULL)
39 addr->domain = g_strdup(domain);
40 }
42 return addr;
43 }
45 /* nothing special about pipes here,
46 but its only called for that purpose */
47 address *create_address_pipe(gchar *path)
48 {
49 address *addr = g_malloc(sizeof(address));
51 if(addr){
52 memset(addr, 0, sizeof(address));
53 addr->address = g_strchomp(g_strdup(path));
54 addr->local_part = g_strdup(addr->address);
56 addr->domain = g_strdup("localhost"); /* quick hack */
57 }
58 return addr;
59 }
61 void 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 *copy_modify_address(const address *orig, gchar *l_part, gchar *dom)
73 {
74 address *addr = NULL;
76 if(orig){
77 addr = g_malloc(sizeof(address));
78 if(addr){
79 addr->address = g_strdup(orig->address);
81 if(l_part == NULL)
82 addr->local_part = g_strdup(orig->local_part);
83 else
84 addr->local_part = g_strdup(l_part);
86 if(dom == NULL)
87 addr->domain = g_strdup(orig->domain);
88 else
89 addr->domain = g_strdup(dom);
91 addr->flags = 0;
92 addr->children = NULL;
93 addr->parent = NULL;
94 }
95 }
96 return addr;
97 }
99 gboolean addr_isequal(address *addr1, address *addr2)
100 {
101 return
102 (strcmp(addr1->local_part, addr2->local_part) == 0) &&
103 (strcasecmp(addr1->domain, addr2->domain) == 0);
104 }
106 /* searches in ancestors of addr1 */
107 gboolean addr_isequal_parent(address *addr1, address *addr2)
108 {
109 address *addr;
111 for(addr = addr1; addr; addr = addr->parent)
112 if(addr_isequal(addr, addr2))
113 return TRUE;
115 return FALSE;
116 }
118 /* careful, this is recursive */
119 /* returns TRUE if ALL children have been delivered */
120 gboolean addr_is_delivered_children(address *addr)
121 {
122 GList *addr_node;
124 if(addr->children == NULL) return addr_is_delivered(addr);
126 foreach(addr->children, addr_node){
127 address *addr = (address *)(addr_node->data);
128 if(!addr_is_delivered_children(addr))
129 return FALSE;
130 }
131 return TRUE;
132 }
134 /* careful, this is recursive */
135 /* returns TRUE if ALL children have been either delivered or have failed */
136 gboolean addr_is_finished_children(address *addr)
137 {
138 GList *addr_node;
140 if(addr->children == NULL) return (addr_is_failed(addr) || addr_is_delivered(addr));
142 foreach(addr->children, addr_node){
143 address *addr = (address *)(addr_node->data);
144 if(!addr_is_finished_children(addr))
145 return FALSE;
146 }
147 return TRUE;
148 }
150 /* find original address */
151 address *addr_find_ancestor(address *addr)
152 {
153 while(addr->parent) addr = addr->parent;
154 return addr;
155 }
157 gchar *addr_string(address *addr)
158 {
159 static gchar *buffer = NULL;
161 if(addr == NULL){
162 g_free(buffer);
163 buffer = NULL;
164 return NULL;
165 }
166 if(buffer)
167 g_free(buffer);
169 if(addr->local_part[0] == 0){
170 buffer = g_strdup("<>");
171 }else{
172 buffer = g_strdup_printf("<%s@%s>",
173 addr->local_part ? addr->local_part : "",
174 addr->domain ? addr->domain : "");
175 }
176 return buffer;
177 }
179 gint addr_match(address *addr1, address *addr2)
180 {
181 int res;
183 if((res = fnmatch(addr1->local_part, addr2->local_part, 0)) == 0){
184 if((res = fnmatch(addr1->domain, addr2->domain, FNM_CASEFOLD)) == 0)
185 return 0;
186 }
187 return res;
188 }