[Rt-commit] rt branch, 4.2/rt-forward-encoding, repushed
Wallace Reis
wreis at bestpractical.com
Thu Nov 13 11:25:49 EST 2014
The branch 4.2/rt-forward-encoding was deleted and repushed:
was b312f51558df0f962da73a56d3414ed2d95254f8
now f5f4e55d03b70e7b1c57d3e58080113c051f847a
1: b312f51 ! 1: f5f4e55 Forwarded messages break attachments with non-ASCII filenames
@@ -19,7 +19,7 @@
use MIME::QuotedPrint;
use MIME::Body;
use RT::Util 'mime_recommended_filename';
-+use Encode 'encode_utf8';
++use Encode ();
+use URI;
sub _OverlayAccessible {
@@ -30,20 +30,29 @@
+sub _EncodeHeaderToMIME {
+ my ( $self, $header_name, $header_val ) = @_;
-+ my $encode_header = sub { URI->new( encode_utf8(shift) )->as_string };
++ my $encode_header = sub {
++ return q{UTF-8''} . URI->new( Encode::encode('UTF-8', shift) );
++ };
+ if ($header_name =~ /^Content-/i) {
+ my $params = MIME::Field::ParamVal->parse_params($header_val);
-+ foreach my $v ( values %$params ) {
-+ $v = $encode_header->($v);
++ $header_val = delete $params->{'_'};
++ foreach my $key ( sort keys %$params ) {
++ my $value = $params->{$key};
++ if ( $value =~ /[^\x00-\x7f]/ ) { # check for non-ASCII
++ $value = $encode_header->($value);
++ $header_val .= qq{; ${key}*="$value"};
++ }
++ else {
++ $header_val .= qq{; $key="$value"};
++ }
+ }
-+ $header_val = bless({}, 'MIME::Field::ParamVal')->set($params)->stringify;
+ }
+ elsif ( $header_name =~ /^(?:Resent-)?(?:To|From|B?Cc|Sender|Reply-To)$/i ) {
+ my @addresses = RT::EmailParser->ParseEmailAddress( $header_val );
+ foreach my $address ( @addresses ) {
+ foreach my $field (qw(phrase comment)) {
+ my $v = $address->$field() or next;
-+ $v = $encode_header->($v);
++ $v = RT::Interface::Email::EncodeToMIME( String => $v );
+ $address->$field($v);
+ }
+ }
@@ -54,6 +63,7 @@
+ String => $header_val
+ );
+ }
++ return $header_val;
+}
+
sub ContentAsMIME {
@@ -74,16 +84,6 @@
diff --git a/t/web/ticket_forward.t b/t/web/ticket_forward.t
--- a/t/web/ticket_forward.t
+++ b/t/web/ticket_forward.t
-@@
- use strict;
- use warnings;
--
-+use utf8;
-+use Encode 'encode_utf8';
-+
- use RT::Test tests => undef;
- use File::Spec;
- my $att_file = File::Spec->catfile( RT::Test->temp_directory, 'attachment' );
@@
$m->submit_form(
form_name => 'ForwardMessage',
@@ -111,7 +111,7 @@
$m->form_name('TicketCreate');
my $attach = $m->current_form->find_input('Attach');
- $attach->filename("awesome.patch");
-+ $attach->filename(encode_utf8("awesome.pátch"));
++ $attach->filename('awesome.pátch');
$attach->headers('Content-Type' => 'text/x-diff');
$m->set_fields(
Subject => 'test forward, empty content but attachments',
@@ -131,7 +131,7 @@
like( $mail, qr/To: rt-test\@example.com/, 'To field' );
like( $mail, qr/This is a forward of transaction/, 'content' );
- like( $mail, qr/awesome\.patch/, 'att file name' );
-+ like( $mail, qr/awesome.p\%C3\%A1tch/, 'att file name' );
++ like( $mail, qr/filename\*\=\"UTF\-8\'\'awesome.p\%C3\%A1tch\"/, 'att file name' );
like( $mail, qr/this is an attachment/, 'att content' );
like( $mail, qr/text\/x-diff/, 'att content type' );
like( $mail, qr/bpslogo\.png/, 'att image file name' );
@@ -140,7 +140,7 @@
{
my $mime = MIME::Entity->build(
- From => 'test at example.com',
-+ From => encode_utf8('"Tést" <test at example.com>'),
++ From => '"Tést" <test at example.com>',
Subject => 'attachments for everyone',
Type => 'multipart/mixed',
);
@@ -148,7 +148,7 @@
like( $forward_txn, qr/This is a forward of transaction/, 'forward description' );
like( $forward_ticket, qr/Subject: $tag test forward, attachments but no "content"/, 'Subject field is from ticket' );
like( $forward_ticket, qr/This is a forward of ticket/, 'forward description' );
-+ like( $forward_ticket, qr/From: \"T\%C3\%A9st/ );
++ like( $forward_ticket, qr/From: \=\?UTF-8\?.* \<test\@example\.com\>/i );
for my $mail ($forward_txn, $forward_ticket) {
like( $mail, qr/To: rt-test\@example.com/, 'To field' );
More information about the rt-commit
mailing list