Show quoted text> > 1) Do I have to write Encode::_utf8_on($to_name) and
Encode::_utf8_on
Show quoted text> > ($text) or not? From documentation I understand that it should work
> > correctly with PERL encoding.
>
> That's not the right was. This way, you force Perl to treat the
string
Show quoted text> as being an utf-8 encoded string. However, it is either already is an
> utf-8 string or it is a latin-2(?) encoded string. (Can't see that
from
Show quoted text> the bug-report)
>
> When your file is utf-8, then your Perl program should start with
> use utf8;
> and everything is ok. Or you should say
> use Encode;
> my $x = decode 'latin2', $bytes;
>
> Internally, Perl uses "latin1" and "UTF8" (not real utf-8). If you
> want to do things right, you must encode/decode text on all entrance
and
Show quoted text> exit points of your program. Either with "encode/decode" or like
this:
Show quoted text> open IN, '<:encoding(latin2)', $fn or die;
I'm writing code in utf-8 console and don't use pragma utf8 because I
don't need UTF-8 source code, only scalar value.
So, the scalar
my $to_name = 'Тестовый Ящик';
perl stores in his internal UTF8 encoding. And when I write
Encode::_utf8_on($to_name) I tell perl that this is real well formated
utf-8 string.
To create 'To' header field I write
my $to_address = Mail::Message::Field::Address->new(
address => 'test@mailbox.ru',
phrase => $to_name,
charset => 'utf-8',
encoding => 'B',
);
I set charset to 'utf-8' to tell that phrase in utf-8 encoding. And
here everything is right.
To create utf-8 message body I've found another way
my $text = "тестовая строка"; # scalar in internal UTF8 perl encoding
my $body = Mail::Message::Body->new(
data => $text,
mime_type => 'text/plain',
charset => 'utf-8', # don't understand why not 'PERL'
);
$body = $body->encoded;
Why I should set charset attribute to 'utf-8' instead of 'PERL'? In
documentation says this option 'Defines the character-set which is used
in the data' and in real this is 'PERL'. Can you show me the right way
of creating utf-8 encoded body, please?
Show quoted text>
> > 2) You didn't set mime_type to default value 'text/plain' when
> > creating body with 'data' option as says in documentation
> > and maybe this is a bug.
>
> I do not read than from the docs. I see "data are lines", but that
also
Show quoted text> holds for "text/html" and hundreds of other text/* types.
>
In documentation to Mail::Message::Body module says that mime_type
option has 'text/plain' value by default, but code without setting it
explicitly doesn't work.
my $body = Mail::Message::Body->new(
data => $text,
charset => 'utf-8',
);
In your code it sets to default value only when creating message body
from file.