7
format of Postfix regular expression tables
11
\fBpostmap -fq "\fIstring\fB" regexp:/etc/postfix/\fIfilename\fR
13
\fBpostmap -fq - regexp:/etc/postfix/\fIfilename\fR <\fIinputfile\fR
17
The Postfix mail system uses optional tables for address
18
rewriting or mail routing. These tables are usually in
19
\fBdbm\fR or \fBdb\fR format.
21
Alternatively, lookup tables can be specified in POSIX regular
22
expression form. In this case, each input is compared against a
23
list of patterns, and when a match is found the corresponding
26
To find out what types of lookup tables your Postfix system
27
supports use the \fBpostconf -m\fR command.
29
To test lookup tables, use the \fBpostmap -fq\fR command as
30
described in the SYNOPSIS above.
36
The general form of a Postfix regular expression table is:
37
.IP "\fB/\fIpattern\fB/\fIflags result\fR"
38
When \fIpattern\fR matches the input string,
39
use the corresponding \fIresult\fR value.
40
.IP "\fB!/\fIpattern\fB/\fIflags result\fR"
41
When \fIpattern\fR does \fBnot\fR match the input string,
42
use the corresponding \fIresult\fR value.
43
.IP "\fBif /\fIpattern\fB/\fIflags\fR"
45
Match the input string against the patterns between \fBif\fR
46
and \fBendif\fR, if and only if that same input string also
47
matches \fIpattern\fR. The \fBif\fR..\fBendif\fR can nest.
49
Note: do not prepend whitespace to patterns inside
50
\fBif\fR..\fBendif\fR.
51
.IP "\fBif !/\fIpattern\fB/\fIflags\fR"
53
Match the input string against the patterns between \fBif\fR
54
and \fBendif\fR, if and only if that same input string does
55
\fBnot\fR match \fIpattern\fR. The \fBif\fR..\fBendif\fR can nest.
56
.IP "blank lines and comments"
57
Empty lines and whitespace-only lines are ignored, as
58
are lines whose first non-whitespace character is a `#'.
60
A logical line starts with non-whitespace text. A line that
61
starts with whitespace continues a logical line.
63
Each pattern is a POSIX regular expression enclosed by a pair of
64
delimiters. The regular expression syntax is documented in
65
re_format(7) with 4.4BSD, in regcomp(3C) with Solaris, and in
66
regex(7) with Linux. Other systems may use other document names.
68
The expression delimiter can be any character, except whitespace
69
or characters that have special meaning (traditionally the forward
70
slash is used). The regular expression can contain whitespace.
72
By default, matching is case-insensitive, and newlines are not
73
treated as special characters. The behavior is controlled by flags,
74
which are toggled by appending one or more of the following
75
characters after the pattern:
76
.IP "\fBi\fR (default: on)"
77
Toggles the case sensitivity flag. By default, matching is case
79
.IP "\fBx\fR (default: on)"
80
Toggles the extended expression syntax flag. By default, support
81
for extended expression syntax is enabled.
82
.IP "\fBm\fR (default: off)"
83
Toggle the multi-line mode flag. When this flag is on, the \fB^\fR
84
and \fB$\fR metacharacters match immediately after and immediately
85
before a newline character, respectively, in addition to
86
matching at the start and end of the input string.
87
.SH "TABLE SEARCH ORDER"
92
Patterns are applied in the order as specified in the table, until a
93
pattern is found that matches the input string.
95
Each pattern is applied to the entire input string.
96
Depending on the application, that string is an entire client
97
hostname, an entire client IP address, or an entire mail address.
98
Thus, no parent domain or parent network search is done, and
99
\fIuser@domain\fR mail addresses are not broken up into their
100
\fIuser\fR and \fIdomain\fR constituent parts, nor is \fIuser+foo\fR
101
broken up into \fIuser\fR and \fIfoo\fR.
102
.SH "TEXT SUBSTITUTION"
107
Substitution of substrings from the matched expression into the result
108
string is possible using $1, $2, etc.. The macros in the result string
109
may need to be written as ${n} or $(n) if they aren't followed
112
Note: since negated patterns (those preceded by \fB!\fR) return a
113
result when the expression does not match, substitutions are not
114
available for negated patterns.
115
.SH "EXAMPLE SMTPD ACCESS MAP"
118
# Disallow sender-specified routing. This is a must if you relay mail
120
/[%!@].*[%!@]/ 550 Sender-specified routing rejected
122
# Postmaster is OK, that way they can talk to us about how to fix
126
# Protect your outgoing majordomo exploders
128
/^(.*)-outgoing@(.*)$/ 550 Use ${1}@${2} instead
130
.SH "EXAMPLE HEADER FILTER MAP"
133
# These were once common in junk mail.
134
/^Subject: make money fast/ REJECT
135
/^To: friend@public\\.com/ REJECT
136
.SH "EXAMPLE BODY FILTER MAP"
139
# First skip over base 64 encoded text to save CPU cycles.
140
~^[[:alnum:]+/]{60,}$~ OK
142
# Put your own body patterns here.
146
postmap(1), Postfix lookup table manager
147
pcre_table(5), format of PCRE tables
148
cidr_table(5), format of CIDR tables
154
Use "\fBpostconf readme_directory\fR" or
155
"\fBpostconf html_directory\fR" to locate this information.
158
DATABASE_README, Postfix lookup table overview
162
The regexp table lookup code was originally written by:
166
That code was based on the PCRE dictionary contributed by:
168
andrewm@connect.com.au
169
connect.com.au Pty. Ltd.
170
Level 3, 213 Miller St
171
North Sydney, NSW, Australia
173
Adopted and adapted by:
175
IBM T.J. Watson Research
177
Yorktown Heights, NY 10598, USA