1#++ 2# NAME 3# pcre_table 5 4# SUMMARY 5# format of Postfix PCRE tables 6# SYNOPSIS 7# \fBpostmap -q "\fIstring\fB" pcre:/etc/postfix/\fIfilename\fR 8# 9# \fBpostmap -q - pcre:/etc/postfix/\fIfilename\fB <\fIinputfile\fR 10# 11# \fBpostmap -hmq - pcre:/etc/postfix/\fIfilename\fB <\fIinputfile\fR 12# 13# \fBpostmap -bmq - pcre:/etc/postfix/\fIfilename\fB <\fIinputfile\fR 14# DESCRIPTION 15# The Postfix mail system uses optional tables for address 16# rewriting, mail routing, or access control. These tables 17# are usually in \fBdbm\fR or \fBdb\fR format. 18# 19# Alternatively, lookup tables can be specified in Perl Compatible 20# Regular Expression form. In this case, each input is compared 21# against a list of patterns. When a match is found, the 22# corresponding result is returned and the search is terminated. 23# 24# To find out what types of lookup tables your Postfix system 25# supports use the "\fBpostconf -m\fR" command. 26# 27# To test lookup tables, use the "\fBpostmap -q\fR" command 28# as described in the SYNOPSIS above. Use "\fBpostmap -hmq 29# -\fR <\fIfile\fR" for header_checks(5) patterns, and 30# "\fBpostmap -bmq -\fR <\fIfile\fR" for body_checks(5) 31# (Postfix 2.6 and later). 32# 33# This driver can be built with the pcre2 library (Postfix 34# 3.7 and later), or with the legacy pcre library (all Postfix 35# versions). 36# COMPATIBILITY 37# .ad 38# .fi 39# With Postfix version 2.2 and earlier specify "\fBpostmap 40# -fq\fR" to query a table that contains case sensitive 41# patterns. Patterns are case insensitive by default. 42# TABLE FORMAT 43# .ad 44# .fi 45# The general form of a PCRE table is: 46# .IP "\fB/\fIpattern\fB/\fIflags result\fR" 47# When \fIpattern\fR matches the input string, use 48# the corresponding \fIresult\fR value. 49# .IP "\fB!/\fIpattern\fB/\fIflags result\fR" 50# When \fIpattern\fR does \fBnot\fR match the input string, use 51# the corresponding \fIresult\fR value. 52# .IP "\fBif /\fIpattern\fB/\fIflags\fR" 53# .IP "\fBendif\fR" 54# If the input string matches /\fIpattern\fR/, then match that 55# input string against the patterns between \fBif\fR and 56# \fBendif\fR. The \fBif\fR..\fBendif\fR can nest. 57# .sp 58# Note: do not prepend whitespace to patterns inside 59# \fBif\fR..\fBendif\fR. 60# .sp 61# This feature is available in Postfix 2.1 and later. 62# .IP "\fBif !/\fIpattern\fB/\fIflags\fR" 63# .IP "\fBendif\fR" 64# If the input string does not match /\fIpattern\fR/, then 65# match that input string against the patterns between \fBif\fR 66# and \fBendif\fR. The \fBif\fR..\fBendif\fR can nest. 67# .sp 68# Note: do not prepend whitespace to patterns inside 69# \fBif\fR..\fBendif\fR. 70# .sp 71# This feature is available in Postfix 2.1 and later. 72# .IP "blank lines and comments" 73# Empty lines and whitespace-only lines are ignored, as 74# are lines whose first non-whitespace character is a `#'. 75# .IP "multi-line text" 76# A logical line starts with non-whitespace text. A line that 77# starts with whitespace continues a logical line. 78# .PP 79# Each pattern is a perl-like regular expression. The expression 80# delimiter can be any non-alphanumeric character, except 81# whitespace or characters 82# that have special meaning (traditionally the forward slash is used). 83# The regular expression can contain whitespace. 84# 85# By default, matching is case-insensitive, and newlines are not 86# treated as special characters. The behavior is controlled by flags, 87# which are toggled by appending one or more of the following 88# characters after the pattern: 89# .IP "\fBi\fR (default: on)" 90# Toggles the case sensitivity flag. By default, matching is case 91# insensitive. 92# .IP "\fBm\fR (default: off)" 93# Toggles the pcre MULTILINE flag. When this flag is on, the \fB^\fR 94# and \fB$\fR metacharacters match immediately after and immediately 95# before a newline character, respectively, in addition to 96# matching at the start and end of the subject string. 97# .IP "\fBs\fR (default: on)" 98# Toggles the pcre DOTALL flag. When this flag is on, the \fB.\fR 99# metacharacter matches the newline character. With 100# Postfix versions prior to 2.0, the flag is off by 101# default, which is inconvenient for multi-line message header 102# matching. 103# .IP "\fBx\fR (default: off)" 104# Toggles the pcre extended flag. When this flag is on, whitespace 105# characters in the pattern (other than in a character class) 106# are ignored. To include a whitespace character as part of 107# the pattern, escape it with backslash. 108# .sp 109# Note: do not use \fB#\fIcomment\fR after patterns. 110# .IP "\fBA\fR (default: off)" 111# Toggles the pcre ANCHORED flag. When this flag is on, 112# the pattern is forced to be "anchored", that is, it is 113# constrained to match only at the start of the string which 114# is being searched (the "subject string"). This effect can 115# also be achieved by appropriate constructs in the pattern 116# itself. 117# .IP "\fBE\fR (default: off)" 118# Toggles the pcre DOLLAR_ENDONLY flag. When this flag is on, 119# a \fB$\fR metacharacter in the pattern matches only at the 120# end of the subject string. Without this flag, a dollar also 121# matches immediately before the final character if it is a 122# newline character (but not before any other newline 123# characters). This flag is ignored if the pcre MULTILINE 124# flag is set. 125# .IP "\fBU\fR (default: off)" 126# Toggles the pcre UNGREEDY flag. When this flag is on, 127# the pattern matching engine inverts the "greediness" of 128# the quantifiers so that they are not greedy by default, 129# but become greedy if followed by "?". This flag can also 130# set by a (?U) modifier within the pattern. 131# .IP "\fBX\fR (default: off)" 132# Toggles the pcre EXTRA flag. 133# When this flag is on, any backslash in a pattern that is 134# followed by a letter that has no special meaning causes an 135# error, thus reserving these combinations for future expansion. 136# 137# This feature is not supported with PCRE2. 138# SEARCH ORDER 139# .ad 140# .fi 141# Patterns are applied in the order as specified in the table, until a 142# pattern is found that matches the input string. 143# 144# Each pattern is applied to the entire input string. 145# Depending on the application, that string is an entire client 146# hostname, an entire client IP address, or an entire mail address. 147# Thus, no parent domain or parent network search is done, and 148# \fIuser@domain\fR mail addresses are not broken up into their 149# \fIuser\fR and \fIdomain\fR constituent parts, nor is \fIuser+foo\fR 150# broken up into \fIuser\fR and \fIfoo\fR. 151# TEXT SUBSTITUTION 152# .ad 153# .fi 154# Substitution of substrings (text that matches patterns 155# inside "()") from the matched expression into the result 156# string is requested with $1, $2, etc.; specify $$ to produce 157# a $ character as output. 158# The macros in the result string may need to be written as 159# ${n} or $(n) if they aren't followed by whitespace. 160# This feature does not support pcre2 substring names. 161# 162# Note: since negated patterns (those preceded by \fB!\fR) return a 163# result when the expression does not match, substitutions are not 164# available for negated patterns. 165# INLINE SPECIFICATION 166# .ad 167# .fi 168# The contents of a table may be specified in the table name 169# (Postfix 3.7 and later). 170# The basic syntax is: 171# 172# .nf 173# main.cf: 174# \fIparameter\fR \fB= .. pcre:{ { \fIrule-1\fB }, { \fIrule-2\fB } .. } ..\fR 175# 176# master.cf: 177# \fB.. -o { \fIparameter\fR \fB= .. pcre:{ { \fIrule-1\fB }, { \fIrule-2\fB } .. } .. } ..\fR 178# .fi 179# 180# Postfix ignores whitespace after '{' and before '}', and 181# writes each \fIrule\fR as one text line to an in-memory 182# file: 183# 184# .nf 185# in-memory file: 186# rule-1 187# rule-2 188# .. 189# .fi 190# 191# Postfix parses the result as if it is a file in /etc/postfix. 192# 193# Note: if a rule contains \fB$\fR, specify \fB$$\fR to keep 194# Postfix from trying to do \fI$name\fR expansion as it 195# evaluates a parameter value. 196# EXAMPLE SMTPD ACCESS MAP 197# # Protect your outgoing majordomo exploders 198# /^(?!owner-)(.*)-outgoing@(.*)/ 550 Use ${1}@${2} instead 199# 200# # Bounce friend@whatever, except when whatever is our domain (you would 201# # be better just bouncing all friend@ mail - this is just an example). 202# /^(friend@(?!my\\.domain$).*)$/ 550 Stick this in your pipe $1 203# 204# # A multi-line entry. The text is sent as one line. 205# # 206# /^noddy@my\\.domain$/ 207# \ 550 This user is a funny one. You really don't want to send mail to 208# \ them as it only makes their head spin. 209# EXAMPLE HEADER FILTER MAP 210# /^Subject: make money fast/ REJECT 211# /^To: friend@public\\.com/ REJECT 212# EXAMPLE BODY FILTER MAP 213# # First skip over base 64 encoded text to save CPU cycles. 214# # Requires PCRE version 3. 215# ~^[[:alnum:]+/]{60,}$~ OK 216# 217# # Put your own body patterns here. 218# SEE ALSO 219# postmap(1), Postfix lookup table manager 220# postconf(5), configuration parameters 221# regexp_table(5), format of POSIX regular expression tables 222# README FILES 223# .ad 224# .fi 225# Use "\fBpostconf readme_directory\fR" or 226# "\fBpostconf html_directory\fR" to locate this information. 227# .na 228# .nf 229# DATABASE_README, Postfix lookup table overview 230# AUTHOR(S) 231# The PCRE table lookup code was originally written by: 232# Andrew McNamara 233# andrewm@connect.com.au 234# connect.com.au Pty. Ltd. 235# Level 3, 213 Miller St 236# North Sydney, NSW, Australia 237# 238# Adopted and adapted by: 239# Wietse Venema 240# IBM T.J. Watson Research 241# P.O. Box 704 242# Yorktown Heights, NY 10598, USA 243# 244# Wietse Venema 245# Google, Inc. 246# 111 8th Avenue 247# New York, NY 10011, USA 248#-- 249