Procmail Recipe - One Email Address, Multiple users

A while back, I switched ISPs and lost the multiple email addresses that the old ISP provided. With the new ISP, my wife and I were restricted to sharing a single public email address. With fetchmail, I could retrieve our email from my ISP's POP3 server and store it in our lan server for on-demand "offline" reading, but with one email address, either my wife and I had to read each other's mail, or one of us got no mail at all.

I fixed this little problem with the judicious use of a procmail recipe that uses a feature of email addresses to seperate mail destined for my wife from mail destined for me. You see, although email addresses are usually expressed in the form of

userid@host.domain

there is an alternate form that's a bit more readable:

John Q Public <userid@host.domain>

The leading plaintext name (called a 'nickname') is ignored by the mail agents, but is treated as part of the email address for the purposes of data entry and display.

This means that

Her <us@ourisp.ca>

and

Him <us@ourisp.ca>

are delivered to the same email address (us@ourisp.ca), but carry slightly different (and testable) values in the email To: field.

This difference permitted me to write a procmail recipe that detected a difference in the nickname and redirect any mail to "Her" into my wife's local mail spool, while directing mail to "Him" into my local mail spool. Additionally, mail addressed to "Him and Her" or "Her and Him" could be duplicated into each of our mail spools.

The procmail recipe that did all this looked like...


# part of /etc/procmailrc - enable procmail to use this
#
#-----------------------------------------------------------#
# If the email was addressed to our public internet address
# Redistribute it to the local mailboxes based on the
# To: personal name (bypass this step if we've already
# preprocessed this piece of mail)
#-----------------------------------------------------------#
:0
* ^TOus@ourisp.ca
* ! ^X-Loop: mail@homelan
{
# add a unique value to the header to prevent email looping
:0fhw
| formail -A "X-Loop: mail@homelan"
# If the To: line says "Him and Her"
# or "Her and Him", deliver to both
:0
* ^TOhim
* ^TOher
! heracct,hisacct
# If the To: line says "Her", deliver it to her
:0
* ^TOher
! heracct
# If the To: line says "Him", deliver it to him
:0
* ^TOhim
! hisacct
}
#
# End of snippet of /etc/procmailrc file

Of course, I could have added as many users as I wanted nicknames to this, and each user would (ultimately) only get the email addressed to them.

Articles: