General-Purpose Mail Filter
It is important to check your filter script before actually starting to use it. There are several ways to do so.
To test the syntax of your filter script, use the --lint
option. It will cause
mailfromd to exit
immediately after attempting to compile the script file. If the
compilation succeeds, the program will exit with code 0. Otherwise,
it will exit with error code 78 (‘configuration error’). In the
mailfromd will also print a diagnostic message,
describing the error along with the exact location where the error was
diagnosed, for example:
mailfromd: /etc/mailfromd.mf:39: syntax error, unexpected reject
The error location is indicated by the name of the file and the
number of the line when the error occurred. By using the
--location-column option you instruct
also print the column number. E.g. with this option the above
error message may look like:
mailfromd: /etc/mailfromd.mf:39.12 syntax error, unexpected reject
Here, ‘39’ is the line and ‘12’ is the column number.
For complex scripts you may wish to obtain a listing of variables used in the script. This can be achieved using --xref command line option:
The output it produces consists of four columns:
Measured in words.
A comma-separated list of locations where the variable was referenced. Each location is represented as file:line. If several locations pertain to the same file, the file name is listed only once.
Here is an example of the cross-reference output:
$ mailfromd --xref Cross-references: ----------------- cache_used number 5 /etc/mailfromd.mf:48 clamav_virus_name string 9 /etc/mailfromd.mf:240,240 db string 15 /etc/mailfromd.mf:135,194,215 dns_record_ttl number 16 /etc/mailfromd.mf:136,172,173 ehlo_domain string 11 gltime number 13 /etc/mailfromd.mf:37,219,220,222,223 greylist_seconds_left number 1 /etc/mailfromd.mf:220,226,227 last_poll_host string 2
If the script passes syntax check, the next step is often to test if
it works as you expect it to. This is done with --test
(-t) command line option. This option runs the
envfrom handler (or another one, see below) and prints the
result of its execution.
When running your script in test mode, you will need to supply the
Sendmail macros it needs. You do this by placing
the necessary assignments in the command line. For example, this is
how to supply initial values for
$ mailfromd --test email@example.com client_addr=127.0.0.1
You may also need to alter initial values of some global variables
your script uses. To do so, use -v (--variable)
command line option. This option takes a single argument consisting
of the variable name and its initial value, separated by an equals
sign. For example, here is how to change the value of
ehlo_domain global variable:
$ mailfromd -v ehlo_domain=mydomain.org
The --test option is often useful in conjunction with options --debug, --trace and --transcript (see Logging and Debugging. The following example shows what the author got while debugging the filter script described in Filter Script Example:
$ mailfromd --test --debug=50 firstname.lastname@example.org client_addr=127.0.0.1 MX 20 mx20.gnu.org MX 10 mx10.gnu.org MX 10 mx10.gnu.org MX 20 mx20.gnu.org getting cache info for email@example.com found status: success (0), time: Thu Sep 14 14:54:41 2006 getting rate info for firstname.lastname@example.org found time: 1158245710, interval: 29, count: 5, rate: 0.172414 rate for email@example.com is 0.162162 updating firstname.lastname@example.org rates SET REPLY 450 4.7.0 Mail sending rate exceeded. Try again later State envfrom: tempfail
To test any handler, other than ‘envfrom’, give its name as the argument to --test option. Since this argument is optional, it is important that it be given immediately after the option, without any intervening white space, for example mailfromd --test=helo, or mailfromd -thelo.
This method allows to test one handler at a time. To test the
script as a whole, use
mtasim utility. When
started it enters interactive mode, similar to that of
sendmail -bs, where it expects SMTP commands on
its standard input and sends answers to the standard output. The
--port=auto command line option instructs it to start
mailfromd and to create a unique socket for communication
with it. For the detailed description of the program and the ways to
use it, See mtasim.
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.