When a message begins life and delivery has not yet been attempted,
the message is considered to have had zero delivery attempts. If the
first delivery attempt fails, the message is deferred to the queue
and marked as having had one delivery attempt. Thereafter, each time
the message is fetched from the queue and delivery fails, the number
of attempts is incremented. Each time the message is read from the
queue, the number of delivery attempts is stored in the
${ntries} macro.
One use for this ${ntries} macro might be to
bounce high-priority mail that fails on the first try. If it cannot
be sent right away, perhaps such mail should be faxed, or followed up
with a telephone call. Consider the following mc
file lines that suggest one way to accomplish this:
LOCAL_CONFIG
C{persistentMacros} {X-Notice}
HX-Notice: $>CheckNotice
Kstore macro
LOCAL_RULESETS
SCheckNotice
R $* $: $(store {X-Notice} $@ YES $)
Scheck_compat
R $* $: $&{X-Notice}
R $* $: $(store {X-Notice} $) $1
R YES $: $(math l $@ $&{ntries} $@ 1 $)
R FALSE $#error $@ 5.7.1 $: "550 X-Notice mail exceeded allowed tries"
Here, we set up our own ${X-Notice} macro as a
private flag so that we can detect the presence of the
X-Notice: header, even when the message is read
from the queue. Under LOCAL_CONFIG, we first add the
${X-Notice} macro to the class
$={persistentMacros} ($={persistentMacros}) which ensures that
${X-Notice} will retain its value despite the
message being queued. We then use the H
configuration command to define the X-Notice:
header and to specify that the X-Notice:
header's value must be processed by the
CheckNotice rule set. Finally, we declare a
macro type database map (macro) which we will reference with the name
store.
In the LOCAL_RULESETS section we set up two rule sets. The first rule
set is the CheckNotice rule set we referenced with
the H configuration command. That rule set
contains a single rule which stores a literal YES into the
${X-Notice} macro.
The second rule set is the check_compat rule set
(Section 7.1.4), which is called just prior to
delivery. It contains four rules. The first rule fetches the current
value (the $&) of the
${X-Notice} macro and places that value into the
workspace. The second rule clears the ${X-Notice}
macro to ready it for any future message. The third rule looks for a
literal YES in the workspace, and if found, compares the value in the
${ntries} macro to a one. If
${ntries} is not less than one, a literal FALSE is
placed into the workspace. The last rule looks for a literal FALSE in
the workspace, and if found, rejects (bounces) the message with an
appropriate notice.
${ntries} is transient. If it is defined in the
configuration file or in the command line, that definition can be
ignored by sendmail. Note that a
$& prefix is necessary when you reference this
macro in rules (that is, use $&{ntries}, not
${ntries}).