masqmail

annotate src/rewrite.c @ 434:f2a7271746d1

Removes Freshmeat.net from the docs The site, which was later renamed to freecode.com, is no longer maintained (contains only a static copy).
author markus schnalke <meillo@marmaro.de>
date Sat, 07 Feb 2015 11:45:07 +0100
parents 41958685480d
children
rev   line source
meillo@367 1 /*
meillo@367 2 ** MasqMail
meillo@367 3 ** Copyright (C) 1999-2001 Oliver Kurth
meillo@367 4 **
meillo@367 5 ** This program is free software; you can redistribute it and/or modify
meillo@367 6 ** it under the terms of the GNU General Public License as published by
meillo@367 7 ** the Free Software Foundation; either version 2 of the License, or
meillo@367 8 ** (at your option) any later version.
meillo@367 9 **
meillo@367 10 ** This program is distributed in the hope that it will be useful,
meillo@367 11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
meillo@367 12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
meillo@367 13 ** GNU General Public License for more details.
meillo@367 14 **
meillo@367 15 ** You should have received a copy of the GNU General Public License
meillo@367 16 ** along with this program; if not, write to the Free Software
meillo@367 17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
meillo@0 18 */
meillo@0 19
meillo@0 20 #ifndef REWRITE_TEST
meillo@0 21 #include "masqmail.h"
meillo@0 22 #endif
meillo@0 23
meillo@10 24 gboolean
meillo@366 25 set_address_header_domain(header *hdr, gchar *domain)
meillo@0 26 {
meillo@10 27 gchar *p = hdr->value;
meillo@10 28 gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header);
meillo@10 29 gint tmp;
meillo@272 30 gchar *loc_beg, *loc_end;
meillo@272 31 gchar *dom_beg, *dom_end;
meillo@272 32 gchar *addr_end;
meillo@272 33 gchar *rewr_string;
meillo@272 34 gchar *left, *right;
meillo@0 35
meillo@10 36 while (*p) {
meillo@272 37 if (!parse_address_rfc822(p, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)) {
meillo@272 38 return FALSE;
meillo@272 39 }
meillo@0 40
meillo@272 41 if (dom_beg) {
meillo@272 42 left = g_strndup(p, dom_beg - p);
meillo@272 43 right = g_strndup(dom_end, addr_end - dom_end);
meillo@0 44
meillo@272 45 rewr_string = g_strconcat(left, domain, right, NULL);
meillo@272 46 } else {
meillo@272 47 left = g_strndup(p, loc_end - p);
meillo@272 48 right = g_strndup(loc_end, addr_end - loc_end);
meillo@0 49
meillo@272 50 rewr_string = g_strconcat(left, "@", domain, right, NULL);
meillo@272 51 }
meillo@272 52 g_free(left);
meillo@272 53 g_free(right);
meillo@0 54
meillo@272 55 p = addr_end;
meillo@272 56 if (*p == ',') {
meillo@272 57 p++;
meillo@272 58 }
meillo@272 59 new_hdr = g_strconcat(new_hdr, rewr_string, *p != '\0' ? "," : NULL, NULL);
meillo@272 60 }
meillo@0 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@366 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@272 82 if (rewr_string) {
meillo@272 83 did_change = TRUE;
meillo@272 84 } else {
meillo@10 85 rewr_string = addr->address;
meillo@272 86 }
meillo@0 87
meillo@272 88 if (rewr_string) {
meillo@10 89 new_hdr = g_strconcat(new_hdr, rewr_string, g_list_next(addr_node) ? "," : "\n", NULL);
meillo@272 90 }
meillo@10 91 }
meillo@10 92 if (did_change) {
meillo@10 93 g_free(hdr->header);
meillo@10 94 hdr->header = new_hdr;
meillo@272 95 } else {
meillo@10 96 g_free(new_hdr);
meillo@272 97 }
meillo@0 98
meillo@10 99 return did_change;
meillo@0 100 }