Re: MailBox Question re parsing From, To, CC addresses
"David A. Golden" <[email protected]> Sun, 19 Sep 2004 17:40:49 -0400
| Newsgroups | gmane.comp.lang.perl.modules.mail-box |
|---|---|
| Message-ID | <[email protected]> |
Ed,
I think you're overcomplicating by using "$msg->head->get('from')" which
is asking for the raw fields. Look in Mail::Message for the "from"
method, which returns a list of addresses as nice Mail::Address objects,
already parsed.
I.e.:
my @from = $msg->from();
for my $addr (@from) {
print "Phrase: ", $addr->phrase(), "\n";
print "Address: ", $addr->address(), "\n";
}
Best of luck,
David Golden
Ed Greenberg wrote:
> Hi folks,
>
> When I get an address, as in:
>
> my @from = $msg->head->get('from');
>
> and then $from = $from[0];
>
> I find that $from contains something like:
> First Last <[email protected]>
>
> I need to parse out the various pieces of this. I could do it myself,
> but I can't believe that there isn't a way to do it using MailBox methods.
>
> When I try this, I came up with:
>
> my $addr = Mail::Message::Field::Address->parse($from);
> print $addr->address,$/;
>
> but I get errors like:
> ERROR: Cannot coerce a Mail::Message::Field::Unstructured into a
> Mail::Message:Field::Address
>
> So I need to get a more structured object back, rather than a string.
>
> What's the method that will return To, From, and Cc addresses as objects
> suitable for parsing?
>
> Or am I going about this all wrong?
>
> Thanks,
> </edg>