On Thursday 18 August 2016 23:35:10 p...@cpan.org wrote:
> On Thursday 18 August 2016 23:21:28 Ricardo Signes wrote:
> > > If I create Email::MIME object from input string, I would like to
> > > get:
> > > 
> > > 1) Raw (ASCII) string representation of To: field
> > > 
> > > 2) Unicode string representation of To: field
> > > 
> > > 3) List of Email::Address::XS objects which are in To: field
> > > 
> > > 4) List of named groups with Email::Address::XS objects of To:
> > > field
> > > 
> > > For 1) and 2) I can use ->header_raw and ->header_str methods.
> > > For 3) and 4) are needed new method(s). Ideally if caller is
> > > able to get original MIME encoded objects (where in ->phrase
> > > part of address object is still MIME encoded) and also if
> > > objects strings are Unicode.
> > 
> > As you say, 1 and 2 are dealt with.  For 3 or 4, you want to have
> > an object in the header slot, rather than a string.  Once you've
> > done that, you use its methods.  If the object's To field stores a
> > 
> > string, you "upgrade" it with something like:
> >   $email->header(To => mailbox_headers_from( $email->header('To')
> >   );
> > 
> > ...and it seems like one would quickly amass some sort of routine
> > 
> > like:
> >   upgrade_headers($email);
> > 
> > ...that would upgrade all the headers it knows about.
> 
> Can you describe (or write code) how you imagine that I get header
> "Original-Cc" in form of addresses in list of named groups from email
> which is stored in string scalar? I'm not sure that I understand how
> you mean it...

I still do not know how you though about it, but I understand it as 
unusable API...

Currently with Email::Address::XS I can achieve it by:

 1  use Email::MIME;
 2  use Email::Address::XS qw(parse_email_groups);
 3  my $str = join "", <>;
 4  my $email = Email::MIME->new($str);
 5  my @groups = parse_email_groups($email->header_raw("Original-Cc"));
 6  foreach (0 .. int($#groups / 2)) {
 7      $groups[2 * $_] = mime_decode($groups[2 * $_]);
 8      next unless defined $groups[2 * $_ + 1];
 9      foreach (@{$groups[2 * $_ + 1]}) {
10          $_->phrase(mime_decode($_->phrase));
11          $_->comment(mime_decode($_->comment));
12      }
13  }
14  # @group now contains:
15  # ('group1' => [ $obj1, $obj2 ], 'group2' => [ $obj3 ])

(where mime_decode is equivalent to Encode::decode("MIME-Header", ...))

And for easier usage I need to have one Email::MIME method which will do 
everything in lines 5-13. Method should get header name (in that case it 
is Original-CC) and returns MIME decoded final @groups list.

Email::MIME is module which automatically do any MIME encoding/decoding 
without user interaction, so that decoding must be done automatically 
and without such "upgrade" function.

I do not want to do that decode manually or call some "upgrade" function 
which you propose... Reading one email header should not change internal 
email structure.

Also it must be possible to get either named groups from Original-Cc 
header or only list of addresses. And I think with your proposal API it 
is not possible. You would need to call some "downgrade" function and 
then "upgrade" it to another object or so...

This can be elegantly solved by my proposal, when there will be two 
additional Email::MIME method. First header_addr which just returns list 
of addresses objects and second header_grps which returns named group 
with addresses objects (that one is in lines 5-13).

Reply via email to