[Rt-commit] rt branch, 4.2/do-not-encode-mime-headers-in-forward-method, created. rt-4.2.10-136-g9f9f521
? sunnavy
sunnavy at bestpractical.com
Tue Mar 10 14:33:15 EDT 2015
The branch, 4.2/do-not-encode-mime-headers-in-forward-method has been created
at 9f9f5212d7fa1d8e4f54dc66fccfbf118775c313 (commit)
- Log -----------------------------------------------------------------
commit 9f9f5212d7fa1d8e4f54dc66fccfbf118775c313
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sun Mar 8 01:41:34 2015 +0800
it's not RT::Ticket::Forward's job to encode headers to mime
previously if the subject of forward email contains non-ascii charts, it will
be encoded to mime like "=?UTF-8?B?w6TDtsO8?="(i.e. "äöü") in ->Forward, which
is wrong because we want utf8 data there so in RT::Action::SendEmail, we can
massage it(e.g. to add subject token) and _then_ encode it to mime.
without this, non-ascii subject would be _double_ mime encoded if subject tag
also contains non-ascii charts.
another issue is: non-ascii subject of forwarded emails would be saved as mime
encoded string(like "=?UTF-8?B?w6TDtsO8?=") in Attachments table(in both Subject
and Headers columns) and be shown the _same_ way in history part of ticket
display page.
Fixes: I#29714
diff --git a/etc/upgrade/4.2.11/content b/etc/upgrade/4.2.11/content
index 5118aff..0d5a5e5 100644
--- a/etc/upgrade/4.2.11/content
+++ b/etc/upgrade/4.2.11/content
@@ -1,5 +1,6 @@
use strict;
use warnings;
+use Encode;
our @Initial = (
sub {
@@ -12,4 +13,22 @@ our @Initial = (
AND Content IS NULL;
EOSQL
},
+ sub {
+ my $txns = RT::Transactions->new(RT->SystemUser);
+ $txns->Limit( FIELD => 'Type', VALUE => 'Forward Transaction' );
+ $txns->Limit( FIELD => 'Type', VALUE => 'Forward Ticket' );
+ while ( my $txn = $txns->Next ) {
+ my $att = $txn->Attachments->First;
+
+ # we only need to process ascii-only strings
+ unless ( $att->Subject =~ /[^\x00-\x7F]/ ) {
+ $att->__Set( Field => 'Subject', Value => decode_utf8(RT::I18N::DecodeMIMEWordsToUTF8($att->Subject, 'Subject')) );
+ }
+ for my $field ( qw/Subject From To Cc Bcc/ ) {
+ next if !$att->GetHeader($field) || $att->GetHeader($field) =~ /[^\x00-\x7F]/;
+ # Subject here is not a typo, because we don't really want to parse email addresses here
+ $att->SetHeader( $field, decode_utf8(RT::I18N::DecodeMIMEWordsToUTF8($att->GetHeader($field), 'Subject')) );
+ }
+ }
+ },
);
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 388579d..6aec0f4 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -3053,12 +3053,11 @@ sub Forward {
Data => Encode::encode( "UTF-8", $args{Content} ),
);
- $mime->head->replace(
- $_ => RT::Interface::Email::EncodeToMIME( String => $args{$_} ) )
+ $mime->head->replace( $_ => Encode::encode('UTF-8',$args{$_} ) )
for grep defined $args{$_}, qw(Subject To Cc Bcc);
$mime->head->replace(
- From => RT::Interface::Email::EncodeToMIME(
- String => RT::Interface::Email::GetForwardFrom(
+ From => Encode::encode( 'UTF-8',
+ RT::Interface::Email::GetForwardFrom(
Transaction => $args{Transaction},
Ticket => $self,
)
diff --git a/t/web/ticket_forward.t b/t/web/ticket_forward.t
index 8339e1a..322f6c9 100644
--- a/t/web/ticket_forward.t
+++ b/t/web/ticket_forward.t
@@ -8,6 +8,7 @@ open my $att_fh, '>', $att_file or die $!;
print $att_fh "this is an attachment";
close $att_fh;
my $att_name = ( File::Spec->splitpath($att_file) )[-1];
+use Encode;
my ( $baseurl, $m ) = RT::Test->started_ok;
ok $m->login, 'logged in as root';
@@ -261,5 +262,24 @@ diag "Forward Ticket Template with a Subject: line" if $ENV{TEST_VERBOSE};
like($mail, qr/Subject: \[example.com #\d+\] OVERRIDING SUBJECT/);
}
+diag "Forward Transaction with non-ascii subject" if $ENV{TEST_VERBOSE};
+{
+ $m->follow_link_ok( { text => 'Forward', n => 2 }, 'follow 2nd Forward' );
+ my $subject = decode_utf8('test non-ascii äöü');
+ $m->submit_form(
+ form_name => 'ForwardMessage',
+ fields => {
+ Subject => $subject,
+ To => 'rt-to at example.com',
+ },
+ button => 'ForwardAndReturn'
+ );
+ my ($mail) = RT::Test->fetch_caught_mails;
+ if ( $mail =~ /Subject: (.+)/ ) {
+ like( decode_utf8(RT::I18N::DecodeMIMEWordsToUTF8( $1, 'Subject' )), qr/$subject/, 'non-ascii subject' );
+ }
+ $m->content_contains( $subject, 'non-ascii subject got displayed correctly' );
+}
+
undef $m;
done_testing;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list