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