* Dmitry Bigunyak via RT (bug-Mail-Box@rt.cpan.org) [091127 11:11]:
Show quoted text> Queue: Mail-Box
> Ticket <URL:
https://rt.cpan.org/Ticket/Display.html?id=52119 >
>
> Ok. I need to make simple thing: create "To" message field. This code
> now doesn't work:
> my $to = 'Простой Тест <simple@test.ru>';
> my $field = Mail::Message::Field::Full->new('To' => $to, charset =>
> 'utf-8', encoding => 'B');
There is a very good reason for this not to work: on various parts in
the "To" field there are different rules about character sets and
how to encode them. Even the rules for one email addresses phrase
and comment components are quite different.
Show quoted text> I know two solutions:
> First.
> my ($ma) = Mail::Address->parse($to);
> my $to_address = Mail::Message::Field::Address->coerce($ma, charset =>
> $charset, encoding => 'B');
> my $field = Mail::Message::Field::Full->new('to' => $to_address);
No, above is not a correct solution: you start with a non-compliant
email address. It's bad behavior of Mail::Address to accept it.
Probably because Mail::Address date from before "MIME" was invented,
and everything was always ASCII.
Show quoted text> Second.
> my $to_address = Mail::Message::Field::Address->new(address =>
> 'simple@test.ru', phrase => "Простой Тест", charset => 'utf-8',
> encoding => 'B');
> my $field = Mail::Message::Field::Full->new('to' => $to_address);
Well, doing encodings right is very difficult. That's why a lot of
people use the non-::Full headers and ignore these encodings (the
end-user sees them not-decoded)
If you have to do above a few times, then simply wrap it in a
function which suites your specific needs.
--
Regards,
MarkOv
------------------------------------------------------------------------
Mark Overmeer MSc MARKOV Solutions
Mark@Overmeer.net solutions@overmeer.net
http://Mark.Overmeer.net http://solutions.overmeer.net