Commit | Line | Data |
---|---|---|
0756eb3c PH |
1 | /************************************************* |
2 | * Exim - an Internet mail transport agent * | |
3 | *************************************************/ | |
4 | ||
3386088d | 5 | /* Copyright (c) University of Cambridge 1995 - 2015 */ |
0756eb3c PH |
6 | /* See the file NOTICE for conditions of use and distribution. */ |
7 | ||
8 | #include "../exim.h" | |
9 | #include "rf_functions.h" | |
10 | ||
11 | ||
12 | /************************************************* | |
13 | * Get additional headers for a router * | |
14 | *************************************************/ | |
15 | ||
76146973 | 16 | /* This function is called by routers to sort out the additional headers |
0756eb3c PH |
17 | and header remove list for a particular address. |
18 | ||
19 | Arguments: | |
20 | addr the input address | |
21 | rblock the router instance | |
22 | extra_headers points to where to hang the header chain | |
23 | remove_headers points to where to hang the remove list | |
24 | ||
25 | Returns: OK if no problem | |
26 | DEFER if expanding a string caused a deferment | |
27 | or a big disaster (e.g. expansion failure) | |
28 | */ | |
29 | ||
30 | int | |
31 | rf_get_munge_headers(address_item *addr, router_instance *rblock, | |
32 | header_line **extra_headers, uschar **remove_headers) | |
33 | { | |
34 | /* Default is to retain existing headers */ | |
d43cbe25 | 35 | *extra_headers = addr->prop.extra_headers; |
0756eb3c | 36 | |
76146973 | 37 | if (rblock->extra_headers) |
0756eb3c | 38 | { |
55414b25 | 39 | const uschar * list = rblock->extra_headers; |
76146973 JH |
40 | int sep = '\n'; |
41 | uschar * s; | |
42 | int slen; | |
0756eb3c | 43 | |
76146973 JH |
44 | while ((s = string_nextinlist(&list, &sep, NULL, 0))) |
45 | if (!(s = expand_string(s))) | |
0756eb3c | 46 | { |
76146973 JH |
47 | if (!expand_string_forcedfail) |
48 | { | |
7325e67c JH |
49 | addr->message = string_sprintf( |
50 | "%s router failed to expand add_headers item \"%s\": %s", | |
51 | rblock->name, s, expand_string_message); | |
76146973 JH |
52 | return DEFER; |
53 | } | |
0756eb3c | 54 | } |
76146973 | 55 | else if ((slen = Ustrlen(s)) > 0) |
0756eb3c | 56 | { |
76146973 JH |
57 | /* Expand succeeded. Put extra headers at the start of the chain because |
58 | further down it may point to headers from other routers, which may be | |
59 | shared with other addresses. The output function outputs them in reverse | |
60 | order. */ | |
61 | ||
62 | header_line * h = store_get(sizeof(header_line)); | |
0756eb3c PH |
63 | |
64 | /* We used to use string_sprintf() to add the newline if needed, but that | |
65 | causes problems if the header line is exceedingly long (e.g. adding | |
66 | something to a pathologically long line). So avoid it. */ | |
67 | ||
68 | if (s[slen-1] == '\n') | |
76146973 | 69 | h->text = s; |
0756eb3c | 70 | else |
76146973 JH |
71 | { |
72 | h->text = store_get(slen+2); | |
73 | memcpy(h->text, s, slen); | |
74 | h->text[slen++] = '\n'; | |
75 | h->text[slen] = 0; | |
76 | } | |
77 | ||
78 | h->next = *extra_headers; | |
0756eb3c PH |
79 | h->type = htype_other; |
80 | h->slen = slen; | |
81 | *extra_headers = h; | |
82 | } | |
0756eb3c PH |
83 | } |
84 | ||
85 | /* Default is to retain existing removes */ | |
d43cbe25 | 86 | *remove_headers = addr->prop.remove_headers; |
0756eb3c | 87 | |
76146973 JH |
88 | /* Expand items from colon-sep list separately, then build new list */ |
89 | if (rblock->remove_headers) | |
0756eb3c | 90 | { |
55414b25 | 91 | const uschar * list = rblock->remove_headers; |
76146973 JH |
92 | int sep = ':'; |
93 | uschar * s; | |
4226691b JH |
94 | int size = 0, len = 0; |
95 | ||
96 | if (*remove_headers) | |
97 | size = (len = Ustrlen(*remove_headers)) + 1; | |
76146973 | 98 | |
97f83c7a | 99 | while ((s = string_nextinlist(&list, &sep, NULL, 0))) |
76146973 | 100 | if (!(s = expand_string(s))) |
0756eb3c | 101 | { |
76146973 JH |
102 | if (!expand_string_forcedfail) |
103 | { | |
7325e67c JH |
104 | addr->message = string_sprintf( |
105 | "%s router failed to expand remove_headers item \"%s\": %s", | |
106 | rblock->name, s, expand_string_message); | |
76146973 JH |
107 | return DEFER; |
108 | } | |
0756eb3c | 109 | } |
76146973 | 110 | else if (*s) |
4226691b | 111 | *remove_headers = string_append_listele(*remove_headers, &size, &len, ':', s); |
0756eb3c PH |
112 | } |
113 | ||
114 | return OK; | |
115 | } | |
116 | ||
7325e67c JH |
117 | /* vi: aw ai sw=4 |
118 | */ | |
0756eb3c | 119 | /* End of rf_get_munge_headers.c */ |