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.

Submission Mode

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
   hosts =                          ## Loop back interface
   control = submission                       ## apply additional checks and transformations

## Suppress submission
   senders =
   control = suppress_local_fixups

Processing Header Lines

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 
envelope_to_remove = false
delivery_date_remove = false

Note: the above disables these header lines

Exim will add the following header lines if they are missing when using submission mode

Rewriting Addresses

There are two circumstances when you may want to rewrite an address

rewrite rule

begin rewrite

*@*     $   
*   $   Ffrsbc
*    $   Ffrsbc

Note: I will explain the flags Ffrsbc later

rewrite rule

begin rewrite

*       "${lookup{$1} lsearch {/etc/email-addresses}{$value} fail}"   Ffrs

## The /etc/email-addresses would be
# user:

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

## Pattern

$0 = hearts-queen@wonderland.example        ## The complete address
$1 = hearts-                                ## The first *
$2 = wonderland                             ## The second *

# Address

## Pattern

$0 = hearts-queen@wonderland.example        ## The complete address
$1 = hearts- or clubs-                      ## The first set of brackets
$2 = deck or wonderland                     ## The second set of brackets

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 *

Note: never rewrite the address

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
Rewrite all envelope fields
Rewrite the envelope From field
Rewrite the envelope To field
Rewrite the Bcc: header line
Rewrite the Cc: header line
Rewrite the From: header line
Rewrite all header lines
Rewrite the Reply-To: header line
Rewrite the Sender: header line
Rewrite the To: header line
Flags that control the rewritting process
The rewritten address is permitted to be an unqualified local part
No further rewriting rules are considered for the current address, even if the address did not get rewritten
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.
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
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
* $ Ffrsbc

# exim -brw

sender:          ## changed because of the s flag
from:          ## changed because of the f flag
to:      ## did not change because we did not use the t flag
cc:          ## changed because of the c flag
bcc:          ## changed because of the b flag
reply-to:          ## changed because of the r flag
env-from:          ## changed because of the F flag
env-to:      ## did not change because we did not use the T flag