1 /* $Cambridge: exim/src/src/routers/rf_get_munge_headers.c,v 1.3 2006/02/07 11:19:02 ph10 Exp $ */
3 /*************************************************
4 * Exim - an Internet mail transport agent *
5 *************************************************/
7 /* Copyright (c) University of Cambridge 1995 - 2006 */
8 /* See the file NOTICE for conditions of use and distribution. */
11 #include "rf_functions.h"
14 /*************************************************
15 * Get additional headers for a router *
16 *************************************************/
18 /* This function is called by both routers to sort out the additional headers
19 and header remove list for a particular address.
22 addr the input address
23 rblock the router instance
24 extra_headers points to where to hang the header chain
25 remove_headers points to where to hang the remove list
27 Returns: OK if no problem
28 DEFER if expanding a string caused a deferment
29 or a big disaster (e.g. expansion failure)
33 rf_get_munge_headers(address_item *addr, router_instance *rblock,
34 header_line **extra_headers, uschar **remove_headers)
36 /* Default is to retain existing headers */
38 *extra_headers = addr->p.extra_headers;
40 if (rblock->extra_headers != NULL)
43 uschar *s = expand_string(rblock->extra_headers);
47 if (!expand_string_forcedfail)
49 addr->message = string_sprintf("%s router failed to expand \"%s\": %s",
50 rblock->name, rblock->extra_headers, expand_string_message);
55 /* Expand succeeded. Put extra header at the start of the chain because
56 further down it may point to headers from other routers, which may be
57 shared with other addresses. The output function outputs them in reverse
62 int slen = Ustrlen(s);
65 h = store_get(sizeof(header_line));
67 /* We used to use string_sprintf() to add the newline if needed, but that
68 causes problems if the header line is exceedingly long (e.g. adding
69 something to a pathologically long line). So avoid it. */
71 if (s[slen-1] == '\n')
77 h->text = store_get(slen+2);
78 memcpy(h->text, s, slen);
79 h->text[slen++] = '\n';
83 h->next = addr->p.extra_headers;
84 h->type = htype_other;
91 /* Default is to retain existing removes */
93 *remove_headers = addr->p.remove_headers;
95 if (rblock->remove_headers != NULL)
97 uschar *s = expand_string(rblock->remove_headers);
100 if (!expand_string_forcedfail)
102 addr->message = string_sprintf("%s router failed to expand \"%s\": %s",
103 rblock->name, rblock->remove_headers, expand_string_message);
109 if (addr->p.remove_headers == NULL)
112 *remove_headers = string_sprintf("%s : %s", addr->p.remove_headers, s);
119 /* End of rf_get_munge_headers.c */