Created
August 13, 2012 11:04
-
-
Save ktat/3339545 to your computer and use it in GitHub Desktop.
Email::MIME bug?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# Using Transport::SMTP, body is grabled with some case. | |
# With same code, | |
# Transport::Sendmail is ok(not garbled) | |
# Transport::SMTP is ng(garbled) | |
use strict; | |
use Carp; | |
use warnings; | |
use Email::MIME; | |
use Email::Sender::Simple qw(sendmail); | |
use Email::Sender::Transport::SMTP; | |
use Email::Sender::Transport::Sendmail; | |
use utf8; | |
my @header_str0 = ( # all key & value will be not utf8 flagged (ok with SMPT/Sendmail). | |
'From' , '"ktat" <ktat@exampl.com>', | |
'To' , '"ktat" <ktat@localhost>', | |
'Subject' , 'タイトル', | |
); | |
my @header_str1 = ( # keys(left of '=>') are utf8 flagged. (ng with SMTP) | |
From => '"ktat" <ktat@exampl.com>', | |
To => '"ktat" <ktat@localhost>', | |
Subject => 'タイトル', | |
); | |
my @header_str2 = ( # To value will be encoded, but utf8 flagged. (ng with SMTP) | |
'From' , '"ktat" <ktat@exampl.com>', | |
'To' , '"加藤敦" <ktat@localhost>', | |
'Subject' , 'タイトル', | |
); | |
{ # test of the above @header_str2 | |
my $x = $header_str2[3]; | |
my $y = Encode::encode("MIME-Q", $x, 1); | |
print $y, "\n"; # "=?UTF-8?Q?=E5=8A=A0=E8=97=A4=E6=95=A6?=" <ktat@localhost> | |
print utf8::is_utf8($y), "\n"; # 1 | |
} | |
my $email = Email::MIME->create | |
( | |
header_str => \@header_str1, | |
attributes => { | |
content_type => 'text/plain', | |
charset => 'UTF-8', | |
encoding => '8bit', | |
}, | |
body_str => '本文', | |
); | |
$| = 1; | |
warn "\n>>> 1 NG\n"; | |
warn $email->as_string; # utf8 flagged string(header) + not utf8 flagged string | |
warn "\n>>> 2 OK\n"; | |
print $email->as_string; # print is ok. I don't know why it is ok. | |
# it is the reason why Transport::Sendmail is ok (it uses 'print' to pipe) | |
warn "\n>>> 3 OK\n"; | |
warn $email->__head->as_string; # utf8 flagged string with no wide chars | |
warn "\n>>> 4 OK\n"; | |
warn $email->body_raw; | |
warn "\n>>> NG\n"; # as same as 1 ($email->as_string does this) | |
warn $email->__head->as_string . $email->body_raw; # NG | |
print "\n"; | |
# use SMTP | |
sendmail($email, | |
{transport => Email::Sender::Transport::SMTP->new | |
( { | |
'timeout' => 120, | |
'ssl' => 0, | |
'allow_partial_success' => 0, | |
'host' => '127.0.0.1' | |
})} | |
); | |
# use Sendmail | |
sendmail($email, {transport => Email::Sender::Transport::Sendmail->new}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment