$|

Match or return a literal $| LHS and RHS operator

It is sometimes necessary to communicate information between one rule and another. The preferred way of doing this is to use the special $| operator, which can be used in both the LHS and RHS of rules. To illustrate, consider the following two rules:

R $-               $: $1 $| $(badusers $1 $)
R $- $| BAD        $# discard $: discard

Here, the first rule’s LHS checks to see whether there is a single token in the workspace (as would be the case if it contained a username). If that is the case, the RHS returns the original workspace (with the $1) and a separator (the $|). Lastly, the RHS looks up the username in a hypothetical badusers database, and if the user is found, the result of the lookup (either a literal GOOD or BAD, for example) is appended to the workspace.

The second rule looks for a workspace that now contains the original username (the $-) followed by a literal separator (the $|) and the literal word BAD. If BAD is found, that user’s email is discarded with the discard delivery agent.

One actual example of using $| can be found in Local_check_relay and check_relay on page 252. That section also describes a trick for using $| in rule-testing mode. Note that the $| operator can be used in either the LHS or RHS of a rule.

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.