masqmail

annotate src/rewrite.c @ 37:4fee89792559

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