[Rt-commit] rt branch, 4.2/do-not-encode-mime-headers-in-forward-method, created. rt-4.2.10-136-gb56cf8e

? sunnavy sunnavy at bestpractical.com
Sun Mar 15 07:02:07 EDT 2015


The branch, 4.2/do-not-encode-mime-headers-in-forward-method has been created
        at  b56cf8e3daac89ceb08554ff85b218ffccb6fe7c (commit)

- Log -----------------------------------------------------------------
commit b56cf8e3daac89ceb08554ff85b218ffccb6fe7c
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..f84dc04 100644
--- a/etc/upgrade/4.2.11/content
+++ b/etc/upgrade/4.2.11/content
@@ -12,4 +12,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 => Encode::decode("UTF-8", 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, Encode::decode("UTF-8", 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..439242d 100644
--- a/t/web/ticket_forward.t
+++ b/t/web/ticket_forward.t
@@ -261,5 +261,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 = Encode::decode("UTF-8", '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( Encode::decode("UTF-8", 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