masqmail

annotate src/rewrite.c @ 336:2d4aa516ba0e

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