Полезная информация

sendmail

sendmailSearch this book
Previous: 9.1 Introducing Rule Set 0Chapter 9
Rule Set 0
Next: 9.3 Testing Rule Set 0
 

9.2 The RHS Triple

The job of rule set 0 is to resolve each address into a triple: the delivery agent's symbolic name, the name of the host, and the name of the user in that order (see Figure 9.2).

Figure 9.2: Rule set 0 resolves a triple

Figure 9.2

Recall that rules are like if-then statements. If the rule in the LHS evaluates to true, then sendmail evaluates the RHS:

 if true ->         do this
 -v         -v
R$+         $#hub $@${REMOTE} $:$1          forward to hub
 -v
otherwise go to next rule

This RHS resolves all three parts of the triple. To accomplish this, the text of the RHS is transformed and then copied into the workspace:

$#hub           -> copied as is (delivery agent part)
$@${REMOTE}     -> defined macro is expanded (host part)
$:$1            -> positional macro is expanded (user part)

We examine these parts in order, showing how each is transformed and copied into the workspace. The transformation operators are shown in Table 9.1.

Table 9.1: Rule Set 0 RHS Transformation Operators
OperatorDescription
$#The mail delivery agent
$@The host
$:The user

9.2.1 The Delivery Agent ($#)

The first part of the triple is the name of the delivery agent. The RHS $# transformation operator tells sendmail that the text following (up to but not including the next operator, ignoring spaces) is the symbolic name of the delivery agent to use.

The symbolic name hub was defined in the client.cf file as

# Delivery agent definition to forward mail to hub
Mhub,   P=[IPC], S=0, R=0, F=mDFMuXa, T=DNS/RFC822/SMTP, A=IPC $h

When the RHS is copied into the workspace, any transformation operators such as $# are copied as is and become new tokens:

$#     <- the workspace thus far

When text, such as hub, is copied into the workspace, it is tokenized by using the separation characters: [1]

[1] As a result, the symbolic name of the mail delivery agent cannot contain any separation characters.

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

Since our symbolic name hub contains none of those characters, it is copied as a single token into the workspace:

$# hub      <- the workspace thus far

9.2.2 The Host ($@)

The second part of the triple is the hostname. The RHS $@ transformation operator tells sendmail that the text following (up to, but not including, the next operator and ignoring spaces) is the name of the host to which the mail will be sent. Whenever sendmail encounters ${name} in the RHS, it uses the value of the named macro. You previously defined ${REMOTE} to contain the name of the host to which all mail will be sent:

D{REMOTE}mailhost              # The name of the mail hub

The second part of the triple is now copied to the workspace. The name of the host is in ${REMOTE}. Combined, they look like this:

$@${REMOTE}

$@ is copied as is. ${REMOTE} is expanded (its value taken), and then that value is broken into tokens and copied into the workspace. If the value of the ${REMOTE} macro is mailhost, the workspace will look like this:

$# hub $@ mailhost   <- the workspace thus far

9.2.3 The User ($:)

The third part of the triple is the username. The RHS $: transformation operator tells sendmail that the following text (up to, but not including, the next operator and ignoring spaces) is the user to whom mail is being sent. Here, the username is determined by the $1, which is called a "positional operator":

$:$1

When sendmail sees a positional operator, a $ followed by a single digit in the RHS, it counts up the number of wildcard operators in the LHS. In this example the LHS has only one wildcard operator, $+, so $1 refers to that operator. If there were more than one wildcard operator in the LHS, for example,

$+.$+
-^  -^
$1 $2

then $1 would refer to the first $+ and $2 to the second $+.

A $digit tells sendmail to copy whatever tokens the corresponding LHS wildcard operator matched. If the original workspace had contained

boss @ acme    <- in the original workspace

then the lone $+ (match one or more) LHS wildcard operator would match the entire workspace (all of its tokens).

All of the original workspace's tokens are then copied. The workspace contains

$# hub $@ mailhost $: boss @ acme

After sendmail has completed writing the workspace, the workspace (the triple) is returned.


Previous: 9.1 Introducing Rule Set 0sendmailNext: 9.3 Testing Rule Set 0
9.1 Introducing Rule Set 0Book Index9.3 Testing Rule Set 0