General-Purpose Mail Filter
Some of the mail filtering conditions may depend on the value of
helo domain name, i.e. the argument to the SMTP
HELO) command. If you ever need such conditions, take into
account the following caveats. Firstly, although
passes the helo domain in
$s macro, it does not do this
consistently. In fact, the
$s macro is available only to
helo handler, all other handlers won’t see it, no matter what
the value of the corresponding
statement. So, if you wish to access its value from any
handler, other than
helo, you will have to store it in a
variable in the
helo handler and then use this variable
value in the other handler. This approach is also recommended for
another MTAs. This brings us to the concept of
A variable is declared using the following syntax:
where variable is the variable name and type is ‘string’, if the variable is to hold a string value, and ‘number’, if it is supposed to have a numeric value.
A variable is assigned a value using the
set name expr
where expr is any valid MFL expression.
set statement can occur within handler or function
declarations as well as outside of them.
There are two kinds of
Mailfromd variables: global
variables, that are visible to all handlers and functions, and
automatic variables, that are available only within the handler
or function where they are declared. For our purpose we need a global
variable (See Variable classes, for detailed descriptions
of both kinds of variables).
The following example illustrates an approach that allows to use
HELO domain name in any handler:
# Declare the helohost variable string helohost prog helo do # Save the host name for further use set helohost $s done prog envfrom do # Reject hosts claiming to be localhost if helohost = "localhost" reject 570 "Please specify real host name" fi done
Notice, that for this approach to work, your MTA
must export the ‘s’ macro (e.g., in case of Sendmail, the
Milter.macros.helo statement in the sendmail.cf file must contain
‘s’. see Sendmail). This requirement can be removed by
using the handler argument of
mailfromd handler is given one or several arguments. The
exact number of arguments and their meaning are handler-specific and are
described in Handlers, and Figure 3.1.
The arguments are referenced by their ordinal number, using the notation
helo handler takes one argument, whose
value is the helo domain. Using this information, the
handler from the example above can be rewritten as follows:
prog helo do # Save the host name for further use set helohost $1 done
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.