masqmail

annotate src/address.c @ 2:653aef34b225

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