masqmail

view 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
line source
1 /*
2 ** MasqMail
3 ** Copyright (C) 1999-2001 Oliver Kurth
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
20 #ifndef REWRITE_TEST
21 #include "masqmail.h"
22 #endif
24 gboolean
25 set_address_header_domain(header *hdr, gchar *domain)
26 {
27 gchar *p = hdr->value;
28 gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header);
29 gint tmp;
30 gchar *loc_beg, *loc_end;
31 gchar *dom_beg, *dom_end;
32 gchar *addr_end;
33 gchar *rewr_string;
34 gchar *left, *right;
36 while (*p) {
37 if (!parse_address_rfc822(p, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)) {
38 return FALSE;
39 }
41 if (dom_beg) {
42 left = g_strndup(p, dom_beg - p);
43 right = g_strndup(dom_end, addr_end - dom_end);
45 rewr_string = g_strconcat(left, domain, right, NULL);
46 } else {
47 left = g_strndup(p, loc_end - p);
48 right = g_strndup(loc_end, addr_end - loc_end);
50 rewr_string = g_strconcat(left, "@", domain, right, NULL);
51 }
52 g_free(left);
53 g_free(right);
55 p = addr_end;
56 if (*p == ',') {
57 p++;
58 }
59 new_hdr = g_strconcat(new_hdr, rewr_string, *p != '\0' ? "," : NULL, NULL);
60 }
62 tmp = (hdr->value - hdr->header);
63 g_free(hdr->header);
64 hdr->header = new_hdr;
65 hdr->value = hdr->header + tmp;
67 return TRUE;
68 }
70 gboolean
71 map_address_header(header *hdr, GList *table)
72 {
73 GList *addr_list = addr_list_append_rfc822(NULL, hdr->value, conf.host_name);
74 GList *addr_node;
75 gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header);
76 gboolean did_change = FALSE;
78 foreach(addr_list, addr_node) {
79 address *addr = (address *) (addr_node->data);
80 gchar *rewr_string = (gchar *) table_find_fnmatch(table, addr->local_part);
82 if (rewr_string) {
83 did_change = TRUE;
84 } else {
85 rewr_string = addr->address;
86 }
88 if (rewr_string) {
89 new_hdr = g_strconcat(new_hdr, rewr_string, g_list_next(addr_node) ? "," : "\n", NULL);
90 }
91 }
92 if (did_change) {
93 g_free(hdr->header);
94 hdr->header = new_hdr;
95 } else {
96 g_free(new_hdr);
97 }
99 return did_change;
100 }