Hi!

Now after long discussion which started 3 months ago and not finished 
yet about Email::Address::XS support in Email::MIME I started to writing 
code... I want to have something working, usable and not never-ending 
discussion.

I implemented new module Email::Address::List::XS which provides object 
representation of list of Email::Address::XS objects with parse() and 
format() methods.

Next I added support for Email::Address::List::XS objects into 
Email::Simple and Email::MIME modules.

All source code is available at:
https://github.com/pali/Email-Address-XS/tree/list
https://github.com/rjbs/Email-Simple/compare/master...pali:master
https://github.com/rjbs/Email-MIME/compare/master...pali:master

Example of usage:

my $email = Email::Simple->create(
        header => [
                From => Email::Address::XS->new('Name' => 'user@host'),
                To => '"My Name" <us...@example.com>',
        ],
);
my $addr1 = Email::Address::XS->new(undef, 'addre...@example.com');
my $addr2 = Email::Address::XS->new(undef, 'addre...@example.com');
my $addrlist = Email::Address::List::XS->new($addr1, $addr2);
$email->header_raw_set(Cc => $addrlist);

Email::Simple can accept any object which has format() method. Both 
modules Email::Address::List::XS and Email::Address::XS provides them.

Email::Simple contains new method header_addrlist_raw() which returns 
Email::Address::List::XS object for specified header (it does not matter 
if header value was passed as object or as string).

my $addrlist_to = $email->header_addrlist_raw('To');
my $phrase = $addrlist_to->first_address()->phrase();

(Now $phrase contains string 'My Name').

Next situation with Email::MIME is a bit complicated as module 
Email::MIME is responsible for doing MIME encoding/decoding. And because 
$address needs to be specially MIME encoded and decoded it is not 
possible to accept arbitrary object with format() method as in 
Email::Simple module. Email::MIME needs to know how to each object 
correctly encode and decode...

So for Email::MIME I added object support only for Email::Address::XS 
and Email::Address::List::XS modules. I do not expect that there will be 
needed support for anything else...

Usage is same as for Email::Simple, just in create() method is used 
"header_str" argument and for retrieving Email::Address::List::XS object 
is used header_addrlist() method. Basically same as work with strings 
(raw methods have _raw suffix). Passing objects to _raw methods just 
cause that objects will not be MIME encoded.

Look at code and tell me if this Email::Address::List::XS module is 
usable and if patches for Email::Simple and Email::MIME are acceptable. 
If yes, I can clean up it, write some tests and release whole 
Email::Address::XS module to CPAN...

Reply via email to