On May 15, 3:49am, Rav Ahuja wrote:
Subject: extracting the TO username
I am trying to write a recipe that gets the USERNAME from the "To" field (or
Received for) of the incoming message, passes it to a program which accesses
a database and returns an address to procmail to forward the email.
That is, if the incoming email is meant for abc(_at_)mydomain(_dot_)com I
recipe to be able to extract "abc" (what I referred to as USERNAME ealier)
and pass it as a parameter to the program. My program then returns
So something like this should do the trick:
! `myscript "$USERNAME"`
But I can't figure out how to extract the $USERNAME before passing it to the
database program. Any hints on how to do this would be greatly appreciated.
Perl has a module for parsing e-mail addresses. It's called
MailTools, available at:
Here's a simple example program, the Address tool:
my ($full_address) = join (" ", @ARGV);
print "full address: ", $full_address, "\n";
my @addrs = Mail::Address->parse($full_address);
foreach my $addr (@addrs)
print "address: ", $addr->address, " user: ", $addr->user, "\n";
And an a one line invocation:
% perl mailaddr.pl Joe User '<joe(_at_)sixpack(_dot_)com>'
full address: Joe User <joe(_at_)sixpack(_dot_)com>
address: joe(_at_)sixpack(_dot_)com user: joe