Email Anonymization

I’m working on an email anonymization feature for my rails app (kind of like craigslist). I’ve configured postfix to pipe all emails addressed to user-* (i.e., where 1234 is the user id in the database) into rails via the mailer’s receive method.

Now, the idea is to first check that the sender’s email address is in the database (if not: return), then anonymize/mask it; so if is the sender and user 24 has that email address, change the sender’s address to Then, parse the recipient’s email address and unmask it (change to user 23’s real email address) so it can be delivered properly.

The thing is, I’m not an expert at email/email headers. What’s the best way to go about this. Directly alter the message’s FROM address and TO address and deliver it? Create a new email in rails, set FROM to an address owned by the server and the REPLY-TO header to the sender’s masked address and the TO header to the recipient’s unmasked address? How do I handle multiple recipients? What’s the best way to handle emails directed to users that don’t exist?

Any help would be appreciated.