Address and Header Processing
Exim can make changes to the sender and recipient addresses messages, as well as the message header lines, this all happens before it is written to Exim spool file.
In submission mode Exim applies a number of checks and transformations that are not used for messages that arrive from other MTAs, they normally come from local processes (not over TCP/IP).
submission mode | ## Apply submission to loopback interface ## Suppress submission |
You can add header lines explicitly by using the option add_header modifier, Exim may well add or remove header itself especially in submission mode.
Exim uses header lines that start with resent- these are for information only and MUST not be used.
Exim will automatically add a From: header line if one has not been supplied, it is normally taken from the envelope sender or if that is empty then from $authenticated_id if authentication is used. From locally submitted messages, the calling users login name and full name are used, this is obtained from getting the gecos name from password file.
Sender header lines are normally left untouched, unless in submission mode when they are removed, if the connection is authenticated then $authenticated_id is used.
Exim can also use the following header lines if required Return-path:, Envelope-to: and Delivery-date: by using the following:
additional header lines | return_path_remove = false Note: the above disables these header lines |
Exim will add the following header lines if they are missing when using submission mode
There are two circumstances when you may want to rewrite an address
rewrite rule | begin rewrite Note: I will explain the flags Ffrsbc later |
rewrite rule | begin rewrite ## The /etc/email-addresses would be |
Exim has its configuration location for rewriting rules which starts with begin rewrite, each line then operates on that specific address in turn (the address may go through none, one or many rules), it then applies the rule when one of the lines are matched. Routers can ignore the rewriting rules using the option rewrite it can be false or true.
The format of the rule is: <pattern> <replacement> <flags>
The pattern can use wildcards and the matching result can be located in the numerical variables $1, $2, etc. $0 will contain the complete address
pattern example | # Address $0 = hearts-queen@wonderland.example ## The complete address # Address ## Pattern |
You can specify that an address never to be rewritten, which means once the address is picked up by this rule it is never passed on to the next rule
Do not rewrite particular address | paul.valle@datadisk.co.uk * Note: never rewrite the address paul.valle@datadisk.co.uk |
There are a number of flags that can appear on the rule
Flags that specify header lines and envelope fields to which the rule applies |
|
E |
Rewrite all envelope fields |
F |
Rewrite the envelope From field |
T |
Rewrite the envelope To field |
b |
Rewrite the Bcc: header line |
c |
Rewrite the Cc: header line |
f |
Rewrite the From: header line |
h |
Rewrite all header lines |
r |
Rewrite the Reply-To: header line |
s |
Rewrite the Sender: header line |
t |
Rewrite the To: header line |
Flags that control the rewritting process |
|
Q |
The rewritten address is permitted to be an unqualified local part |
q |
No further rewriting rules are considered for the current address, even if the address did not get rewritten |
R |
causes a successful rewriting rule to be reapplied to the new address (up to 10 times), it can be used with q flag to stop rewriting once it fails to match. Normally used in gateway environments where different styles of addressing are used. This flag is also unknown as the repeat flag. |
w |
when a header line is rewritten it is normally only applied to the working part of the address, with any comments and RFC2822 "phase" left unchanged, however sometimes there is a need to replace the whole RFC2822 address item, and this can be done by adding the w flag to the rule. |
Flag that specifies rewriting at SMTP time |
|
S |
specifies a rule that applies to incoming envelope addresses at SMTP time (as soon as MAIL and RCPT), you can use this flag to handle addresses that are not compliant with RFC2821. |
You can test the rewrite rules by using Exim's -brw option
Testing rewrite rules | # Rewrite rule sender: paul.valle@datadisk.co.uk ## changed because of the s flag |