Mercurial > masqmail
comparison src/rewrite.c @ 0:08114f7dcc23 0.2.21
this is masqmail-0.2.21 from oliver kurth
author | meillo@marmaro.de |
---|---|
date | Fri, 26 Sep 2008 17:05:23 +0200 |
parents | |
children | 26e34ae9a3e3 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:08114f7dcc23 |
---|---|
1 /* MasqMail | |
2 Copyright (C) 1999-2001 Oliver Kurth | |
3 | |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 2 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program; if not, write to the Free Software | |
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 */ | |
18 | |
19 #ifndef REWRITE_TEST | |
20 #include "masqmail.h" | |
21 #endif | |
22 | |
23 gboolean set_address_header_domain(header *hdr, gchar *domain) | |
24 { | |
25 gchar *p = hdr->value; | |
26 gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header); | |
27 gint tmp; | |
28 | |
29 while(*p){ | |
30 gchar *loc_beg, *loc_end; | |
31 gchar *dom_beg, *dom_end; | |
32 gchar *addr_end; | |
33 gchar *rewr_string; | |
34 | |
35 if(parse_address_rfc822(p, | |
36 &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)){ | |
37 gchar *left, *right; | |
38 | |
39 if(dom_beg != NULL){ | |
40 left = g_strndup(p, dom_beg - p); | |
41 right = g_strndup(dom_end, addr_end - dom_end); | |
42 | |
43 rewr_string = g_strconcat(left, domain, right, NULL); | |
44 }else{ | |
45 left = g_strndup(p, loc_end - p); | |
46 right = g_strndup(loc_end, addr_end - loc_end); | |
47 | |
48 rewr_string = g_strconcat(left, "@", domain, right, NULL); | |
49 } | |
50 g_free(left); | |
51 g_free(right); | |
52 | |
53 p = addr_end; | |
54 if(*p == ',') p++; | |
55 | |
56 new_hdr = | |
57 g_strconcat(new_hdr, rewr_string, | |
58 *p != 0 ? "," : NULL, NULL); | |
59 | |
60 }else | |
61 return FALSE; | |
62 } | |
63 tmp = (hdr->value - hdr->header); | |
64 g_free(hdr->header); | |
65 hdr->header = new_hdr; | |
66 hdr->value = hdr->header + tmp; | |
67 | |
68 return TRUE; | |
69 } | |
70 | |
71 gboolean 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; | |
77 | |
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); | |
81 | |
82 if(rewr_string == NULL) | |
83 rewr_string = addr->address; | |
84 else | |
85 did_change = TRUE; | |
86 | |
87 if(rewr_string) | |
88 new_hdr = | |
89 g_strconcat(new_hdr, rewr_string, | |
90 g_list_next(addr_node) ? "," : "\n", NULL); | |
91 } | |
92 if(did_change){ | |
93 g_free(hdr->header); | |
94 hdr->header = new_hdr; | |
95 }else | |
96 g_free(new_hdr); | |
97 | |
98 return did_change; | |
99 } | |
100 |