masqmail

annotate src/rewrite.c @ 1:af25f5c39d90

added diff from debian (masqmail-0.2.21-4)
author meillo@marmaro.de
date Fri, 26 Sep 2008 20:56:23 +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 #ifndef REWRITE_TEST
meillo@0 20 #include "masqmail.h"
meillo@0 21 #endif
meillo@0 22
meillo@0 23 gboolean set_address_header_domain(header *hdr, gchar *domain)
meillo@0 24 {
meillo@0 25 gchar *p = hdr->value;
meillo@0 26 gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header);
meillo@0 27 gint tmp;
meillo@0 28
meillo@0 29 while(*p){
meillo@0 30 gchar *loc_beg, *loc_end;
meillo@0 31 gchar *dom_beg, *dom_end;
meillo@0 32 gchar *addr_end;
meillo@0 33 gchar *rewr_string;
meillo@0 34
meillo@0 35 if(parse_address_rfc822(p,
meillo@0 36 &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)){
meillo@0 37 gchar *left, *right;
meillo@0 38
meillo@0 39 if(dom_beg != NULL){
meillo@0 40 left = g_strndup(p, dom_beg - p);
meillo@0 41 right = g_strndup(dom_end, addr_end - dom_end);
meillo@0 42
meillo@0 43 rewr_string = g_strconcat(left, domain, right, NULL);
meillo@0 44 }else{
meillo@0 45 left = g_strndup(p, loc_end - p);
meillo@0 46 right = g_strndup(loc_end, addr_end - loc_end);
meillo@0 47
meillo@0 48 rewr_string = g_strconcat(left, "@", domain, right, NULL);
meillo@0 49 }
meillo@0 50 g_free(left);
meillo@0 51 g_free(right);
meillo@0 52
meillo@0 53 p = addr_end;
meillo@0 54 if(*p == ',') p++;
meillo@0 55
meillo@0 56 new_hdr =
meillo@0 57 g_strconcat(new_hdr, rewr_string,
meillo@0 58 *p != 0 ? "," : NULL, NULL);
meillo@0 59
meillo@0 60 }else
meillo@0 61 return FALSE;
meillo@0 62 }
meillo@0 63 tmp = (hdr->value - hdr->header);
meillo@0 64 g_free(hdr->header);
meillo@0 65 hdr->header = new_hdr;
meillo@0 66 hdr->value = hdr->header + tmp;
meillo@0 67
meillo@0 68 return TRUE;
meillo@0 69 }
meillo@0 70
meillo@0 71 gboolean map_address_header(header *hdr, GList *table)
meillo@0 72 {
meillo@0 73 GList *addr_list = addr_list_append_rfc822(NULL, hdr->value, conf.host_name);
meillo@0 74 GList *addr_node;
meillo@0 75 gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header);
meillo@0 76 gboolean did_change = FALSE;
meillo@0 77
meillo@0 78 foreach(addr_list, addr_node){
meillo@0 79 address *addr = (address *)(addr_node->data);
meillo@0 80 gchar *rewr_string = (gchar *)table_find_fnmatch(table, addr->local_part);
meillo@0 81
meillo@0 82 if(rewr_string == NULL)
meillo@0 83 rewr_string = addr->address;
meillo@0 84 else
meillo@0 85 did_change = TRUE;
meillo@0 86
meillo@0 87 if(rewr_string)
meillo@0 88 new_hdr =
meillo@0 89 g_strconcat(new_hdr, rewr_string,
meillo@0 90 g_list_next(addr_node) ? "," : "\n", NULL);
meillo@0 91 }
meillo@0 92 if(did_change){
meillo@0 93 g_free(hdr->header);
meillo@0 94 hdr->header = new_hdr;
meillo@0 95 }else
meillo@0 96 g_free(new_hdr);
meillo@0 97
meillo@0 98 return did_change;
meillo@0 99 }
meillo@0 100