1REGEXP_TABLE(5) File Formats Manual REGEXP_TABLE(5)
2
3
4
6 regexp_table - format of Postfix regular expression tables
7
9 postmap -q "string" regexp:/etc/postfix/filename
10
11 postmap -q - regexp:/etc/postfix/filename <inputfile
12
14 The Postfix mail system uses optional tables for address rewriting,
15 mail routing, or access control. These tables are usually in dbm or db
16 format.
17
18 Alternatively, lookup tables can be specified in POSIX regular expres‐
19 sion form. In this case, each input is compared against a list of pat‐
20 terns. When a match is found, the corresponding result is returned and
21 the search is terminated.
22
23 To find out what types of lookup tables your Postfix system supports
24 use the "postconf -m" command.
25
26 To test lookup tables, use the "postmap -q" command as described in the
27 SYNOPSIS above. Use "postmap -hmq - <file" for header_checks(5) pat‐
28 terns, and "postmap -bmq - <file" for body_checks(5) (Postfix 2.6 and
29 later).
30
32 With Postfix version 2.2 and earlier specify "postmap -fq" to query a
33 table that contains case sensitive patterns. Patterns are case insensi‐
34 tive by default.
35
37 The general form of a Postfix regular expression table is:
38
39 /pattern/flags result
40 When pattern matches the input string, use the corresponding
41 result value.
42
43 !/pattern/flags result
44 When pattern does not match the input string, use the corre‐
45 sponding result value.
46
47 if /pattern/flags
48
49 endif If the input string matches /pattern/, then match that input
50 string against the patterns between if and endif. The if..endif
51 can nest.
52
53 Note: do not prepend whitespace to patterns inside if..endif.
54
55 This feature is available in Postfix 2.1 and later.
56
57 if !/pattern/flags
58
59 endif If the input string does not match /pattern/, then match that
60 input string against the patterns between if and endif. The
61 if..endif can nest.
62
63 Note: do not prepend whitespace to patterns inside if..endif.
64
65 This feature is available in Postfix 2.1 and later.
66
67 blank lines and comments
68 Empty lines and whitespace-only lines are ignored, as are lines
69 whose first non-whitespace character is a `#'.
70
71 multi-line text
72 A logical line starts with non-whitespace text. A line that
73 starts with whitespace continues a logical line.
74
75 Each pattern is a POSIX regular expression enclosed by a pair of delim‐
76 iters. The regular expression syntax is documented in re_format(7) with
77 4.4BSD, in regex(5) with Solaris, and in regex(7) with Linux. Other
78 systems may use other document names.
79
80 The expression delimiter can be any non-alphanumerical character,
81 except whitespace or characters that have special meaning (tradition‐
82 ally the forward slash is used). The regular expression can contain
83 whitespace.
84
85 By default, matching is case-insensitive, and newlines are not treated
86 as special characters. The behavior is controlled by flags, which are
87 toggled by appending one or more of the following characters after the
88 pattern:
89
90 i (default: on)
91 Toggles the case sensitivity flag. By default, matching is case
92 insensitive.
93
94 m (default: off)
95 Toggle the multi-line mode flag. When this flag is on, the ^ and
96 $ metacharacters match immediately after and immediately before
97 a newline character, respectively, in addition to matching at
98 the start and end of the input string.
99
100 x (default: on)
101 Toggles the extended expression syntax flag. By default, support
102 for extended expression syntax is enabled.
103
105 Patterns are applied in the order as specified in the table, until a
106 pattern is found that matches the input string.
107
108 Each pattern is applied to the entire input string. Depending on the
109 application, that string is an entire client hostname, an entire client
110 IP address, or an entire mail address. Thus, no parent domain or par‐
111 ent network search is done, and user@domain mail addresses are not bro‐
112 ken up into their user and domain constituent parts, nor is user+foo
113 broken up into user and foo.
114
116 Substitution of substrings (text that matches patterns inside "()")
117 from the matched expression into the result string is requested with
118 $1, $2, etc.; specify $$ to produce a $ character as output. The
119 macros in the result string may need to be written as ${n} or $(n) if
120 they aren't followed by whitespace.
121
122 Note: since negated patterns (those preceded by !) return a result when
123 the expression does not match, substitutions are not available for
124 negated patterns.
125
127 # Disallow sender-specified routing. This is a must if you relay mail
128 # for other domains.
129 /[%!@].*[%!@]/ 550 Sender-specified routing rejected
130
131 # Postmaster is OK, that way they can talk to us about how to fix
132 # their problem.
133 /^postmaster@/ OK
134
135 # Protect your outgoing majordomo exploders
136 if !/^owner-/
137 /^(.*)-outgoing@(.*)$/ 550 Use ${1}@${2} instead
138 endif
139
141 # These were once common in junk mail.
142 /^Subject: make money fast/ REJECT
143 /^To: friend@public\.com/ REJECT
144
146 # First skip over base 64 encoded text to save CPU cycles.
147 ~^[[:alnum:]+/]{60,}$~ OK
148
149 # Put your own body patterns here.
150
152 postmap(1), Postfix lookup table manager
153 pcre_table(5), format of PCRE tables
154 cidr_table(5), format of CIDR tables
155
157 Use "postconf readme_directory" or "postconf html_directory" to locate
158 this information.
159 DATABASE_README, Postfix lookup table overview
160
162 The regexp table lookup code was originally written by:
163 LaMont Jones
164 lamont@hp.com
165
166 That code was based on the PCRE dictionary contributed by:
167 Andrew McNamara
168 andrewm@connect.com.au
169 connect.com.au Pty. Ltd.
170 Level 3, 213 Miller St
171 North Sydney, NSW, Australia
172
173 Adopted and adapted by:
174 Wietse Venema
175 IBM T.J. Watson Research
176 P.O. Box 704
177 Yorktown Heights, NY 10598, USA
178
179 Wietse Venema
180 Google, Inc.
181 111 8th Avenue
182 New York, NY 10011, USA
183
184
185
186 REGEXP_TABLE(5)