Access Classes in Rules

Class macros are useful only in the LHS of rules. The sendmail program offers two ways to use them:

$=X

The $= prefix causes sendmail to seek a match between the workspace and one of the words in a class list.[4]

$~X

The $~ prefix causes sendmail to accept only a single token in the workspace that does not match any of the words in a class list.

Matching Any in a Class: $=

The list of words that form a class are searched by prefixing the class name with the characters $=:

R$=X    $@<$1>

In this rule, the expression $=X causes sendmail to search a class for the word that is in the current workspace. If sendmail finds that the word has been defined, and if it finds that the word is associated with the class $=X, only then is a match made.

The matching word is made available for use in the RHS rewriting. Because the value of $=X is not known ahead of time, the matched word can be referenced in the RHS with the $digit positional operator.

Consider the following example. Two classes have been declared elsewhere in the configuration file. The first, $=w, contains all the possible names for the local host:

Cw localhost mailhost server1 server2

The second, $=D, contains the domain names of the two different networks on which this host sits:

CD internal.domain external.domain

If the object of a rule is to match any variation on the local hostname at either of the domains and to rewrite the result as the official hostname at the appropriate domain, the following rule can be ...

Get Sendmail, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.