General-Purpose Mail Filter
This section discusses some potential culprits in the MFL.
It is important to execute special caution when writing format
sprintf (see String formatting) and
(see strftime) functions. They use ‘%’ as a character
introducing conversion specifiers, while the same character is used to
expand a MFL variable within a string. To prevent this
misinterpretation, always enclose format specification in single
quotes (see singe-vs-double). To illustrate this, let’s consider
the following example:
echo sprintf ("Mail from %s", $f)
If a variable
s is not declared, this line will produce the
‘Variable s is not defined’ error message, which will allow you
to identify and fix the bug. The situation is considerably worse if
s is declared. In that case you will see no warning message,
as the statement is perfectly valid, but at the run-time the variable
s will be interpreted within the format string, and its value
%s. To prevent this from happening, single quotes
must be used:
echo sprintf ('Mail from %s', $f)
This does not limit the functionality, since there is no need to fall back to variable interpretation in format strings.
Yet another dangerous feature of the language is the way to refer to variable and constant names within literal strings. To expand a variable or a constant the same notation is used (See Variables, and see Constants). Now, lets consider the following code:
const x 2 string x "X" prog envfrom do echo "X is %x" done
echo refers to the variable or to the
constant? The correct answer is ‘to the variable’. When executed, this
code will print ‘X is X’.
As of version 8.7,
mailfromd will always print a
diagnostic message whenever it stumbles upon a variable having the
same name as a previously defined constant or vice versa. The
resolution of such name clashes is described in detail in
See variable--constant shadowing.
Future versions of the program may provide a non-ambiguous way of referring to variables and constants from literal strings.
This document was generated on January 3, 2019 using makeinfo.Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.