Re: Email::Address hangs

[email protected] (Joseph Crotty) Fri, 2 Mar 2012 22:06:14 -0700
Newsgroups perl.pep
Message-ID <CAEkpLoJ+06dURgd4UivJ_ARXvhmG7vEvH7vfL9rOMfJNFYADuQ@mail.gmail.com>
Attached is a demo script and email that show the problem.  After the call
to Email::Address->parse($header_to); the code hangs.

Joe

On Sun, Jan 29, 2012 at 7:25 AM, Ricardo Signes
<[email protected]>wrote:

> * Joseph Crotty <[email protected]> [2012-01-28T18:20:28]
> > When calling parse on a large To: header field it hangs. Large in this
> case
> > is 600 emails some with comments. I put in a length check on the To:
> field
> > to avoid this. Are there any other ways to parse long To:field fields
> > successfully?
>
> You could provide an anonymized version of this header, so I can look at
> what
> might be happening?
>
> Also, consider trying Mail::Address.
>
> --
> rjbs
>
1317124844913-619.rpco-jcrottyMB (application/octet-stream, 56.4 KB) - not displayed
demo.pl (application/octet-stream, 660 B)
#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

use Email::Address;
use File::Slurp;
use MIME::Parser;

my $email = '1317124844913-619.rpco-jcrottyMB';

my $msg = read_file( $email, binmode => ':utf8' );
my $parser = new MIME::Parser;
$parser->output_under('/tmp');
my $entity;

eval { $entity = $parser->parse_data($msg); };
if ($@) {
    print "MIME::Parser error: $@";
    exit;
}
elsif ( $parser->last_error ) {
    print( "MIME::Parser warning: " . $parser->last_error );
    exit;
}

my $header = $entity->head();
my $header_to = $header->get("to");

print Dumper($header_to);
Email::Address->parse($header_to);
print Dumper('done');
exit;