$:
Rewrite once and continue RHS prefix
Ordinarily, the RHS of a rule continues to rewrite the workspace for as long as the workspace continues to match the LHS. This looping behavior can be useful when intended, but can be a disaster if unintended. But consider what could happen, under older versions of sendmail, if you wrote a rule such as the following, which seeks to match a domain address with at least one first dot:
R $+ . $* $1.OK
An address such as wash.dc.gov
will match the LHS and will be rewritten by the RHS
into wash.OK. But because rules
continue to match until they fail, the new address,
wash.OK, will be matched by
the LHS again, and again will be rewritten to be
wash.OK. As you can see, this
rule sets up an infinite loop.[254] To prevent such infinite looping on this
rule, you should prefix the RHS with the $
: operator:
R $+ . $* $:
$1.OK
The $
: prefix tells
sendmail to rewrite the
workspace only once. With the $
: prefix added to our
example, the domain address
wash.dc.gov would be
rewritten to wash.OK exactly
once. Progress would then proceed to the next
following rule (if there is one).
The $
: prefix is
described in full in Rewrite Once Prefix: $:
on page 662.
[254] * Fortunately, modern sendmail detects and breaks such infinite loops for you now.
Get sendmail, 4th 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.