General-Purpose Mail Filter
Mailfromd provides a special option that allows to run arbitrary MFL scripts. This is an experimental feature, intended for future use of MFL as a scripting language.
When given the --run command line option,
mailfromd loads the script given in its command line and
executes a function called ‘main’.
The function main must be declared as:
func main(...) returns number
Mailfromd passes all command line arguments that follow the script
name as arguments to that function. When the function returns, its
return value is used by
mailfromd as exit code.
As an example, suppose the file script.mf contains the following:
func main (...) returns number do loop for number i 1, while i <= $#, set i i + 1 do echo "arg %i=" . $(i) done done
This function prints all its arguments (See variadic functions, for a detailed description of functions with variable number of arguments). Now running:
$ mailfromd --run script.mf 1 file dest
displays the following:
arg 1=1 arg 2=file arg 3=dest
Note, that MFL does not have a direct equivalent of
$0 argument. If your function needs to know the name
of the script that is being executed, use
constant instead (see __file__.
You may name your start function with any name other than the default
‘main’. In this case, give its name as an argument to the
--run option. This argument is optional, therefore it must
be separated from the option by an equals sign (with no whitespace
from either side). For example, given the command line below,
mailfromd loads the file script.mf and execute the
function named ‘start’:
$ mailfromd --run=start script.mf
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.