1PCRE_TABLE(5)                 File Formats Manual                PCRE_TABLE(5)
2
3
4

NAME

6       pcre_table - format of Postfix PCRE tables
7

SYNOPSIS

9       postmap -q "string" pcre:/etc/postfix/filename
10
11       postmap -q - pcre:/etc/postfix/filename <inputfile
12
13       postmap -hmq - pcre:/etc/postfix/filename <inputfile
14
15       postmap -bmq - pcre:/etc/postfix/filename <inputfile
16

DESCRIPTION

18       The  Postfix  mail  system  uses optional tables for address rewriting,
19       mail routing, or access control. These tables are usually in dbm or  db
20       format.
21
22       Alternatively,  lookup tables can be specified in Perl Compatible Regu‐
23       lar Expression form. In this case, each input  is  compared  against  a
24       list  of  patterns.  When a match is found, the corresponding result is
25       returned and the search is terminated.
26
27       To find out what types of lookup tables your  Postfix  system  supports
28       use the "postconf -m" command.
29
30       To test lookup tables, use the "postmap -q" command as described in the
31       SYNOPSIS above. Use "postmap -hmq - <file"  for  header_checks(5)  pat‐
32       terns,  and  "postmap -bmq - <file" for body_checks(5) (Postfix 2.6 and
33       later).
34
35       This driver can be built  with  the  pcre2  library  (Postfix  3.7  and
36       later), or with the legacy pcre library (all Postfix versions).
37

COMPATIBILITY

39       With  Postfix  version 2.2 and earlier specify "postmap -fq" to query a
40       table that contains case sensitive patterns. Patterns are case insensi‐
41       tive by default.
42

TABLE FORMAT

44       The general form of a PCRE table is:
45
46       /pattern/flags result
47              When pattern matches the input string, use the corresponding re‐
48              sult value.
49
50       !/pattern/flags result
51              When pattern does not match the input  string,  use  the  corre‐
52              sponding result value.
53
54       if /pattern/flags
55
56       endif  If  the  input  string  matches /pattern/, then match that input
57              string against the patterns between if and endif.  The if..endif
58              can nest.
59
60              Note: do not prepend whitespace to patterns inside if..endif.
61
62              This feature is available in Postfix 2.1 and later.
63
64       if !/pattern/flags
65
66       endif  If  the  input  string does not match /pattern/, then match that
67              input string against the patterns  between  if  and  endif.  The
68              if..endif can nest.
69
70              Note: do not prepend whitespace to patterns inside if..endif.
71
72              This feature is available in Postfix 2.1 and later.
73
74       blank lines and comments
75              Empty  lines and whitespace-only lines are ignored, as are lines
76              whose first non-whitespace character is a `#'.
77
78       multi-line text
79              A logical line starts with  non-whitespace  text.  A  line  that
80              starts with whitespace continues a logical line.
81
82       Each  pattern  is a perl-like regular expression. The expression delim‐
83       iter can be any non-alphanumeric character, except whitespace or  char‐
84       acters  that  have  special meaning (traditionally the forward slash is
85       used).  The regular expression can contain whitespace.
86
87       By default, matching is case-insensitive, and newlines are not  treated
88       as  special  characters. The behavior is controlled by flags, which are
89       toggled by appending one or more of the following characters after  the
90       pattern:
91
92       i (default: on)
93              Toggles  the case sensitivity flag. By default, matching is case
94              insensitive.
95
96       m (default: off)
97              Toggles the pcre MULTILINE flag. When this flag is on, the ^ and
98              $  metacharacters match immediately after and immediately before
99              a newline character, respectively, in addition  to  matching  at
100              the start and end of the subject string.
101
102       s (default: on)
103              Toggles  the  pcre  DOTALL  flag.  When  this  flag is on, the .
104              metacharacter matches the newline character. With  Postfix  ver‐
105              sions  prior to 2.0, the flag is off by default, which is incon‐
106              venient for multi-line message header matching.
107
108       x (default: off)
109              Toggles the pcre extended flag. When this flag is on, whitespace
110              characters  in the pattern (other than in a character class) are
111              ignored.  To include a whitespace character as part of the  pat‐
112              tern, escape it with backslash.
113
114              Note: do not use #comment after patterns.
115
116       A (default: off)
117              Toggles  the pcre ANCHORED flag.  When this flag is on, the pat‐
118              tern is forced to be "anchored", that is, it is  constrained  to
119              match  only  at  the start of the string which is being searched
120              (the "subject string"). This effect can also be achieved by  ap‐
121              propriate constructs in the pattern itself.
122
123       E (default: off)
124              Toggles  the pcre DOLLAR_ENDONLY flag. When this flag is on, a $
125              metacharacter in the pattern matches only at the end of the sub‐
126              ject  string.  Without  this flag, a dollar also matches immedi‐
127              ately before the final character if it is  a  newline  character
128              (but  not before any other newline characters). This flag is ig‐
129              nored if the pcre MULTILINE flag is set.
130
131       U (default: off)
132              Toggles the pcre UNGREEDY flag.  When this flag is on, the  pat‐
133              tern matching engine inverts the "greediness" of the quantifiers
134              so that they are not greedy by default,  but  become  greedy  if
135              followed  by  "?".   This  flag  can also set by a (?U) modifier
136              within the pattern.
137
138       X (default: off)
139              Toggles the pcre EXTRA flag.  When this flag is  on,  any  back‐
140              slash in a pattern that is followed by a letter that has no spe‐
141              cial meaning causes an error, thus reserving these  combinations
142              for future expansion.
143
144              This feature is not supported with PCRE2.
145

SEARCH ORDER

147       Patterns  are  applied  in the order as specified in the table, until a
148       pattern is found that matches the input string.
149
150       Each pattern is applied to the entire input string.  Depending  on  the
151       application, that string is an entire client hostname, an entire client
152       IP address, or an entire mail address.  Thus, no parent domain or  par‐
153       ent network search is done, and user@domain mail addresses are not bro‐
154       ken up into their user and domain constituent parts,  nor  is  user+foo
155       broken up into user and foo.
156

TEXT SUBSTITUTION

158       Substitution  of  substrings  (text  that matches patterns inside "()")
159       from the matched expression into the result string  is  requested  with
160       $1,  $2,  etc.;  specify  $$  to  produce a $ character as output.  The
161       macros in the result string may need to be written as ${n} or  $(n)  if
162       they  aren't  followed  by  whitespace.   This feature does not support
163       pcre2 substring names.
164
165       Note: since negated patterns (those preceded by !) return a result when
166       the  expression  does  not  match,  substitutions are not available for
167       negated patterns.
168

INLINE SPECIFICATION

170       The contents of a table may be specified in the table name.  The  basic
171       syntax is:
172
173       main.cf:
174           parameter = .. pcre:{ { rule-1 }, { rule-2 } .. } ..
175
176       master.cf:
177           .. -o { parameter = .. pcre:{ { rule-1 }, { rule-2 } .. } .. } ..
178
179       Postfix  ignores  whitespace  after '{' and before '}', and writes each
180       rule as one text line to an in-memory file:
181
182       in-memory file:
183           rule-1
184           rule-2
185           ..
186
187       Postfix parses the result as if it is a file in /etc/postfix.
188
189       Note: if a rule contains $, specify $$ to keep Postfix from  trying  to
190       do $name expansion as it evaluates a parameter value.
191

EXAMPLE SMTPD ACCESS MAP

193       # Protect your outgoing majordomo exploders
194       /^(?!owner-)(.*)-outgoing@(.*)/ 550 Use ${1}@${2} instead
195
196       # Bounce friend@whatever, except when whatever is our domain (you would
197       # be better just bouncing all friend@ mail - this is just an example).
198       /^(friend@(?!my\.domain$).*)$/  550 Stick this in your pipe $1
199
200       # A multi-line entry. The text is sent as one line.
201       #
202       /^noddy@my\.domain$/
203        550 This user is a funny one. You really don't want to send mail to
204        them as it only makes their head spin.
205

EXAMPLE HEADER FILTER MAP

207       /^Subject: make money fast/     REJECT
208       /^To: friend@public\.com/       REJECT
209

EXAMPLE BODY FILTER MAP

211       # First skip over base 64 encoded text to save CPU cycles.
212       # Requires PCRE version 3.
213       ~^[[:alnum:]+/]{60,}$~          OK
214
215       # Put your own body patterns here.
216

SEE ALSO

218       postmap(1), Postfix lookup table manager
219       postconf(5), configuration parameters
220       regexp_table(5), format of POSIX regular expression tables
221

README FILES

223       Use  "postconf readme_directory" or "postconf html_directory" to locate
224       this information.
225       DATABASE_README, Postfix lookup table overview
226

AUTHOR(S)

228       The PCRE table lookup code was originally written by:
229       Andrew McNamara
230       andrewm@connect.com.au
231       connect.com.au Pty. Ltd.
232       Level 3, 213 Miller St
233       North Sydney, NSW, Australia
234
235       Adopted and adapted by:
236       Wietse Venema
237       IBM T.J. Watson Research
238       P.O. Box 704
239       Yorktown Heights, NY 10598, USA
240
241       Wietse Venema
242       Google, Inc.
243       111 8th Avenue
244       New York, NY 10011, USA
245
246
247
248                                                                 PCRE_TABLE(5)
Impressum