1 /* $Cambridge: exim/src/src/routers/rf_change_domain.c,v 1.5 2009/11/16 19:50:38 nm4 Exp $ */
3 /*************************************************
4 * Exim - an Internet mail transport agent *
5 *************************************************/
7 /* Copyright (c) University of Cambridge 1995 - 2009 */
8 /* See the file NOTICE for conditions of use and distribution. */
12 #include "rf_functions.h"
16 /*************************************************
17 * Change domain in an address *
18 *************************************************/
20 /* When a router wants to change the address that is being routed, it is like a
21 redirection. We insert a new parent of the current address to hold the original
22 information, and change the data in the original address, which is now the
23 child. The child address is put onto the addr_new chain. Pick up the local part
24 from the "address" field so as to get it in external form - caseful, and with
28 addr the address block
30 rewrite TRUE if headers lines are to be rewritten
31 addr_new the new address chain
37 rf_change_domain(address_item *addr, uschar *domain, BOOL rewrite,
38 address_item **addr_new)
40 address_item *parent = store_get(sizeof(address_item));
41 uschar *at = Ustrrchr(addr->address, '@');
42 uschar *address = string_sprintf("%.*s@%s", at - addr->address, addr->address,
45 DEBUG(D_route) debug_printf("domain changed to %s\n", domain);
47 /* The current address item is made into the parent, and a new address is set
48 up in the old space. */
52 /* First copy in initializing values, to wipe out stuff such as the named
53 domain cache. Then copy over the propagating fields from the parent. Then set
56 *addr = address_defaults;
59 addr->address = address;
60 addr->unique = string_copy(address);
61 addr->parent = parent;
63 addr->next = *addr_new;
66 /* Rewrite header lines if requested */
71 DEBUG(D_route|D_rewrite) debug_printf("rewriting header lines\n");
72 for (h = header_list; h != NULL; h = h->next)
75 rewrite_header(h, parent->domain, domain,
76 global_rewrite_rules, rewrite_existflags, TRUE);
80 header_rewritten = TRUE;
86 /* End of rf_change_domain.c */