annotate src/rewrite.c @ 323:29de6a1c4538

Fixed an important bug with folded headers! g_strconcat() returns a *copy* of the string, but hdr->value still pointed to the old header (which probably was a memory leak, too). If the folded part had been quite small it was likely that the new string was at the same position as the old one, thus making everything go well. But if pretty long headers were folded several times it was likely that the new string was allocated somewhere else in memory, thus breaking things. In result mails to lots of recipients (folded header) were frequently only sent to the ones in the first line. Sorry for the inconvenience.
author meillo@marmaro.de
date Fri, 03 Jun 2011 09:47:27 +0200
parents 681863fdafbb
children 41958685480d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
1 /* MasqMail
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
2 Copyright (C) 1999-2001 Oliver Kurth
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
3
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
6 the Free Software Foundation; either version 2 of the License, or
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
7 (at your option) any later version.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
8
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
12 GNU General Public License for more details.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
13
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
15 along with this program; if not, write to the Free Software
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
17 */
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
18
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
19 #ifndef REWRITE_TEST
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
20 #include "masqmail.h"
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
21 #endif
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
22
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
23 gboolean
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
24 set_address_header_domain(header * hdr, gchar * domain)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
25 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
26 gchar *p = hdr->value;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
27 gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
28 gint tmp;
272
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
29 gchar *loc_beg, *loc_end;
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
30 gchar *dom_beg, *dom_end;
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
31 gchar *addr_end;
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
32 gchar *rewr_string;
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
33 gchar *left, *right;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
34
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
35 while (*p) {
272
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
36 if (!parse_address_rfc822(p, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)) {
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
37 return FALSE;
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
38 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
39
272
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
40 if (dom_beg) {
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
41 left = g_strndup(p, dom_beg - p);
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
42 right = g_strndup(dom_end, addr_end - dom_end);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
43
272
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
44 rewr_string = g_strconcat(left, domain, right, NULL);
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
45 } else {
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
46 left = g_strndup(p, loc_end - p);
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
47 right = g_strndup(loc_end, addr_end - loc_end);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
48
272
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
49 rewr_string = g_strconcat(left, "@", domain, right, NULL);
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
50 }
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
51 g_free(left);
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
52 g_free(right);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
53
272
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
54 p = addr_end;
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
55 if (*p == ',') {
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
56 p++;
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
57 }
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
58 new_hdr = g_strconcat(new_hdr, rewr_string, *p != '\0' ? "," : NULL, NULL);
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
59 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
60
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
61 tmp = (hdr->value - hdr->header);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
62 g_free(hdr->header);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
63 hdr->header = new_hdr;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
64 hdr->value = hdr->header + tmp;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
65
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
66 return TRUE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
67 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
68
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
69 gboolean
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
70 map_address_header(header * hdr, GList * table)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
71 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
72 GList *addr_list = addr_list_append_rfc822(NULL, hdr->value, conf.host_name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
73 GList *addr_node;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
74 gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
75 gboolean did_change = FALSE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
76
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
77 foreach(addr_list, addr_node) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
78 address *addr = (address *) (addr_node->data);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
79 gchar *rewr_string = (gchar *) table_find_fnmatch(table, addr->local_part);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
80
272
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
81 if (rewr_string) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
82 did_change = TRUE;
272
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
83 } else {
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
84 rewr_string = addr->address;
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
85 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
86
272
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
87 if (rewr_string) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
88 new_hdr = g_strconcat(new_hdr, rewr_string, g_list_next(addr_node) ? "," : "\n", NULL);
272
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
89 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
90 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
91 if (did_change) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
92 g_free(hdr->header);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
93 hdr->header = new_hdr;
272
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
94 } else {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
95 g_free(new_hdr);
272
681863fdafbb refactoring in the small
markus schnalke <meillo@marmaro.de>
parents: 15
diff changeset
96 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
97
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
98 return did_change;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
99 }