1<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" 2 "https://www.w3.org/TR/html4/loose.dtd"> 3<html> <head> 4<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 5<link rel='stylesheet' type='text/css' href='postfix-doc.css'> 6<title> Postfix manual - pcre_table(5) </title> 7</head> <body> <pre> 8PCRE_TABLE(5) PCRE_TABLE(5) 9 10<b><a name="name">NAME</a></b> 11 pcre_table - format of Postfix PCRE tables 12 13<b><a name="synopsis">SYNOPSIS</a></b> 14 <b>postmap -q "</b><i>string</i><b>" <a href="pcre_table.5.html">pcre</a>:/etc/postfix/</b><i>filename</i> 15 16 <b>postmap -q - <a href="pcre_table.5.html">pcre</a>:/etc/postfix/</b><i>filename</i> <<i>inputfile</i> 17 18 <b>postmap -hmq - <a href="pcre_table.5.html">pcre</a>:/etc/postfix/</b><i>filename</i> <<i>inputfile</i> 19 20 <b>postmap -bmq - <a href="pcre_table.5.html">pcre</a>:/etc/postfix/</b><i>filename</i> <<i>inputfile</i> 21 22<b><a name="description">DESCRIPTION</a></b> 23 The Postfix mail system uses optional tables for address rewriting, 24 mail routing, or access control. These tables are usually in <b>dbm</b> or <b>db</b> 25 format. 26 27 Alternatively, lookup tables can be specified in Perl Compatible Regu- 28 lar Expression form. In this case, each input is compared against a 29 list of patterns. When a match is found, the corresponding result is 30 returned and the search is terminated. 31 32 To find out what types of lookup tables your Postfix system supports 33 use the "<b>postconf -m</b>" command. 34 35 To test lookup tables, use the "<b>postmap -q</b>" command as described in the 36 SYNOPSIS above. Use "<b>postmap -hmq -</b> <<i>file</i>" for <a href="header_checks.5.html">header_checks(5)</a> pat- 37 terns, and "<b>postmap -bmq -</b> <<i>file</i>" for <a href="header_checks.5.html">body_checks(5)</a> (Postfix 2.6 and 38 later). 39 40 This driver can be built with the pcre2 library (Postfix 3.7 and 41 later), or with the legacy pcre library (all Postfix versions). 42 43<b><a name="compatibility">COMPATIBILITY</a></b> 44 With Postfix version 2.2 and earlier specify "<b>postmap -fq</b>" to query a 45 table that contains case sensitive patterns. Patterns are case insensi- 46 tive by default. 47 48<b><a name="table_format">TABLE FORMAT</a></b> 49 The general form of a PCRE table is: 50 51 <b>/</b><i>pattern</i><b>/</b><i>flags result</i> 52 When <i>pattern</i> matches the input string, use the corresponding 53 <i>result</i> value. 54 55 <b>!/</b><i>pattern</i><b>/</b><i>flags result</i> 56 When <i>pattern</i> does <b>not</b> match the input string, use the corre- 57 sponding <i>result</i> value. 58 59 <b>if /</b><i>pattern</i><b>/</b><i>flags</i> 60 61 <b>endif</b> If the input string matches /<i>pattern</i>/, then match that input 62 string against the patterns between <b>if</b> and <b>endif</b>. The <b>if</b>..<b>endif</b> 63 can nest. 64 65 Note: do not prepend whitespace to patterns inside <b>if</b>..<b>endif</b>. 66 67 This feature is available in Postfix 2.1 and later. 68 69 <b>if !/</b><i>pattern</i><b>/</b><i>flags</i> 70 71 <b>endif</b> If the input string does not match /<i>pattern</i>/, then match that 72 input string against the patterns between <b>if</b> and <b>endif</b>. The 73 <b>if</b>..<b>endif</b> can nest. 74 75 Note: do not prepend whitespace to patterns inside <b>if</b>..<b>endif</b>. 76 77 This feature is available in Postfix 2.1 and later. 78 79 blank lines and comments 80 Empty lines and whitespace-only lines are ignored, as are lines 81 whose first non-whitespace character is a `#'. 82 83 multi-line text 84 A logical line starts with non-whitespace text. A line that 85 starts with whitespace continues a logical line. 86 87 Each pattern is a perl-like regular expression. The expression delim- 88 iter can be any non-alphanumeric character, except whitespace or char- 89 acters that have special meaning (traditionally the forward slash is 90 used). The regular expression can contain whitespace. 91 92 By default, matching is case-insensitive, and newlines are not treated 93 as special characters. The behavior is controlled by flags, which are 94 toggled by appending one or more of the following characters after the 95 pattern: 96 97 <b>i</b> (default: on) 98 Toggles the case sensitivity flag. By default, matching is case 99 insensitive. 100 101 <b>m</b> (default: off) 102 Toggles the pcre MULTILINE flag. When this flag is on, the <b>^</b> and 103 <b>$</b> metacharacters match immediately after and immediately before 104 a newline character, respectively, in addition to matching at 105 the start and end of the subject string. 106 107 <b>s</b> (default: on) 108 Toggles the pcre DOTALL flag. When this flag is on, the <b>.</b> 109 metacharacter matches the newline character. With Postfix ver- 110 sions prior to 2.0, the flag is off by default, which is incon- 111 venient for multi-line message header matching. 112 113 <b>x</b> (default: off) 114 Toggles the pcre extended flag. When this flag is on, whitespace 115 characters in the pattern (other than in a character class) are 116 ignored. To include a whitespace character as part of the pat- 117 tern, escape it with backslash. 118 119 Note: do not use <b>#</b><i>comment</i> after patterns. 120 121 <b>A</b> (default: off) 122 Toggles the pcre ANCHORED flag. When this flag is on, the pat- 123 tern is forced to be "anchored", that is, it is constrained to 124 match only at the start of the string which is being searched 125 (the "subject string"). This effect can also be achieved by 126 appropriate constructs in the pattern itself. 127 128 <b>E</b> (default: off) 129 Toggles the pcre DOLLAR_ENDONLY flag. When this flag is on, a <b>$</b> 130 metacharacter in the pattern matches only at the end of the sub- 131 ject string. Without this flag, a dollar also matches immedi- 132 ately before the final character if it is a newline character 133 (but not before any other newline characters). This flag is 134 ignored if the pcre MULTILINE flag is set. 135 136 <b>U</b> (default: off) 137 Toggles the pcre UNGREEDY flag. When this flag is on, the pat- 138 tern matching engine inverts the "greediness" of the quantifiers 139 so that they are not greedy by default, but become greedy if 140 followed by "?". This flag can also set by a (?U) modifier 141 within the pattern. 142 143 <b>X</b> (default: off) 144 Toggles the pcre EXTRA flag. When this flag is on, any back- 145 slash in a pattern that is followed by a letter that has no spe- 146 cial meaning causes an error, thus reserving these combinations 147 for future expansion. 148 149 This feature is not supported with PCRE2. 150 151<b><a name="search_order">SEARCH ORDER</a></b> 152 Patterns are applied in the order as specified in the table, until a 153 pattern is found that matches the input string. 154 155 Each pattern is applied to the entire input string. Depending on the 156 application, that string is an entire client hostname, an entire client 157 IP address, or an entire mail address. Thus, no parent domain or par- 158 ent network search is done, and <i>user@domain</i> mail addresses are not bro- 159 ken up into their <i>user</i> and <i>domain</i> constituent parts, nor is <i>user+foo</i> 160 broken up into <i>user</i> and <i>foo</i>. 161 162<b><a name="text_substitution">TEXT SUBSTITUTION</a></b> 163 Substitution of substrings (text that matches patterns inside "()") 164 from the matched expression into the result string is requested with 165 $1, $2, etc.; specify $$ to produce a $ character as output. The 166 macros in the result string may need to be written as ${n} or $(n) if 167 they aren't followed by whitespace. This feature does not support 168 pcre2 substring names. 169 170 Note: since negated patterns (those preceded by <b>!</b>) return a result when 171 the expression does not match, substitutions are not available for 172 negated patterns. 173 174<b><a name="inline_specification">INLINE SPECIFICATION</a></b> 175 The contents of a table may be specified in the table name (Postfix 3.7 176 and later). The basic syntax is: 177 178 <a href="postconf.5.html">main.cf</a>: 179 <i>parameter</i> <b>= .. <a href="pcre_table.5.html">pcre</a>:{ {</b> <i>rule-1</i> <b>}, {</b> <i>rule-2</i> <b>} .. } ..</b> 180 181 <a href="master.5.html">master.cf</a>: 182 <b>.. -o {</b> <i>parameter</i> <b>= .. <a href="pcre_table.5.html">pcre</a>:{ {</b> <i>rule-1</i> <b>}, {</b> <i>rule-2</i> <b>} .. } .. } ..</b> 183 184 Postfix recursively expands any <i>$parametername</i> instances in the above 185 parameter value, ignores whitespace after '{' and before '}', and 186 writes each <i>rule</i> as one text line to an in-memory file: 187 188 in-memory file: 189 rule-1 190 rule-2 191 .. 192 193 Postfix parses the result as if it is a file in /etc/postfix. 194 195<b><a name="inline_specification_caveats">INLINE SPECIFICATION CAVEATS</a></b> 196 <b>o</b> When using <i>$parametername</i> inside an inlined pattern, use 197 \Q<i>$parametername</i>\E to disable metacharacters such as '.' in the 198 <i>$parametername</i> expansion. Otherwise, the pattern may have unex- 199 pected matches. 200 201 <b>o</b> When an inlined rule must contain <b>$</b>, specify <b>$$</b> to keep Postfix 202 from trying to do <i>$name</i> expansion as it evaluates a parameter 203 value. To check an inline configuration, use the "<b>postconf -x</b>" 204 option as shown below: 205 206 <b>o</b> When a <a href="postconf.5.html">main.cf</a> "<i>parametername = value</i>" setting contains 207 an inline <a href="pcre_table.5.html">pcre</a>: table, use the command "<b>postconf -x</b> 208 <i>parametername</i>". Verify that there are no "undefined 209 parameter" warnings, and that the output has the syntax 210 that one would use in a non-inlined Postfix <a href="pcre_table.5.html">pcre</a>: file. 211 212 <b>o</b> When a <a href="master.5.html">master.cf</a> "<b>-o {</b> <i>parametername = value</i> <b>}</b>" override 213 contains an inline <a href="pcre_table.5.html">pcre</a>: table, use the command "<b>postconf</b> 214 <b>-Px '*/*/</b><i>parametername</i><b>'</b> ". Verify that there are no 215 "undefined parameter" warnings, and that the output has 216 the syntax that one would use in a non-inlined Postfix 217 <a href="pcre_table.5.html">pcre</a>: file. 218 219<b><a name="example_smtpd_access_map">EXAMPLE SMTPD ACCESS MAP</a></b> 220 # Protect your outgoing majordomo exploders 221 /^(?!owner-)(.*)-outgoing@(.*)/ 550 Use ${1}@${2} instead 222 223 # Bounce friend@whatever, except when whatever is our domain (you would 224 # be better just bouncing all friend@ mail - this is just an example). 225 /^(friend@(?!my\.domain$).*)$/ 550 Stick this in your pipe $1 226 227 # A multi-line entry. The text is sent as one line. 228 # 229 /^noddy@my\.domain$/ 230 550 This user is a funny one. You really don't want to send mail to 231 them as it only makes their head spin. 232 233<b><a name="example_header_filter_map">EXAMPLE HEADER FILTER MAP</a></b> 234 /^Subject: make money fast/ REJECT 235 /^To: friend@public\.com/ REJECT 236 237<b><a name="example_body_filter_map">EXAMPLE BODY FILTER MAP</a></b> 238 # First skip over base 64 encoded text to save CPU cycles. 239 # Requires PCRE version 3. 240 ~^[[:alnum:]+/]{60,}$~ OK 241 242 # Put your own body patterns here. 243 244<b><a name="see_also">SEE ALSO</a></b> 245 <a href="postmap.1.html">postmap(1)</a>, Postfix lookup table manager 246 <a href="postconf.5.html">postconf(5)</a>, configuration parameters 247 <a href="regexp_table.5.html">regexp_table(5)</a>, format of POSIX regular expression tables 248 249<b><a name="readme_files">README FILES</a></b> 250 <a href="DATABASE_README.html">DATABASE_README</a>, Postfix lookup table overview 251 252<b>AUTHOR(S)</b> 253 The PCRE table lookup code was originally written by: 254 Andrew McNamara 255 andrewm@connect.com.au 256 connect.com.au Pty. Ltd. 257 Level 3, 213 Miller St 258 North Sydney, NSW, Australia 259 260 Adopted and adapted by: 261 Wietse Venema 262 IBM T.J. Watson Research 263 P.O. Box 704 264 Yorktown Heights, NY 10598, USA 265 266 Wietse Venema 267 Google, Inc. 268 111 8th Avenue 269 New York, NY 10011, USA 270 271 PCRE_TABLE(5) 272</pre> </body> </html> 273