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
latter case, 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.mfl: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 mailfromd
to
also print the column number. E.g. with this option the above
error message may look like:
mailfromd: /etc/mailfromd.mfl: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:
Either number
or string
.
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.mfl:48 clamav_virus_name string 9 /etc/mailfromd.mfl:240,240 db string 15 /etc/mailfromd.mfl:135,194,215 dns_record_ttl number 16 /etc/mailfromd.mfl:136,172,173 ehlo_domain string 11 gltime number 13 /etc/mailfromd.mfl:37,219,220,222,223 greylist_seconds_left number 1 /etc/mailfromd.mfl: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
values of 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 f
and client_addr
macros:
$ mailfromd --test f=gray@gnu.org 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 f=gray@gnu.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 gray@gnu.org found status: success (0), time: Thu Sep 14 14:54:41 2006 getting rate info for gray@gnu.org-127.0.0.1 found time: 1158245710, interval: 29, count: 5, rate: 0.172414 rate for gray@gnu.org-127.0.0.1 is 0.162162 updating gray@gnu.org-127.0.0.1 rates SET REPLY 450 4.7.0 Mail sending rate exceeded. Try again later State envfrom: tempfail
If your script uses echo
statements (see Echo), they will
print their output on standard error. To direct them to the standard
output, use the --echo option. You can also redirect the
echo
output to arbitrary file, by supplying its name as
argument, as in: --echo=file. see echo option.
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.