[Rt-commit] rt branch, 4.2/encode-2.53-support, created. rt-4.2.0rc4-1-g8a30d76

Alex Vandiver alexmv at bestpractical.com
Fri Sep 27 14:47:09 EDT 2013


The branch, 4.2/encode-2.53-support has been created
        at  8a30d764d4507a7e3fe8d0f7a6fff8d564a9df59 (commit)

- Log -----------------------------------------------------------------
commit 8a30d764d4507a7e3fe8d0f7a6fff8d564a9df59
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Sep 27 14:30:39 2013 -0400

    Ensure that the Subject header is not double-encoded
    
    In Encode 2.52 and below, `decode_utf8(...)` called on a string with the
    internal utf8" flag (i.e. containing characters, not bytes) was a no-op.
    Encode 2.53 changed this, for parity with `decode('utf8', ...)`
    
    The contents of the 'Subject' header when sending mail were usually
    bytes, as parsed by MIME-Tools.  As such, before adding the subject tag,
    they were decoded into characters.  However, in the case where no
    Subject was given by the template (for example, the "Transaction"
    template), RT generated a (wide-character) string for the Subject based
    on the ticket title, and inserted it into the MIME object.  Later,
    before the subject tag was added decode_utf8() was called on this wide
    string -- and prior to Encode 2.53, this was a no-op.
    
    Ensure that the values placed in the MIME header are always bytes, and
    not wide characters.  There are two changes to do this: first, ensure
    that the automatically-generated subject is encoded before being used;
    and second, that the string with the subject tag is re-encoded before
    the header is set to it.

diff --git a/lib/RT/Action/SendEmail.pm b/lib/RT/Action/SendEmail.pm
index fa22b20..5f02e43 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -1021,7 +1021,7 @@ sub SetSubject {
 
     $subject =~ s/(\r\n|\n|\s)/ /g;
 
-    $self->SetHeader( 'Subject', $subject );
+    $self->SetHeader( 'Subject', Encode::encode_utf8( $subject ) );
 
 }
 
@@ -1035,11 +1035,14 @@ sub SetSubjectToken {
     my $self = shift;
 
     my $head = $self->TemplateObj->MIMEObj->head;
-    $head->replace(
-        Subject => RT::Interface::Email::AddSubjectTag(
-            Encode::decode_utf8( $head->get('Subject') ),
-            $self->TicketObj,
-        ),
+    $self->SetHeader(
+        Subject =>
+            Encode::encode_utf8(
+                RT::Interface::Email::AddSubjectTag(
+                    Encode::decode_utf8( $head->get('Subject') ),
+                    $self->TicketObj,
+                ),
+            ),
     );
 }
 

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


More information about the Rt-commit mailing list