8.7 Wildcard OperatorsRules would be pretty useless if they always had to match the workspace exactly. Fortunately, that is not the case. In addition to literal text, you can also use wildcard operators that allow the LHS of rules to match arbitrary text in the workspace. To illustrate, consider this rule:
R$+ rhs is here lhs
This LHS begins with the first character following the
$+
This is a wildcard operator.
The truth of this if statement is determined by a process called
pattern
matching
. The LHS
gw@wash.dc.gov tokenized into gw @ wash . dc . gov in the workspace
When matching the workspace to an LHS pattern,
sendmail
scans the
workspace from left to right. Each token in the workspace is compared
to the wildcard operator (the
The
workspace pattern gw $+ match one token (``one'') @ and optionally more (``or more'') wash . dc . gov
As you can see, if there are any tokens in the address at all
(the workspace is not empty), the LHS rule 8.7.1 Other Text in the LHS
A rule of
gw@wash.dc.gov $+ should match and does @wash.dc.gov $+ matches an incomplete address
To make matching in the LHS more effective,
sendmail
allows
other text to appear in the pattern.
To make sure that the address in the workspace
contains a user part, the
$+@$+
Just like the address in the workspace, this pattern is tokenized
before it is compared for a match. Wildcard operators (like
.:
The pattern of
$+ @ $+
Text in the pattern must match text in the workspace
exactly
(token for token) if there is to be a match. A good address in the
workspace (one containing a user part and a host part)
will match our new LHS (
workspace pattern gw $+ match one or more @ @ match exactly wash $+ match one . or more dc . gov
Here, the flow of matching begins with the first A bad address in the workspace, on the other hand, will not match the pattern. Consider an address, for example, that lacks a user part:
@wash.dc.gov in the workspace workspace pattern @ $+ match one wash or more . dc . gov @ match exactly (fails!) $+
Here, the first 8.7.2 Minimal Matching
One small bit of confusion may yet remain. When a wildcard operator such as
R$+@$+
In this LHS the first
a@b@c
In the above, 8.7.3 More Play with LHS MatchingTake a moment to replace the previous demo rules with the following three new demo rules in the client.cf file:
S0 R@ one R@$+ two R$+@$+ three Again, these three rules are for demonstration purposes only (you'll see how to declare a real one soon enough). We've given each temporary RHS a number to see whether it is selected. Now run sendmail in rule-testing mode:
% Now print the rules to remind yourself what they are:
>
We'll test those rules with an assortment of test addresses.
The first address to try is a lone
>
The
R@ one
The LHS here (the pattern to match) contains the lone Next enter an address that just contains a host and domain part but not a user part:
> The first thing to notice is what was not printed! The workspace does not match the pattern of the first rule. But instead of returning an error, the workspace is carried down as is to the next rule - where it does match:
@your.domain does not match, so ... R@ one try the next rule R@$+ two Now enter an address that fails to match the first two rules but successfully matches the third:
> The flow for this address is
your@your.domain does not match, so ... R@ one try the next rule, which also does not match, so ... R@$+ two try the next rule, which does match. R$+@$+ three Try other addresses such as your login name or UUCP addresses such as you@host.uucp and host!you . Can you predict what will happen with weird addresses like @@ or a@b@c ? When you are done experimenting, exit rule-testing mode and delete the four temporary lines that you added for this demonstration. |
|