masqmail

view src/rewrite.c @ 329:5ce2b1280679

Switched back from 127.0.0.1 to localhost Better be straight-forward than too clever.
author markus schnalke <meillo@marmaro.de>
date Wed, 13 Jul 2011 10:24:45 +0200
parents f671821d8222
children 41958685480d
line source
1 /* MasqMail
2 Copyright (C) 1999-2001 Oliver Kurth
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.
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.
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 */
19 #ifndef REWRITE_TEST
20 #include "masqmail.h"
21 #endif
23 gboolean
24 set_address_header_domain(header * hdr, gchar * domain)
25 {
26 gchar *p = hdr->value;
27 gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header);
28 gint tmp;
29 gchar *loc_beg, *loc_end;
30 gchar *dom_beg, *dom_end;
31 gchar *addr_end;
32 gchar *rewr_string;
33 gchar *left, *right;
35 while (*p) {
36 if (!parse_address_rfc822(p, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)) {
37 return FALSE;
38 }
40 if (dom_beg) {
41 left = g_strndup(p, dom_beg - p);
42 right = g_strndup(dom_end, addr_end - dom_end);
44 rewr_string = g_strconcat(left, domain, right, NULL);
45 } else {
46 left = g_strndup(p, loc_end - p);
47 right = g_strndup(loc_end, addr_end - loc_end);
49 rewr_string = g_strconcat(left, "@", domain, right, NULL);
50 }
51 g_free(left);
52 g_free(right);
54 p = addr_end;
55 if (*p == ',') {
56 p++;
57 }
58 new_hdr = g_strconcat(new_hdr, rewr_string, *p != '\0' ? "," : NULL, NULL);
59 }
61 tmp = (hdr->value - hdr->header);
62 g_free(hdr->header);
63 hdr->header = new_hdr;
64 hdr->value = hdr->header + tmp;
66 return TRUE;
67 }
69 gboolean
70 map_address_header(header * hdr, GList * table)
71 {
72 GList *addr_list = addr_list_append_rfc822(NULL, hdr->value, conf.host_name);
73 GList *addr_node;
74 gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header);
75 gboolean did_change = FALSE;
77 foreach(addr_list, addr_node) {
78 address *addr = (address *) (addr_node->data);
79 gchar *rewr_string = (gchar *) table_find_fnmatch(table, addr->local_part);
81 if (rewr_string) {
82 did_change = TRUE;
83 } else {
84 rewr_string = addr->address;
85 }
87 if (rewr_string) {
88 new_hdr = g_strconcat(new_hdr, rewr_string, g_list_next(addr_node) ? "," : "\n", NULL);
89 }
90 }
91 if (did_change) {
92 g_free(hdr->header);
93 hdr->header = new_hdr;
94 } else {
95 g_free(new_hdr);
96 }
98 return did_change;
99 }