Wednesday, August 29, 2007

Multiple Recipient Delimiters in Postfix

err.pngSome time ago I enabled recipient delimiters (e.g. user+foo@host.tld) as a convenient way to know if shady web forms are contributing to my spam folder. The idea is that when House Depot requires me to have an account before I can see if they have loose screws in stock locally, I can sign up with garrison+housedepot@codefix.net instead of my usual e-mail. With recipient delimiters enabled, postfix will try to deliver any incoming mail to garrison+housedepot but when it finds no such user, it will try garrison and I get my mail. The problem arises when I discover that House Depot’s broken web form rejects any e-mail addresses with “+” in the user name as invalid. I’m already using garrison+foo style addresses elsewhere so I don’t want to change the recipient delimiter, but neither do I trust my real address to a company that can’t even create a proper web form.


Postfix allows only one recipient delimiter, but address rewriting can mimic multiple recipient delimiters; I chose to use regular expression tables in my aliases database. I’m most comfortable with Perl, so I chose to install the Perl compatible regular expression package, on Debian/Ubuntu this is done with:

sudo aptitude install postfix-pcre

Next I created a file named aliases-pcre with the following content:

/^garrison\./ garrison

Finally I updated main.conf with these lines:

alias_database = hash:/etc/postfix/aliases
alias_maps = hash:/etc/postfix/aliases, pcre:/etc/postfix/aliases-pcre


Now I can enjoy e-mail addresses like garrison+housedepot@codefix.net or garrison.housedepot@codefix.net without needing to keep track of each alias. If I get spam addressed to that address, I can easily block it and complain loudly to House Depot’s customer service in India.