Update version number and copyright year.
[exim.git] / src / src / routers / rf_change_domain.c
CommitLineData
184e8823 1/* $Cambridge: exim/src/src/routers/rf_change_domain.c,v 1.4 2007/01/08 10:50:20 ph10 Exp $ */
0756eb3c
PH
2
3/*************************************************
4* Exim - an Internet mail transport agent *
5*************************************************/
6
184e8823 7/* Copyright (c) University of Cambridge 1995 - 2007 */
0756eb3c
PH
8/* See the file NOTICE for conditions of use and distribution. */
9
10
11#include "../exim.h"
12#include "rf_functions.h"
13
14
15
16/*************************************************
17* Change domain in an address *
18*************************************************/
19
20/* When a router wants to change the address that is being routed, it is like a
21redirection. We insert a new parent of the current address to hold the original
22information, and change the data in the original address, which is now the
23child. The child address is put onto the addr_new chain. Pick up the local part
24from the "address" field so as to get it in external form - caseful, and with
25any quoting retained.
26
27Arguments:
28 addr the address block
29 domain the new domain
30 rewrite TRUE if headers lines are to be rewritten
31 addr_new the new address chain
32
33Returns: nothing
34*/
35
36void
37rf_change_domain(address_item *addr, uschar *domain, BOOL rewrite,
38 address_item **addr_new)
39{
40address_item *parent = store_get(sizeof(address_item));
41uschar *at = Ustrrchr(addr->address, '@');
42uschar *address = string_sprintf("%.*s@%s", at - addr->address, addr->address,
43 domain);
44
45DEBUG(D_route) debug_printf("domain changed to %s\n", domain);
46
47/* The current address item is made into the parent, and a new address is set
48up in the old space. */
49
50*parent = *addr;
51
52/* First copy in initializing values, to wipe out stuff such as the named
53domain cache. Then copy over the propagating fields from the parent. Then set
54up the new fields. */
55
56*addr = address_defaults;
57addr->p = parent->p;
58
59addr->address = address;
60addr->unique = string_copy(address);
61addr->parent = parent;
62
63addr->next = *addr_new;
64*addr_new = addr;
65
66/* Rewrite header lines if requested */
67
68if (rewrite)
69 {
70 header_line *h;
71 DEBUG(D_route|D_rewrite) debug_printf("rewriting header lines\n");
72 for (h = header_list; h != NULL; h = h->next)
73 {
74 header_line *newh =
75 rewrite_header(h, parent->domain, domain,
76 global_rewrite_rules, rewrite_existflags, TRUE);
77 if (newh != NULL)
78 {
79 h = newh;
80 header_rewritten = TRUE;
81 }
82 }
83 }
84}
85
86/* End of rf_change_domain.c */