Subject: | use utf8 causes encoding issues |
When using unicode characters in Email::MIME the result from as_string()
is sometimes double encoded utf-8.
In the attached test script this behaviour is triggered by having a use
utf8 to correctly interpret the inline utf8 strings. Normal output from
as_string() can be triggered by including the no utf8 clause (commented
out).
Imho the main problem is that Email::MIME is joining byte strings (when
creating a message to be sent) and depending on the context (e.g. use
utf8) will have those strings interpreted as utf-8 strings. This will
result in the bytes being encoded twice (as seen in the test script).
Subject: | test.pl |
use utf8;
use Encode;
use Devel::Peek;
use Email::MIME;
$subject = 'Bestätigung';
Dump( $subject );
$message = 'Hello Wörld';
Dump( $message );
#no utf8;
my $mail = Email::MIME->create(
header_str => [
Subject => $subject,
],
attributs => {
content_type => 'multipart/alternative',
},
parts => [
Email::MIME->create(
attributes => {
content_type => 'text/plain',
charset => 'utf-8',
encoding => '8bit',
},
body_str => $message,
#body => encode_utf8($message),
),
Email::MIME->create(
attributes => {
content_type => 'text/html',
charset => 'utf-8',
encoding => '8bit',
},
body_str => $message,
#body => encode_utf8($message),
),
],
);
Dump( $mail->as_string );