masqmail

view src/address.c @ 405:0dd84c8f2524

Broke long lines.
author markus schnalke <meillo@marmaro.de>
date Wed, 29 Feb 2012 10:28:23 +0100
parents b27f66555ba8
children 9b93c0a3bd8c
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_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_strchomp(g_strdup(path));
54 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");
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_strdup(orig->address);
82 addr->local_part = l_part ? g_strdup(l_part) :
83 g_strdup(orig->local_part);
84 addr->domain = dom ? g_strdup(dom) : g_strdup(orig->domain);
85 addr->flags = 0;
86 addr->children = NULL;
87 addr->parent = NULL;
88 return addr;
89 }
91 gboolean
92 addr_isequal(address *addr1, address *addr2,
93 int (*cmpfunc) (const char*, const char*))
94 {
95 return (cmpfunc(addr1->local_part, addr2->local_part)==0) &&
96 (strcasecmp(addr1->domain, addr2->domain)==0);
97 }
99 /* searches in ancestors of addr1 */
100 gboolean
101 addr_isequal_parent(address *addr1, address *addr2,
102 int (*cmpfunc) (const char*, const char*))
103 {
104 address *addr;
106 for (addr = addr1; addr; addr = addr->parent) {
107 if (addr_isequal(addr, addr2, cmpfunc)) {
108 return TRUE;
109 }
110 }
111 return FALSE;
112 }
114 /* careful, this is recursive */
115 /* returns TRUE if ALL children have been delivered */
116 gboolean
117 addr_is_delivered_children(address *addr)
118 {
119 GList *addr_node;
121 if (!addr->children) {
122 return addr_is_delivered(addr);
123 }
124 foreach(addr->children, addr_node) {
125 address *addr = (address *) (addr_node->data);
126 if (!addr_is_delivered_children(addr)) {
127 return FALSE;
128 }
129 }
130 return TRUE;
131 }
133 /* careful, this is recursive */
134 /* returns TRUE if ALL children have been either delivered or have failed */
135 gboolean
136 addr_is_finished_children(address *addr)
137 {
138 GList *addr_node;
140 if (!addr->children) {
141 return (addr_is_failed(addr) || addr_is_delivered(addr));
142 }
143 foreach(addr->children, addr_node) {
144 address *addr = (address *) (addr_node->data);
145 if (!addr_is_finished_children(addr)) {
146 return FALSE;
147 }
148 }
149 return TRUE;
150 }
152 /* find original address */
153 address*
154 addr_find_ancestor(address *addr)
155 {
156 while (addr->parent) {
157 addr = addr->parent;
158 }
159 return addr;
160 }
162 gchar*
163 addr_string(address *addr)
164 {
165 static gchar *buffer = NULL;
167 if (!addr) {
168 g_free(buffer);
169 buffer = NULL;
170 return NULL;
171 }
172 if (buffer) {
173 g_free(buffer);
174 }
175 if (!*addr->local_part) {
176 buffer = g_strdup("<>");
177 } else {
178 buffer = g_strdup_printf("<%s@%s>",
179 addr->local_part ? addr->local_part : "",
180 addr->domain ? addr->domain : "");
181 }
182 return buffer;
183 }