Hi Peter, I have written a simple email address capture program, without using any Mail:* modules. Provided that the Emails do not have the "From: " line in the subjects, the following should work fine.

#!C:/Perl/bin/Perl.exe -w use strict; use Data::Dumper; my %MailList; # A list of all seen addresses. # This hash is setup in step 1 in the # previous post. # Parse the mail box while (<DATA>) { next unless /^From:\s/; # ignore all other lines chomp; # except the from line # assume that email addresses are separated # by the ',' character. my @emails = split /,\s*/, substr($_, 6); # build a hash from the email address list my %emails = map { s/\s+$//g; # remove tailing spaces my ($name, $address); if (/>$/) { # look for < ... > ($name, $address) = /^(.*)\s<(.*)>$/; } else { $name = $address = $_; } $address => $name } @emails; # inspect captured email details # print Dumper(\%emails); # check if the email address(es) are already seen foreach (keys %emails) { if (! exists $MailList{$_}) { # ok, we haven't seen this Email address yet $MailList{$_} = $emails{$_}; } } } print Data::Dumper->Dump([\%MailList], ['MailList']); __DATA__ From: Roger <roger@somewhere.com>, Roger 2 <roger2@nowhere.com> To: Peter R <peterr@us.com> Subject: Hello Hello Peter, this from address has two addresses From: roger3@somewhere.com To: Peter R <peterr@us.com> Subject: Hello Hello Peter, this from address has no full name From: roger3@somewhere.com To: Peter R <peterr@us.com> Subject: Hello Hello Peter, has already seen this from address
And the output is
$MailList = { 'roger2@nowhere.com' => 'Roger 2', 'roger3@somewhere.com' => 'roger3@somewhere.com', 'roger@somewhere.com' => 'Roger' };
The code is able to handle Email address in the forms of:
Full Name <email.address@somewhere.com> Email.Address@somewhere.com
You can tweak it a bit if the format of the Mail Addresses are different, or have a address separator other than ','. Oh yes, and put it in a subroutine and add more error checking for a good coding practise.

Update: I agree that Mail::Address module is much more capable than my simpler version. And I agree that using Mail::Box is really nice and easy. But Peter was having plenty of trouble to make them work, so I posted an interim solution to help Peter to get the things going at the mean time.

In reply to Re: Parsing Pegasus email boxes by Roger
in thread Parsing Pegasus email boxes by peterr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.