19.7 Rule Sets 1 and 2

Rule sets 1 and 2 handle sender and recipient addresses, respectively. Rule set 1 is called before the S= delivery agent's rule set is called. Rule set 2 is called before the R= delivery agent's rule set is called. Neither is used (by default) in modern configuration files.

19.7.1 Rule Set 1

Rule set 1 is intended to process all sender addresses. It is rarely used but can find application at sites where all outgoing mail should appear to come from a central mail server. Rules to handle this host-hiding might look like this:

R $* <@ $=w> $*      $@ $1 <@ $M> $3        user@localhost => user@ourdomain

In the LHS the $=w matches any name from a list of names by which the local host is known. In the RHS the $M contains the name of the mail server. If the mail is not from the local host, it is unchanged.

Other uses for rule set 1 might include the following:

  • Normalizing senders, for example, making mail from the users operator and dumper appear to come from root

  • Hiding user login names by mapping them (through an external database) to the form firstname.lastname

Needless to say, great care should be exercised in adding schemes such as these to your configuration file.

See LOCAL_RULE_1 (Section for a way to add rules to rule set 1.

19.7.2 Rule Set 2

All recipient addresses are rewritten by rule set 2 and the R= of delivery agents. But in almost all configuration files, rule set 2 is unused because no processing is needed:

# Recipient processing: none needed

But note that rule set 2 can be used to debug rules.[6] Consider the following rule in rule set 2 (that requires V8.9 and above sendmail to work):

[6] This is a truly bogus example. We are really stretching to find a use for rule set 2. There is no reason to do this debugging in rule set 2 because rule set 99 would work just as well. According to Eric, "I can think of no good reason to use S2 today."

R $# $+ $: $+     $:$2    Strip delivery agent and host when debugging

Recall that the parse rule set 0 returns a triple. When testing an address, rule set 2 can be called following the parse rule set 0 to simulate the rewriting of the user portion of the parse rule set 0. Here the LHS matches only a triple, so normal recipient addresses are unaffected. The user part that is returned by the RHS can then be used to test individual R= rules of delivery agents. (Another technique is to use the /try command in -bt rule-testing mode; see Section 8.5.6.)

See LOCAL_RULE_2 (Section for a way to add rules to rule set 2.

    Part I: Build and Install
    Part II: Administration
    Part III: The Configuration File
    Chapter 21. The D (Define a Macro) Configuration Command
    Chapter 24. The O (Options) Configuration Command