macro
Store a value into a macro via a rule V8.10 and later
Not only is it possible to use defined macros in rule
sets, but as of V8.10 sendmail,
it is also possible to place new values into defined
macros from inside rule sets. This marvel is
accomplished using the macro
-type database map. It is an
internal type, always available regardless of how
sendmail was compiled.
The macro
type can
be used in three ways. For example:
Kstore_it_in macro R$* $: $(store_it_in {MyMacro} $@ $1 $) ← store new value into macro R$* $: $(store_it_in {MyMacro} $@ $) ← clear macro to empty string R$* $: $(store_it_in {MyMacro} $) ← undefine the macro
The first line declares store_it_in
to be the name of a
macro
database-map type that is used in the rules that
follow. Those three rules show three different ways
to affect the value stored in the macro {MyMacro}
. Note that the
macro name must not be prefixed with a $
. If it is, its value
will be used as the name, instead of its actual
name. We cover the use of $&
later.
The first rule shows that the value to be stored into
the macro is passed as the first $@
argument, the
$1
. If this
value is that of an undefined macro, the stored
result is an empty string. Otherwise, the value is
stored as is into the {MyMacro}
macro. If the value contains
macro-like expressions (such as $x
), their values are
used. If {MyMacro}
was previously undefined, it
becomes defined.
The second rule shows what happens when the value to be stored is missing (or undefined). A missing value ...
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.