Rewrite From header in postfix

The essential steps
Create /etc/postfix/header_checks (discussed below) then run these commands
cd /etc/postfix
postconf -e 'smtp_header_checks = regexp:/etc/postfix/header_checks'
/etc/init.d/postfix reload
Developing the header_checks file
Line format
For present purposes, each effective line of the header_checks file is of the form
/pattern/ REPLACE text...
The pattern
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".
The text
display-name needs double quotes.
angle-addr needs the < and > characters.
Development techniques
To find out what's after the "From:":
If the regex matches, the original headers can be displayed by
grep -o 'replace: header .*$' /var/log/mail.info
Keep the original header text in the re-written header by using back-substitution in header_checks like (replace ):
/^From:[[:space:]]+(.*)/ REPLACE From: ">${1}<"

Reference
Postfix Architecture Overview: http://www.postfix.org/OVERVIEW.html
Postfix Address Rewriting: http://www.postfix.org/ADDRESS_REWRITING_README.html
Postfix Lookup Table Overview: http://www.postfix.org/DATABASE_README.html
REGEXP_TABLE man page: http://www.postfix.org/regexp_table.5.html
header_checks man page: http://www.postfix.org/header_checks.5.html

Trackbacks

Trackback specific URI for this entry

This link is not meant to be clicked. It contains the trackback URI for this entry. You can use this URI to send ping- & trackbacks from your own blog to this entry. To copy the link, right click and select "Copy Shortcut" in Internet Explorer or "Copy Link Location" in Mozilla.

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment

You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.