Mailfromd 

GeneralPurpose Mail Filter 
Sergey Poznyakoff 
In addition to the traditional relational operators, described
above, mailfromd
provides two operators for regular
expression matching:
Expression  Result 

x matches y  True if the string x matches the regexp denoted by y. 
x fnmatches y  True if the string x matches the globbing pattern denoted by y. 
The type of the regular expression used by matches
operator
is controlled by #pragma regex
(see pragma regex). For example:
$f ⇒ "gray@gnu.org.ua" $f matches '.*@gnu\.org\.ua' ⇒true
$f matches '.*@GNU\.ORG\.UA' ⇒false
#pragma regex +icase $f matches '.*@GNU\.ORG\.UA' ⇒true
The fnmatches
operator compares its lefthand operand with a
globbing pattern (see glob(7)) given as its righthand side
operand. For example:
$f ⇒ "gray@gnu.org.ua" $f fnmatches "*ua" ⇒true
$f fnmatches "*org" ⇒false
$f fnmatches "*org*" ⇒true
Both operators have a special form, for ‘MX’ pattern matching. The expression:
x mx matches y
is evaluated as follows: first, the expression x is analyzed and, if it is an email address, its domain part is selected. If it is not, its value is used verbatim. Then the list of ‘MX’s for this domain is looked up. Each of ‘MX’ names is then compared with the regular expression y. If any of the names matches, the expression returns true. Otherwise, its result is false.
Similarly, the expression:
x mx fnmatches y
returns true only if any of the ‘MX’s for (domain or email) x match the globbing pattern y.
Both mx matches
and mx fnmatches
can signal the
following exceptions: e_temp_failure
, e_failure
.
The value of any parenthesized subexpression occurring within the
righthand side argument to matches
or mx matches
can be
referenced using the notation ‘\d’, where d is the
ordinal number of the subexpression (subexpressions are numbered from
left to right, starting at 1). This notation is allowed in the
program text as well as within doublequoted strings and
heredocuments, for example:
if $f matches '.*@\(.*\)\.gnu\.org\.ua' set message "Your host name is \1;" fi
Remember that the grouping symbols are ‘\(’ and ‘\)’ for basic regular expressions, and ‘(’ and ‘)’ for extended regular expressions. Also make sure you properly escape all special characters (backslashes in particular) in doublequoted strings, or use singlequoted strings to avoid having to do so (see singevsdouble, for a comparison of the two forms).
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.