masqmail
view src/address.c @ 428:e972c3cbe1e0
Bugfix: Read as long as there *is* content.
Before this fix masqmail did not read the contents of files that
were given as values to config items.
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Wed, 03 Apr 2013 21:45:57 +0200 |
parents | bc9a7845b53a |
children |
line source
1 /*
2 ** MasqMail
3 ** Copyright (C) 1999-2001 Oliver Kurth
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 */
20 #include "masqmail.h"
22 address*
23 create_address(gchar *path, gboolean is_rfc821)
24 {
25 address *addr;
26 addr = _create_address(path, NULL, is_rfc821);
28 if (addr) {
29 addr_unmark_delivered(addr);
30 }
31 return addr;
32 }
34 address*
35 create_address_qualified(gchar *path, gboolean is_rfc821, gchar *domain)
36 {
37 address *addr = create_address(path, is_rfc821);
39 if (addr && !addr->domain) {
40 addr->domain = g_strstrip(g_strdup(domain));
41 }
42 return addr;
43 }
45 /* nothing special about pipes here, but its only called for that purpose */
46 address*
47 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_strstrip(g_strdup(path));
54 addr->local_part = g_strstrip(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");
64 g_free(addr->address);
65 g_free(addr->local_part);
66 g_free(addr->domain);
67 g_free(addr);
68 }
70 address*
71 copy_modify_address(const address *orig, gchar *l_part, gchar *dom)
72 {
73 address *addr = NULL;
75 if (!orig) {
76 return NULL;
77 }
78 if (!(addr = g_malloc(sizeof(address)))) {
79 return NULL;
80 }
81 addr->address = g_strstrip(g_strdup(orig->address));
82 addr->local_part = g_strstrip(l_part ? g_strdup(l_part) :
83 g_strdup(orig->local_part));
84 addr->domain = g_strstrip(dom ? g_strdup(dom) :
85 g_strdup(orig->domain));
86 addr->flags = 0;
87 addr->children = NULL;
88 addr->parent = NULL;
89 return addr;
90 }
92 gboolean
93 addr_isequal(address *addr1, address *addr2,
94 int (*cmpfunc) (const char*, const char*))
95 {
96 return (cmpfunc(addr1->local_part, addr2->local_part)==0) &&
97 (strcasecmp(addr1->domain, addr2->domain)==0);
98 }
100 /* searches in ancestors of addr1 */
101 gboolean
102 addr_isequal_parent(address *addr1, address *addr2,
103 int (*cmpfunc) (const char*, const char*))
104 {
105 address *addr;
107 for (addr = addr1; addr; addr = addr->parent) {
108 if (addr_isequal(addr, addr2, cmpfunc)) {
109 return TRUE;
110 }
111 }
112 return FALSE;
113 }
115 /* careful, this is recursive */
116 /* returns TRUE if ALL children have been delivered */
117 gboolean
118 addr_is_delivered_children(address *addr)
119 {
120 GList *addr_node;
122 if (!addr->children) {
123 return addr_is_delivered(addr);
124 }
125 foreach(addr->children, addr_node) {
126 address *addr = (address *) (addr_node->data);
127 if (!addr_is_delivered_children(addr)) {
128 return FALSE;
129 }
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
137 addr_is_finished_children(address *addr)
138 {
139 GList *addr_node;
141 if (!addr->children) {
142 return (addr_is_failed(addr) || addr_is_delivered(addr));
143 }
144 foreach(addr->children, addr_node) {
145 address *addr = (address *) (addr_node->data);
146 if (!addr_is_finished_children(addr)) {
147 return FALSE;
148 }
149 }
150 return TRUE;
151 }
153 /* find original address */
154 address*
155 addr_find_ancestor(address *addr)
156 {
157 while (addr->parent) {
158 addr = addr->parent;
159 }
160 return addr;
161 }
163 gchar*
164 addr_string(address *addr)
165 {
166 static gchar *buffer = NULL;
168 if (buffer) {
169 g_free(buffer);
170 }
171 if (!addr) {
172 return NULL;
173 }
174 if (!*addr->local_part) {
175 buffer = g_strdup("<>");
176 } else {
177 buffer = g_strdup_printf("<%s@%s>",
178 addr->local_part ? addr->local_part : "",
179 addr->domain ? addr->domain : "");
180 }
181 return buffer;
182 }