sendmail

sendmailSearch this book
Previous: 8.2 Why Rules?Chapter 8
Addresses and Rules
Next: 8.4 Rules
 

8.3 Rule Sets

Sequences of rules are grouped together into rule sets. Each set is similar to a subroutine. A rule set is declared with the S command, which must begin a line in sendmail.cf. For example:

S0

This begins the declaration of the rules that form rule set number 0. Rule sets are numbered starting from 0. [2] Sets 0 through 5 [3] are internally defined by sendmail to have very specific purposes, as shown in Table 8.1. We'll expand on them throughout the rest of the tutorial. Rule-set definitions may appear in any order in the configuration file. For example, rule set S5 may be defined first, followed by S2 and then S7. The rule sets are gathered when the sendmail.cf file is read and are then sorted internally by sendmail.

[2] Beginning with V8.7, rule sets may have symbolic names too. We show this in Chapter 11, Rule Sets 1 and S=.

[3] Other rule sets may be used by future versions of sendmail, so avoid using rule sets 6 through 9.

Table 8.1: The Purposes of Rule Sets
Rule SetPurpose
0Resolve a mail delivery agent
1Process sender address
2Process recipient address
3Preprocess all addresses
4Postprocess all addresses
5Rewrite unaliased local users

The client.cf file contains no rule-set definitions yet. To observe the effect of nonexistent rules, rerun sendmail on that file:

% ./sendmail -Cclient.cf -bt
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter <ruleset> <address>
>

The -bt command-line switch causes sendmail to run in address-testing mode. In this mode, sendmail waits for you to type a rule set and an address. [4] It then shows you how the rule set rewrites the address. At the > prompt, you can now enter an address by specifying a rule-set number, then a space, and then a mail address:

[4] V8.7's rule-testing mode can do much more (see Section 38.1, "Overview").

> 0 gw@wash.dc.gov
rewrite: ruleset  0   input: gw @ wash . dc . gov
rewrite: ruleset  0 returns: gw @ wash . dc . gov
>

The rule set specified is 0, but you can specify any number.

The rewrite: word that begins each line of address-testing mode output is there simply to distinguish rewriting lines when they are mixed with other kinds of debugging output. The input means that sendmail placed the address into the workspace (more about this soon). The returns shows the result after the rule set has rewritten that address on the basis of its rules.

The address that is fed to sendmail, gw@wash.dc.gov, is first split into parts (tokens) based on two sets of separating characters. Both are defined internally. One can be changed in your configuration file; [5] the other cannot:

[5] Prior to V8.7, the o macro was used in the configuration file to define different or more characters. Beginning with V8.7, the OperatorChars option is used instead.

.:@[]          <- you can change these
()<>,;\"\r\n   <- you cannot change these

The two sets are combined into one, and the result is used to separate the various parts of email addresses. The address gw@wash.dc.gov is divided into seven tokens because the @ and dot are both in the list of separation characters.

rewrite: ruleset  0   input: gw @ wash . dc . gov
rewrite: ruleset  0 returns: gw @ wash . dc . gov

The input: line shows seven tokens passed to rule set 0. The returns: line shows, since there is no rule set 0, that the undefined  - pty) rule set returns those tokens unchanged.

If a rule set is undefined, the result is the same as if it were defined but had no rules associated with it. It is like a C language subroutine that contains nothing but a return statement. It does nothing and produces no errors.


Previous: 8.2 Why Rules?sendmailNext: 8.4 Rules
8.2 Why Rules?Book Index8.4 Rules