Mercurial > masqmail
annotate src/rewrite.c @ 434:f2a7271746d1 default tip
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 | b27f66555ba8 |
children |
rev | line source |
---|---|
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
1 /* |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
2 ** MasqMail |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
3 ** Copyright (C) 1999-2001 Oliver Kurth |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
4 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
5 ** This program is free software; you can redistribute it and/or modify |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
6 ** it under the terms of the GNU General Public License as published by |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
7 ** the Free Software Foundation; either version 2 of the License, or |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
8 ** (at your option) any later version. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
9 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
10 ** This program is distributed in the hope that it will be useful, |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
13 ** GNU General Public License for more details. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
14 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
15 ** You should have received a copy of the GNU General Public License |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
16 ** along with this program; if not, write to the Free Software |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
0 | 18 */ |
19 | |
20 #ifndef REWRITE_TEST | |
21 #include "masqmail.h" | |
22 #endif | |
23 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
24 gboolean |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
272
diff
changeset
|
25 set_address_header_domain(header *hdr, gchar *domain) |
0 | 26 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
27 gchar *p = hdr->value; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
28 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
|
29 gint tmp; |
272
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
30 gchar *loc_beg, *loc_end; |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
31 gchar *dom_beg, *dom_end; |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
32 gchar *addr_end; |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
33 gchar *rewr_string; |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
34 gchar *left, *right; |
0 | 35 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
36 while (*p) { |
272
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
37 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
|
38 return FALSE; |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
39 } |
0 | 40 |
272
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
41 if (dom_beg) { |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
42 left = g_strndup(p, dom_beg - p); |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
43 right = g_strndup(dom_end, addr_end - dom_end); |
0 | 44 |
272
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
45 rewr_string = g_strconcat(left, domain, right, NULL); |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
46 } else { |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
47 left = g_strndup(p, loc_end - p); |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
48 right = g_strndup(loc_end, addr_end - loc_end); |
0 | 49 |
272
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
50 rewr_string = g_strconcat(left, "@", domain, right, NULL); |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
51 } |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
52 g_free(left); |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
53 g_free(right); |
0 | 54 |
272
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
55 p = addr_end; |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
56 if (*p == ',') { |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
57 p++; |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
58 } |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
59 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
|
60 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
61 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
62 tmp = (hdr->value - hdr->header); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
63 g_free(hdr->header); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
64 hdr->header = new_hdr; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
65 hdr->value = hdr->header + tmp; |
0 | 66 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
67 return TRUE; |
0 | 68 } |
69 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
70 gboolean |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
272
diff
changeset
|
71 map_address_header(header *hdr, GList *table) |
0 | 72 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
73 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
|
74 GList *addr_node; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
75 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
|
76 gboolean did_change = FALSE; |
0 | 77 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
78 foreach(addr_list, addr_node) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
79 address *addr = (address *) (addr_node->data); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
80 gchar *rewr_string = (gchar *) table_find_fnmatch(table, addr->local_part); |
0 | 81 |
272
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
82 if (rewr_string) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
83 did_change = TRUE; |
272
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
84 } else { |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
85 rewr_string = addr->address; |
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
86 } |
0 | 87 |
272
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
88 if (rewr_string) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
89 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
|
90 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
91 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
92 if (did_change) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
93 g_free(hdr->header); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
94 hdr->header = new_hdr; |
272
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
95 } else { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
96 g_free(new_hdr); |
272
681863fdafbb
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
15
diff
changeset
|
97 } |
0 | 98 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
99 return did_change; |
0 | 100 } |