The error you're encountering typically occurs when Postfix is compiled without PCRE (Perl Compatible Regular Expressions) support. Many Linux distributions don't include PCRE support in their default Postfix packages due to licensing considerations.
First, check if your Postfix installation supports PCRE:
postconf -m | grep pcre
If this command returns no output, your Postfix lacks PCRE support.
The most robust solution is to recompile Postfix with PCRE support:
# Install dependencies
sudo apt-get install libpcre3-dev
# Download Postfix source
wget http://ftp.debian.org/debian/pool/main/p/postfix/postfix_3.4.14.orig.tar.gz
tar xzf postfix_3.4.14.orig.tar.gz
cd postfix-3.4.14
# Compile with PCRE support
make makefiles CCARGS="-DHAS_PCRE -I/usr/include/pcre" AUXLIBS="-lpcre"
# Build and install
make
sudo make install
For immediate workaround, modify your header_checks to use basic regexp instead of PCRE:
# Change this in main.cf
header_checks = regexp:/etc/postfix/header_checks
# Update your header_checks file format:
/^Received:/ IGNORE
/^X-Originating-IP:/ IGNORE
/^X-Mailer:/ IGNORE
/Message-Id:[[:space:]]+<(.*)@www\.mainserver\.com>/ REPLACE Message-Id: <\1@www.domain.com>
When switching from PCRE to regexp:
- Replace \s with [[:space:]] for whitespace
- Use \1 instead of $1 for backreferences
- Escape dots with \.
- No support for non-greedy quantifiers (*?)
After making changes, always test:
sudo postfix check
sudo postfix reload
postmap /etc/postfix/header_checks
On Ubuntu, you can often find Postfix packages with PCRE support:
sudo apt-get install postfix-pcre
Then reconfigure Postfix to use the PCRE version.
When implementing header checks in Postfix, you might encounter the frustrating "unsupported dictionary type: pcre"
error. This typically occurs when your Postfix installation wasn't compiled with PCRE (Perl Compatible Regular Expressions) support.
First, check if your Postfix was built with PCRE support:
postconf -m | grep pcre
If this command returns nothing, you'll need to either:
- Recompile Postfix with PCRE support
- Use a different regex engine
For Ubuntu 18.04, the quickest solution is to change your header_checks configuration to use the built-in regex engine instead of PCRE:
# In main.cf
header_checks = regexp:/etc/postfix/header_checks
If you must use PCRE, you'll need to install the PCRE development libraries and recompile Postfix:
sudo apt-get install libpcre3-dev
sudo apt-get build-dep postfix
sudo apt-get source postfix
cd postfix-*
sudo make tidy
sudo make makefiles CCARGS="-DHAS_PCRE -I/usr/include/pcre" \
AUXLIBS="-L/usr/lib/x86_64-linux-gnu -lpcre"
sudo make
sudo make install
After making changes, always test your configuration:
postmap -q "Received: by mail.example.com" regexp:/etc/postfix/header_checks
Here's a properly formatted header_checks file that works with regexp type:
/^Received:/ IGNORE
/^X-Originating-IP:/ IGNORE
/^X-Mailer:/ IGNORE
/Message-Id:\s+<(.*?)@www\.mainserver\.com>/ REPLACE Message-Id: <$1@www.domain.com>
/X-Mailer-LID:/ IGNORE
/^MIME-Version:/i PREPEND Precedence: bulk
/X-Mailer-RecptId:/ IGNORE
/X-Mailer-SID:/ IGNORE
/X-Mailer-Sent-By:/ IGNORE
/List-Unsubscribe:/ IGNORE
Remember that header checks impact performance. For high-volume servers, consider:
- Using simpler regex patterns
- Minimizing the number of rules
- Using hash maps for static replacements