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 character, except whitespace or
79 characters that have special meaning (traditionally the forward slash
80 is used). The regular expression can contain whitespace.
81
82 By default, matching is case-insensitive, and newlines are not treated
83 as special characters. The behavior is controlled by flags, which are
84 toggled by appending one or more of the following characters after the
85 pattern:
86
87 i (default: on)
88 Toggles the case sensitivity flag. By default, matching is case
89 insensitive.
90
91 m (default: off)
92 Toggle the multi-line mode flag. When this flag is on, the ^ and
93 $ metacharacters match immediately after and immediately before
94 a newline character, respectively, in addition to matching at
95 the start and end of the input string.
96
97 x (default: on)
98 Toggles the extended expression syntax flag. By default, support
99 for extended expression syntax is enabled.
100
102 Patterns are applied in the order as specified in the table, until a
103 pattern is found that matches the input string.
104
105 Each pattern is applied to the entire input string. Depending on the
106 application, that string is an entire client hostname, an entire client
107 IP address, or an entire mail address. Thus, no parent domain or par‐
108 ent network search is done, and user@domain mail addresses are not bro‐
109 ken up into their user and domain constituent parts, nor is user+foo
110 broken up into user and foo.
111
113 Substitution of substrings from the matched expression into the result
114 string is possible using $1, $2, etc.; specify $$ to produce a $ char‐
115 acter as output. The macros in the result string may need to be writ‐
116 ten as ${n} or $(n) if they aren't followed by whitespace.
117
118 Note: since negated patterns (those preceded by !) return a result when
119 the expression does not match, substitutions are not available for
120 negated patterns.
121
123 # Disallow sender-specified routing. This is a must if you relay mail
124 # for other domains.
125 /[%!@].*[%!@]/ 550 Sender-specified routing rejected
126
127 # Postmaster is OK, that way they can talk to us about how to fix
128 # their problem.
129 /^postmaster@/ OK
130
131 # Protect your outgoing majordomo exploders
132 if !/^owner-/
133 /^(.*)-outgoing@(.*)$/ 550 Use ${1}@${2} instead
134 endif
135
137 # These were once common in junk mail.
138 /^Subject: make money fast/ REJECT
139 /^To: friend@public\.com/ REJECT
140
142 # First skip over base 64 encoded text to save CPU cycles.
143 ~^[[:alnum:]+/]{60,}$~ OK
144
145 # Put your own body patterns here.
146
148 postmap(1), Postfix lookup table manager
149 pcre_table(5), format of PCRE tables
150 cidr_table(5), format of CIDR tables
151
153 Use "postconf readme_directory" or "postconf html_directory" to locate
154 this information.
155 DATABASE_README, Postfix lookup table overview
156
158 The regexp table lookup code was originally written by:
159 LaMont Jones
160 lamont@hp.com
161
162 That code was based on the PCRE dictionary contributed by:
163 Andrew McNamara
164 andrewm@connect.com.au
165 connect.com.au Pty. Ltd.
166 Level 3, 213 Miller St
167 North Sydney, NSW, Australia
168
169 Adopted and adapted by:
170 Wietse Venema
171 IBM T.J. Watson Research
172 P.O. Box 704
173 Yorktown Heights, NY 10598, USA
174
175
176
177 REGEXP_TABLE(5)