31.5 Macro Expansion: $ and $&
The value of a macro can be used by putting
a
D
Here, the macro named
If you later prefix a macro name with a
$X
Here, the expression For multicharacter names, the process is the same, but the name is surrounded with curly braces:
D
31.5.1 Macro Expansion Is Recursive
When
DAxxx DByyy DC$A.$B DD$C.zzz
Here, the
$D becomes $C.zzz $C.zzz becomes $A.$B.zzz $A.$B.zzz becomes xxx.$B.zzz xxx.$B.zzz becomes xxx.yyy.zzz Notice that when sendmail recursively expands a macro, it does so one macro at a time, always expanding the leftmost macro.
In rules, when
sendmail
expands a macro,
it also tokenizes it. For example,
placing the above
R$+@$D $1 causes the LHS to contain seven tokens, rather than three:
R$+@xxx.yyy.zzz $1
31.5.2 When Is a Macro Expanded?A macro can either be expanded immediately or at runtime, depending on where the expansion takes place in the configuration file.
Macros are expanded in rule sets as the configuration
file is read and parsed by
sendmail
,
and (beginning with V8.7) so are macros in
rule-set names (see
Section 29.1.4, "Macros in Rule-Set Names"
)
and in maps declared with the To illustrate, macros used in header commands are not be expanded until the headers of a mail message are processed:
H?x?Full-Name: $x
Here,
On the other hand, macros in rules are always expanded
when the configuration
file is read
. Therefore macros like
R$x ($x)
Rules like this won't work because
R ()
Note that the
R${HOST} <$1>
The
Rmyhost <$1> error
Here, the
replacement $1 out of bounds
31.5.3 Use Value as Is with $&
For those situations in which a macro should not be recursively expanded,
but rather should be used in rules as is, V8
sendmail
offers the
R... $w.$&m
When
sendmail
encounters this RHS in the configuration
file, it recursively expands
This could be useful, because it appears to offer a way to delay
expansion of macros in rules until after the configuration file
is read. Unfortunately such is not always the case, because the expanded
text returned by the
lady . $m
Here, the
lady . our.domain When tokens are compared during rule-set processing, they are compared token by token. Consequently, the single token above will not match the individual tokens of a real address, as shown on the left:
our does not match our.domain . does not match our.domain domain does not match our.domain
The
To illustrate one application of To break such a loop, a rule must be devised that recognizes that a received message is from the hub:
R$+ $: $&r @ $&s <$1> Get protocol and host Rsmtp @ $H <$+> $#local $: $1 Local delivery breaks a loop R$* <$+> $#smtp $@ $H $: $2 Punt to hub
These rules appear in rule set 0. By the time they are reached,
other rules have forwarded any nonlocal mail to the hub. What is left
in the workspace is a lone username. The first rule above matches
the workspace and rewrites it to be the sending protocol (
user becomes smtp@hub<user>
The second rule checks to make sure the message was received with
the SMTP protocol from the hub. If it was, then the |
|