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

? sunnavy sunnavy at bestpractical.com
Sat Mar 7 15:18:46 EST 2015


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

- Log -----------------------------------------------------------------
commit bd70fea27144dd3230446d43eb566b525263e573
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.12/content b/etc/upgrade/4.2.12/content
new file mode 100644
index 0000000..3bea306
--- /dev/null
+++ b/etc/upgrade/4.2.12/content
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+
+use Encode;
+
+our @Final = (
+    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,
             )

-----------------------------------------------------------------------


More information about the rt-commit mailing list