Postfix: Can I insert a custom header to incoming mail?

Paul Hartman <[email protected]> Thu, 7 Jul 2011 16:50:45 -0500
Newsgroups gmane.linux.gentoo.server
Message-ID <CAEH5T2PXj00d3SEO=CuzRkU=WDK8fQWrj+1ObVd3y5k79N7=MQ@mail.gmail.com>
Hi,

The background:

Long-time Gentoo user, newbie to mail server setup. I've got a Gentoo
server (~amd64) and I set up Postfix and Dovecot following this guide:
http://en.gentoo-wiki.com/wiki/Mail_server_using_Postfix_and_Dovecot

I'm using postfix-2.8.4 and dovecot-2.0.13

So far, everything works as advertised. I've added a domain, created
accounts, additionally I've set up sqlgrey, DKIM signing and SPF,
sender-ID and all of that good stuff. My sent mail goes out
successfully and incoming mail gets delivered to the virtual mailboxes
and everything's working properly as far as I can tell.

The problem:

My existing (hosted) mail server has a catch-all account so any mail
to the domains I own goes to me. I believe they use qmail. The
delivered-to header on the messages retain the address of the original
message, not the catch-all address to which it is forwarded. Why do I
care? I basically use a different address for every site or person I
interact with and then sort them out into folders based on the
delivered-to address. (For example if I bought something from Sears I
would use [email protected] as my email address).

With postfix, it doesn't work that way. I set up a catchall, but the
delivered-to: header becomes [email protected] for all of the
catchall mail. I can't change my rules to use use the To: address
because it is not reliable (BCC, spam...).

The idea:

Assuming I can't do anything about how Postfix handles the
Delivered-To header, I'd like to insert a new header entry
(X-Originally-To: or something like that) into incoming mail before it
hits the catchall forward, so I can know to whom the email was
originally addressed... but i don't really know where to begin.

The question:

Are there any postfix gurus out there who can point me in the right
direction? Thanks in advance for any tips or advice (or if you want to
tell me that I'm doing it all wrong).

Thanks,
Paul