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@10: gboolean meillo@10: set_address_header_domain(header * hdr, gchar * domain) meillo@0: { meillo@10: gchar *p = hdr->value; meillo@10: gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header); meillo@10: gint tmp; meillo@0: meillo@10: while (*p) { meillo@10: gchar *loc_beg, *loc_end; meillo@10: gchar *dom_beg, *dom_end; meillo@10: gchar *addr_end; meillo@10: gchar *rewr_string; meillo@0: meillo@10: if (parse_address_rfc822(p, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)) { meillo@10: gchar *left, *right; meillo@0: meillo@10: if (dom_beg != NULL) { meillo@10: left = g_strndup(p, dom_beg - p); meillo@10: right = g_strndup(dom_end, addr_end - dom_end); meillo@0: meillo@10: rewr_string = g_strconcat(left, domain, right, NULL); meillo@10: } else { meillo@10: left = g_strndup(p, loc_end - p); meillo@10: right = g_strndup(loc_end, addr_end - loc_end); meillo@0: meillo@10: rewr_string = g_strconcat(left, "@", domain, right, NULL); meillo@10: } meillo@10: g_free(left); meillo@10: g_free(right); meillo@0: meillo@10: p = addr_end; meillo@10: if (*p == ',') meillo@10: p++; meillo@0: meillo@15: new_hdr = g_strconcat(new_hdr, rewr_string, *p != '\0' ? "," : NULL, NULL); meillo@0: meillo@10: } else meillo@10: return FALSE; meillo@10: } meillo@10: tmp = (hdr->value - hdr->header); meillo@10: g_free(hdr->header); meillo@10: hdr->header = new_hdr; meillo@10: hdr->value = hdr->header + tmp; meillo@0: meillo@10: return TRUE; meillo@0: } meillo@0: meillo@10: gboolean meillo@10: map_address_header(header * hdr, GList * table) meillo@0: { meillo@10: GList *addr_list = addr_list_append_rfc822(NULL, hdr->value, conf.host_name); meillo@10: GList *addr_node; meillo@10: gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header); meillo@10: gboolean did_change = FALSE; meillo@0: meillo@10: foreach(addr_list, addr_node) { meillo@10: address *addr = (address *) (addr_node->data); meillo@10: gchar *rewr_string = (gchar *) table_find_fnmatch(table, addr->local_part); meillo@0: meillo@10: if (rewr_string == NULL) meillo@10: rewr_string = addr->address; meillo@10: else meillo@10: did_change = TRUE; meillo@0: meillo@10: if (rewr_string) meillo@10: new_hdr = g_strconcat(new_hdr, rewr_string, g_list_next(addr_node) ? "," : "\n", NULL); meillo@10: } meillo@10: if (did_change) { meillo@10: g_free(hdr->header); meillo@10: hdr->header = new_hdr; meillo@10: } else meillo@10: g_free(new_hdr); meillo@0: meillo@10: return did_change; meillo@0: }