Next: Conditionals, Previous: Shadowing, Up: MFL [Contents][Index]
Statements are language constructs, that, unlike expressions, do not return any value. Statements execute some actions, such as assigning a value to a variable, or serve to control the execution flow in the program.
• Actions | Actions control the handling of the mail. | |
• Assignments | ||
• Pass | ||
• Echo |
Next: Assignments, Up: Statements [Contents][Index]
An action statement instructs mailfromd
to
perform a certain action over the message being processed. There are
two kinds of actions: return actions and header manipulation actions.
Reply actions tell Sendmail
to return given response code
to the remote party. There are five such actions:
accept
Return an accept
reply. The remote party will continue
transmitting its message.
reject code excode message-expr
reject (code-expr, excode-expr, message-expr)
Return a reject
reply. The remote party will have to
cancel transmitting its message. The three arguments are optional,
their usage is described below.
tempfail code excode message
tempfail (code-expr, excode-expr, message-expr)
Return a ‘temporary failure’ reply. The remote party can retry to send its message later. The three arguments are optional, their usage is described below.
discard
Instructs Sendmail
to accept the message and silently discard
it without delivering it to any recipient.
continue
Stops the current handler and instructs Sendmail
to
continue processing of the message.
Two actions, reject
and tempfail
can take up to three
optional parameters. There are two forms of supplying these
parameters.
In the first form, called literal or traditional notation,
the arguments are supplied as additional words after the action name,
and are separated by whitespace. The first argument is a three-digit
RFC 2821 reply code. It must begin with ‘5’ for
reject
and with ‘4’ for tempfail
. If two arguments
are supplied, the second argument must be either an extended
reply code (RFC 1893/2034) or a textual string to be
returned along with the SMTP reply. Finally, if all three
arguments are supplied, then the second one must be an extended reply
code and the third one must give the textual string. The following
examples illustrate the possible ways of using the reject
statement:
reject reject 503 reject 503 5.0.0 reject 503 "Need HELO command" reject 503 5.0.0 "Need HELO command"
Used without arguments, reject
is equivalent to
reject 550
and tempfail
to
tempfail 451
In literal notation, the values of code and extendended code (if supplied) must be literal strings. The third argument (textual message) can be either a literal string or MFL expression that evaluates to string.
The second form of supplying arguments is called functional notation, because it resembles the function syntax. When used in this form, the action word is followed by a parenthesized group of exactly three arguments, separated by commas. Each argument is a MFL expression. The meaning and ordering of the arguments is the same as in literal form. Any or all of these three arguments may be absent, in which case the corresponding default value will be used16. To illustrate this, here are the statements from the previous example, written in functional notation:
reject(,,) reject(503,,) reject(503, 5.0.0) reject(503, , "Need HELO command") reject(503, 5.0.0, "Need HELO command")
Notice that there is an important difference between the two notations. The functional notation allows to compute both reply codes at run time, e.g.:
reject(500 + dig2*10 + dig3, "5.%edig2.%edig2")
Header manipulation actions provide basic means to add, delete or modify the message RFC 2822 headers.
add name string
Add the header name with the value string. E.g.:
add "X-Seen-By" "Mailfromd 9.0"
(notice argument quoting)
replace name string
The same as add
, but if the header name already
exists, it will be removed first, for example:
replace "X-Last-Processor" "Mailfromd 9.0"
delete name
Delete the header named name:
delete "X-Envelope-Date"
These actions impose some restrictions. First of all, their first argument must be a literal string (not a variable or expression). Secondly, there is no way to select a particular header instance to delete or replace, which may be necessary to properly handle multiple headers (e.g. ‘Received’). For more elaborate ways of header modifications, see Header modification functions.
Next: Pass, Previous: Actions, Up: Statements [Contents][Index]
An assignment is a special statement that assigns a value to the variable. It has the following syntax:
set name value
where name is the variable name and value is the value to be assigned to it.
Assignment statements can appear in any part of a filter program.
If an assignment occurs outside of function or handler definition,
the value must be a literal value (see Literals). If it
occurs within a function or handler definition, value can be any
valid mailfromd
expression (see Expressions). In this
case, the expression will be evaluated and its value will be assigned
to the variable. For example:
set delay 150 prog envfrom do set delay delay * 2 … done
Next: Echo, Previous: Assignments, Up: Statements [Contents][Index]
pass
statementThe pass
statement has no effect. It is used in places
where no statement is needed, but the language syntax requires one:
on poll $f do when success: pass when not_found or failure: reject 550 done
Previous: Pass, Up: Statements [Contents][Index]
echo
statementThe echo
statement concatenates all its arguments into a single
string and sends it to the syslog
using the priority
‘info’. It is useful for debugging your script, in
conjunction with built-in constants (see Built-in constants), for
example:
func foo(number x) do echo "%__file__:%__line__: foo called with arg %x" … done
The default value for code is
550 for reject
and
451 for tempfail
. The remaining two
arguments default to empty strings.
Previous: Pass, Up: Statements [Contents][Index]