1PCRE_TABLE(5) File Formats Manual PCRE_TABLE(5)
2
3
4
6 pcre_table - format of Postfix PCRE tables
7
9 postmap -q "string" pcre:/etc/postfix/filename
10
11 postmap -q - pcre:/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 Perl Compatible Regu‐
19 lar Expression form. In this case, each input is compared against a
20 list of patterns. When a match is found, the corresponding result is
21 returned and 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 PCRE 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 perl-like regular expression. The expression delim‐
74 iter can be any non-alphanumerical character, except whitespace or
75 characters that have special meaning (traditionally the forward slash
76 is used). The regular expression can contain whitespace.
77
78 By default, matching is case-insensitive, and newlines are not treated
79 as special characters. The behavior is controlled by flags, which are
80 toggled by appending one or more of the following characters after the
81 pattern:
82
83 i (default: on)
84 Toggles the case sensitivity flag. By default, matching is case
85 insensitive.
86
87 m (default: off)
88 Toggles the PCRE_MULTILINE flag. When this flag is on, the ^ and
89 $ metacharacters match immediately after and immediately before
90 a newline character, respectively, in addition to matching at
91 the start and end of the subject string.
92
93 s (default: on)
94 Toggles the PCRE_DOTALL flag. When this flag is on, the .
95 metacharacter matches the newline character. With Postfix ver‐
96 sions prior to 2.0, the flag is off by default, which is incon‐
97 venient for multi-line message header matching.
98
99 x (default: off)
100 Toggles the pcre extended flag. When this flag is on, whitespace
101 characters in the pattern (other than in a character class) are
102 ignored. To include a whitespace character as part of the pat‐
103 tern, escape it with backslash.
104
105 Note: do not use #comment after patterns.
106
107 A (default: off)
108 Toggles the PCRE_ANCHORED flag. When this flag is on, the pat‐
109 tern is forced to be "anchored", that is, it is constrained to
110 match only at the start of the string which is being searched
111 (the "subject string"). This effect can also be achieved by
112 appropriate constructs in the pattern itself.
113
114 E (default: off)
115 Toggles the PCRE_DOLLAR_ENDONLY flag. When this flag is on, a $
116 metacharacter in the pattern matches only at the end of the sub‐
117 ject string. Without this flag, a dollar also matches immedi‐
118 ately before the final character if it is a newline character
119 (but not before any other newline characters). This flag is
120 ignored if PCRE_MULTILINE flag is set.
121
122 U (default: off)
123 Toggles the ungreedy matching flag. When this flag is on, the
124 pattern matching engine inverts the "greediness" of the quanti‐
125 fiers so that they are not greedy by default, but become greedy
126 if followed by "?". This flag can also set by a (?U) modifier
127 within the pattern.
128
129 X (default: off)
130 Toggles the PCRE_EXTRA flag. When this flag is on, any back‐
131 slash in a pattern that is followed by a letter that has no spe‐
132 cial meaning causes an error, thus reserving these combinations
133 for future expansion.
134
136 Patterns are applied in the order as specified in the table, until a
137 pattern is found that matches the input string.
138
139 Each pattern is applied to the entire input string. Depending on the
140 application, that string is an entire client hostname, an entire client
141 IP address, or an entire mail address. Thus, no parent domain or par‐
142 ent network search is done, and user@domain mail addresses are not bro‐
143 ken up into their user and domain constituent parts, nor is user+foo
144 broken up into user and foo.
145
147 Substitution of substrings from the matched expression into the result
148 string is possible using the conventional perl syntax ($1, $2, etc.);
149 specify $$ to produce a $ character as output. The macros in the
150 result string may need to be written as ${n} or $(n) if they aren't
151 followed by whitespace.
152
153 Note: since negated patterns (those preceded by !) return a result when
154 the expression does not match, substitutions are not available for
155 negated patterns.
156
158 # Protect your outgoing majordomo exploders
159 /^(?!owner-)(.*)-outgoing@(.*)/ 550 Use ${1}@${2} instead
160
161 # Bounce friend@whatever, except when whatever is our domain (you would
162 # be better just bouncing all friend@ mail - this is just an example).
163 /^(friend@(?!my\.domain$).*)$/ 550 Stick this in your pipe $1
164
165 # A multi-line entry. The text is sent as one line.
166 #
167 /^noddy@my\.domain$/
168 550 This user is a funny one. You really don't want to send mail to
169 them as it only makes their head spin.
170
172 /^Subject: make money fast/ REJECT
173 /^To: friend@public\.com/ REJECT
174
176 # First skip over base 64 encoded text to save CPU cycles.
177 # Requires PCRE version 3.
178 ~^[[:alnum:]+/]{60,}$~ OK
179
180 # Put your own body patterns here.
181
183 postmap(1), Postfix lookup table manager
184 postconf(5), configuration parameters
185 regexp_table(5), format of POSIX regular expression tables
186
188 Use "postconf readme_directory" or "postconf html_directory" to locate
189 this information.
190 DATABASE_README, Postfix lookup table overview
191
193 The PCRE table lookup code was originally written by:
194 Andrew McNamara
195 andrewm@connect.com.au
196 connect.com.au Pty. Ltd.
197 Level 3, 213 Miller St
198 North Sydney, NSW, Australia
199
200 Adopted and adapted by:
201 Wietse Venema
202 IBM T.J. Watson Research
203 P.O. Box 704
204 Yorktown Heights, NY 10598, USA
205
206
207
208 PCRE_TABLE(5)