This page explains how to use postfix header_checks to re-write "From:" headers, specifically to adjust the display name.
It was developed and tested on a Debian 6 Squeeze system running postfix 2.7.1 using POSIX regular expressions.
The terms used for address components on this page are taken from RFC2822 (http://tools.ietf.org/html/rfc2822#section-3.4). Using example address
"Mr Foo" <foo@example.com>
"Mr Foo"
is the display-name<foo@example.com>
is angle-addrCreate /etc/postfix/header_checks (discussed below) then run these commands
cd /etc/postfix
postmap header_checks
postconf -e 'smtp_header_checks = regexp:/etc/postfix/header_checks'
/etc/init.d/postfix reload
For present purposes, each effective line of the header_checks file is of the form
/pattern/ REPLACE text...
The /pattern/ is a POSIX regular expression matching the "FROM:" header. So it always begins with
/^From:
The pattern should always be anchored to the start of the line using ^. This ensures no false positives (such as matching "From:" in some other header such as the subject) and gives better postfix performance (postfix does not have to scan the whole of each header looking for the match).
The rest of the pattern depends on local requirements – what you want to match.
Any whitespace in the pattern should be represented by [[:space:]]. This avoids warnings from postmap such as "record is in "key: value" format; is this an alias file?" and "duplicate entry".
To find out what's after the "From:":
grep -o 'replace: header .*$' /var/log/mail.info
/^From:[[:space:]]+(.*)/ REPLACE From: ">${1}<" <email_address>
There are few HOWTO pages on the Internet about this topic. The ones found most useful were:
Postfix sender address rewriting, changing mails “from” field in header on relay server (but beware < and > represented as "<" etc.): http://tech.gate.io/postfix-sender-address-rewriting-changing-mails-from-field-in-header-on-relay-server/
Missing full sender name in your sent email with postfix?: http://www.ifusio.com/blog/missing-full-sender-name-in-your-sent-email-with-postfix
Postfix Lookup Table Overview: http://www.postfix.org/DATABASE_README.html
REGEXP_TABLE man page: http://www.postfix.org/regexp_table.5.html