Previous Table of Contents Next

The Left Side

The left side of rewriting rules contains a pattern. Normal words are simply matched directly. Dollar signs introduce metasymbols, which match units other than simple words, such as macros or classes. The metasymbols are shown in Table 4-8.

Table 4-8 Left-Side Metasymbols for sendmail

Symbol Description
$* Match zero or more tokens
$+ Match one or more tokens
$- Match exactly one token
$=x Match any string in class x
$~x Match any token not in class x
$%x Match any token in NIS map or NIS+ table $x
$!x Match any token not in NIS map or NIS+ table $x
$x Match macro x

If any of the patterns match, the match is assigned to the symbol $c n for replacement on the right side, in which n is the index in the LHS. For example, if the LHS


is applied to the input


the rule will match, and the values passed to the RHS will be

$2 eric

The $%x uses the macro x to specify the name of an NIS map or NIS+ table. The special form $%y matches any host name in the Hosts database for NIS+, in hosts.byname map for NIS, or in /etc/hosts if NIS or NIS+ is not running.

Right-Side Address Rewriting Rules

When the left side of a rewriting rule matches, the input is replaced by the right side. Tokens are copied directly from the right side unless they begin with a dollar sign. Metasymbols for more complicated substitutions are shown in Table 4-9.

Table 4-9 Right-Side Metasymbols for sendmail

Symbol Description
$x Expand macro x
$n Substitute indefinite token n from LHS
$>n Call ruleset n
$#mailer Resolve to mailer
$@host Specify host (+prefix? ruleset return)
$:user Specify user (+ prefix rule limit)
$[host$] Map to primary host name
${xname$} Map name through NIS map or NIS+ table $x. If the map name begins with REVERSE, it will look things up in reverse to invert aliases

The $cn (n being a digit) syntax substitutes the corresponding value from a $+, $-, $*, $=, or $@ match on the LHS. It may be used anywhere.

The $>cn syntax substitutes the remainder of the line as usual and then passes it to ruleset n. The final value of ruleset n then becomes the substitution for this rule (such as a procedure or function call).

Use the $# syntax only in ruleset 0. Evaluation of the ruleset stops immediately and signals to sendmail that the name has completely resolved. The complete syntax is


This syntax specifies the {mailer, host, user} triplet necessary to direct the mailer. More processing may then take place, depending on the mailer. For example, local names are aliased.

A right side may also be preceded by a $@ or a $: to control evaluation. A $@ prefix returns the remainder of the right side as the value. A $: prefix terminates the rule immediately, but the ruleset continues; thus, it can be used to limit a rule to one application. Neither prefix affects the result of the right side expansion.

The $@ and $: prefixes can precede a $> specification. For example,

R$+            $:$>7$1

matches anything, passes that to ruleset 7, and continues; the $: is necessary to avoid an infinite loop. The $[host]$ syntax replaces the host name with the "official" or primary host name--the one listed first in the hosts.byname NIS map, NIS+ table, DNS, or local /etc/hosts file. It is used to eliminate nicknames for hosts. The ${xname$} syntax replaces the string by the result of the nis_map_name indicated in macro $x.

Semantics of Rewriting Rulesets

Five rewriting sets have specific semantics, as shown in Figure 4-1.

Figure 4-1  Semantics of rewriting rulesets.

Ruleset 3 is applied by sendmail before it does anything with any name. That ruleset should turn the name into canonical form, with the basic syntax


If no @ sign is specified, the host-domain-spec may be appended from the sender name (if the C flag is set in the mailer definition corresponding to the sending mailer).

Ruleset 0 is applied after ruleset 3 to names that actually specify recipients. It must resolve to a {mailer, host, user} triplet. The mailer must be defined in the mailer definitions from the configuration file. The host is defined into the $h macro for use in the argument expansion of the specified mailer; the user is defined into $u.

Rulesets 1 and 2 are applied to all From:, To:, and CC: recipient names, respectively. The rulesets specified in the mailer definition line (and R=) are then applied. Note that this process is completed many times for one message, depending on how many mailers the message is routed to by ruleset 0.

Ruleset 4 is applied last to all names in the message. It is typically used to translate addresses from internal to external form.

The error Mailer

You can use this mailer with the special name error in ruleset 0 to generate a user error message. The user field is a message to be printed. For example, the entry

$#error$:Host unknown in this domain

on the RHS of a rule generates the specified error if the LHS matches.

Previous Table of Contents Next