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

DESCRIPTION

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

COMPATIBILITY

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

TABLE FORMAT

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 character, except whitespace or characters that have
75       special meaning (traditionally the forward slash is used).  The regular
76       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              in the pattern (other than in a character class) and  characters
102              between a # outside a character class and the next newline char‐
103              acter are ignored. An escaping backslash can be used to  include
104              a whitespace or # character as part of the pattern.
105
106       A (default: off)
107              Toggles  the PCRE_ANCHORED flag.  When this flag is on, the pat‐
108              tern is forced to be "anchored", that is, it is  constrained  to
109              match  only  at  the start of the string which is being searched
110              (the "subject string"). This effect  can  also  be  achieved  by
111              appropriate constructs in the pattern itself.
112
113       E (default: off)
114              Toggles  the PCRE_DOLLAR_ENDONLY flag. When this flag is on, a $
115              metacharacter in the pattern matches only at the end of the sub‐
116              ject  string.  Without  this flag, a dollar also matches immedi‐
117              ately before the final character if it is  a  newline  character
118              (but  not  before  any  other  newline characters). This flag is
119              ignored if PCRE_MULTILINE flag is set.
120
121       U (default: off)
122              Toggles the ungreedy matching flag.  When this flag is  on,  the
123              pattern  matching engine inverts the "greediness" of the quanti‐
124              fiers so that they are not greedy by default, but become  greedy
125              if  followed  by "?".  This flag can also set by a (?U) modifier
126              within the pattern.
127
128       X (default: off)
129              Toggles the PCRE_EXTRA flag.  When this flag is  on,  any  back‐
130              slash in a pattern that is followed by a letter that has no spe‐
131              cial meaning causes an error, thus reserving these  combinations
132              for future expansion.
133

SEARCH ORDER

135       Patterns  are  applied  in the order as specified in the table, until a
136       pattern is found that matches the input string.
137
138       Each pattern is applied to the entire input string.  Depending  on  the
139       application, that string is an entire client hostname, an entire client
140       IP address, or an entire mail address.  Thus, no parent domain or  par‐
141       ent network search is done, and user@domain mail addresses are not bro‐
142       ken up into their user and domain constituent parts,  nor  is  user+foo
143       broken up into user and foo.
144

TEXT SUBSTITUTION

146       Substitution  of substrings from the matched expression into the result
147       string is possible using the conventional perl syntax ($1,  $2,  etc.);
148       specify  $$  to  produce  a  $  character as output.  The macros in the
149       result string may need to be written as ${n} or  $(n)  if  they  aren't
150       followed by whitespace.
151
152       Note: since negated patterns (those preceded by !) return a result when
153       the expression does not match,  substitutions  are  not  available  for
154       negated patterns.
155

EXAMPLE SMTPD ACCESS MAP

157       # Protect your outgoing majordomo exploders
158       /^(?!owner-)(.*)-outgoing@(.*)/ 550 Use ${1}@${2} instead
159
160       # Bounce friend@whatever, except when whatever is our domain (you would
161       # be better just bouncing all friend@ mail - this is just an example).
162       /^(friend@(?!my\.domain$).*)$/  550 Stick this in your pipe $1
163
164       # A multi-line entry. The text is sent as one line.
165       #
166       /^noddy@my\.domain$/
167        550 This user is a funny one. You really don't want to send mail to
168        them as it only makes their head spin.
169

EXAMPLE HEADER FILTER MAP

171       /^Subject: make money fast/     REJECT
172       /^To: friend@public\.com/       REJECT
173

EXAMPLE BODY FILTER MAP

175       # First skip over base 64 encoded text to save CPU cycles.
176       # Requires PCRE version 3.
177       ~^[[:alnum:]+/]{60,}$~          OK
178
179       # Put your own body patterns here.
180

SEE ALSO

182       postmap(1), Postfix lookup table manager
183       postconf(5), configuration parameters
184       regexp_table(5), format of POSIX regular expression tables
185

README FILES

187       Use  "postconf readme_directory" or "postconf html_directory" to locate
188       this information.
189       DATABASE_README, Postfix lookup table overview
190

AUTHOR(S)

192       The PCRE table lookup code was originally written by:
193       Andrew McNamara
194       andrewm@connect.com.au
195       connect.com.au Pty. Ltd.
196       Level 3, 213 Miller St
197       North Sydney, NSW, Australia
198
199       Adopted and adapted by:
200       Wietse Venema
201       IBM T.J. Watson Research
202       P.O. Box 704
203       Yorktown Heights, NY 10598, USA
204
205
206
207                                                                 PCRE_TABLE(5)
Impressum