Some rule sets are passed only a recipient or a sender address,
supplied from either a header or the envelope. Examples are rule sets
1 and 2, and the rule sets indicated by the R= and
S= equates. Other rule sets, such as the
canonify rule set 3, can be called with any
combination.
When designing rules, it might be necessary to know whether those
rules are dealing with a sender or a recipient, and whether the
address is from the envelope or a header. Beginning with V8.10,
sendmail offers the
${addr_type} macro as a means to solve that very
problem. As shown in Table 21-8 the
${addr_type} macro can hold any of several pairs
of characters, depending on whether the address is from the envelope
or a header, and whether the address is that of a sender or a
recipient.
Table 21-8. Possible values for the {addr_type} macro
e s
|
An envelope sender address
|
e r
|
An envelope recipient address
|
h
|
A header recipient address or header sender address
|
To illustrate one use for this ${addr_type}
macro's value, consider a rule set that screens
addresses and rejects any that are found in a database of spam sender
hosts:
LOCAL_CONFIG
Kspammers hash /etc/mail/spammers
LOCAL_RULESETS
SDomainLookup
R $+ <@ $=w .> $@ OK local users are always OK
R $+ <@ $+> $: $1 <@ $2 > <$&{addr_type}>
R $+ <@ $+> <e r> $@ OK we only screen envelope senders.
R $+ <@ $+> <h> $@ OK we don't screen header addresses.
R $+ <@ $+> <$*> $(spammers $2 $: OK $)
R OK $@ OK
R $* $@ ERROR
Under the LOCAL_CONFIG section of this mc
configuration file, we define a database,
/etc/mail/spammers, that contains a list of
sites we want to reject for spamming.
Under the LOCAL_RULESETS section, we declare the
DomainLookup rule set. We might call this rule set
from other policy rule sets, such as
Local_check_mail (Section 7.1.2).
The first rule accepts anything that looks like a local address. The
second rule appends the value of the ${addr_type}
macro to the workspace. The third and fourth rules accept all
envelope recipient addresses and all header addresses, but not
envelope sender addresses.
The fifth rule looks up the envelope sender's host
in the spammers database. If that hostname is
found, its value is returned (a spam site was found). If it is not
found in the database, OK is returned (the site is
not a spam site). The last two rules simply return
OK or ERROR to indicate the
nature of the hostname. Depending on how you employ this rule set,
you might wish to return more complex information, such as the
original workspace augmented with good or bad.
${addr_type} is transient. If it is defined in the
configuration file or command line, that definition can be ignored by
sendmail. Note that it is currently not possible
to differentiate between a header sender and a header recipient with
this macro.
Also note that a $& prefix is necessary when
you reference this macro in rules (that is, use
$&{addr_type}, not
${addr_type}).