meillo@0: /* MasqMail meillo@0: Copyright (C) 1999-2001 Oliver Kurth meillo@0: meillo@0: This program is free software; you can redistribute it and/or modify meillo@0: it under the terms of the GNU General Public License as published by meillo@0: the Free Software Foundation; either version 2 of the License, or meillo@0: (at your option) any later version. meillo@0: meillo@0: This program is distributed in the hope that it will be useful, meillo@0: but WITHOUT ANY WARRANTY; without even the implied warranty of meillo@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the meillo@0: GNU General Public License for more details. meillo@0: meillo@0: You should have received a copy of the GNU General Public License meillo@0: along with this program; if not, write to the Free Software meillo@0: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. meillo@0: */ meillo@0: meillo@0: #ifndef REWRITE_TEST meillo@0: #include "masqmail.h" meillo@0: #endif meillo@0: meillo@0: gboolean set_address_header_domain(header *hdr, gchar *domain) meillo@0: { meillo@0: gchar *p = hdr->value; meillo@0: gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header); meillo@0: gint tmp; meillo@0: meillo@0: while(*p){ meillo@0: gchar *loc_beg, *loc_end; meillo@0: gchar *dom_beg, *dom_end; meillo@0: gchar *addr_end; meillo@0: gchar *rewr_string; meillo@0: meillo@0: if(parse_address_rfc822(p, meillo@0: &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)){ meillo@0: gchar *left, *right; meillo@0: meillo@0: if(dom_beg != NULL){ meillo@0: left = g_strndup(p, dom_beg - p); meillo@0: right = g_strndup(dom_end, addr_end - dom_end); meillo@0: meillo@0: rewr_string = g_strconcat(left, domain, right, NULL); meillo@0: }else{ meillo@0: left = g_strndup(p, loc_end - p); meillo@0: right = g_strndup(loc_end, addr_end - loc_end); meillo@0: meillo@0: rewr_string = g_strconcat(left, "@", domain, right, NULL); meillo@0: } meillo@0: g_free(left); meillo@0: g_free(right); meillo@0: meillo@0: p = addr_end; meillo@0: if(*p == ',') p++; meillo@0: meillo@0: new_hdr = meillo@0: g_strconcat(new_hdr, rewr_string, meillo@0: *p != 0 ? "," : NULL, NULL); meillo@0: meillo@0: }else meillo@0: return FALSE; meillo@0: } meillo@0: tmp = (hdr->value - hdr->header); meillo@0: g_free(hdr->header); meillo@0: hdr->header = new_hdr; meillo@0: hdr->value = hdr->header + tmp; meillo@0: meillo@0: return TRUE; meillo@0: } meillo@0: meillo@0: gboolean map_address_header(header *hdr, GList *table) meillo@0: { meillo@0: GList *addr_list = addr_list_append_rfc822(NULL, hdr->value, conf.host_name); meillo@0: GList *addr_node; meillo@0: gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header); meillo@0: gboolean did_change = FALSE; meillo@0: meillo@0: foreach(addr_list, addr_node){ meillo@0: address *addr = (address *)(addr_node->data); meillo@0: gchar *rewr_string = (gchar *)table_find_fnmatch(table, addr->local_part); meillo@0: meillo@0: if(rewr_string == NULL) meillo@0: rewr_string = addr->address; meillo@0: else meillo@0: did_change = TRUE; meillo@0: meillo@0: if(rewr_string) meillo@0: new_hdr = meillo@0: g_strconcat(new_hdr, rewr_string, meillo@0: g_list_next(addr_node) ? "," : "\n", NULL); meillo@0: } meillo@0: if(did_change){ meillo@0: g_free(hdr->header); meillo@0: hdr->header = new_hdr; meillo@0: }else meillo@0: g_free(new_hdr); meillo@0: meillo@0: return did_change; meillo@0: } meillo@0: