[Rt-commit] r19645 - in rt/3.8/branches/forward-message-encoding: lib/RT

falcone at bestpractical.com falcone at bestpractical.com
Tue May 12 18:10:08 EDT 2009


Author: falcone
Date: Tue May 12 18:10:08 2009
New Revision: 19645

Modified:
   rt/3.8/branches/forward-message-encoding/lib/RT/Attachment_Overlay.pm
   rt/3.8/branches/forward-message-encoding/share/html/Ticket/Attachment/WithHeaders/dhandler

Log:
 r19578:  elacour | 2009-05-07 06:13:05 -0400
 Fix encoding differences between attachment content and headers when
 downloading attachments with headers.
 
 - $AttachmentsObj->Headers is always UTF-8 as it's converted when saved to DB,
   and it has utf8 flag on
 - $AttachmentsObj->OriginalContent is in the original encoding and has utf8
   flag off
 
 so this patch adds an Attachment::OriginalHeaders method.


Modified: rt/3.8/branches/forward-message-encoding/lib/RT/Attachment_Overlay.pm
==============================================================================
--- rt/3.8/branches/forward-message-encoding/lib/RT/Attachment_Overlay.pm	(original)
+++ rt/3.8/branches/forward-message-encoding/lib/RT/Attachment_Overlay.pm	Tue May 12 18:10:08 2009
@@ -320,6 +320,46 @@
     return $content;
 }
 
+=head2 OriginalHeaders
+
+Returns the attachment's headers as octets before RT's mangling.  Currently,
+this just means restoring text content back to its original encoding.
+
+=cut
+
+sub OriginalHeaders {
+    my $self = shift;
+
+    return $self->Headers unless RT::I18N::IsTextualContentType($self->ContentType);
+    my $enc = $self->OriginalEncoding;
+
+    my $headers;
+    if ( !$self->ContentEncoding || $self->ContentEncoding eq 'none' ) {
+        $headers = $self->_Value('Headers', decode_utf8 => 0);
+    } elsif ( $self->ContentEncoding eq 'base64' ) {
+        $headers = MIME::Base64::decode_base64($self->_Value('Headers', decode_utf8 => 0));
+    } elsif ( $self->ContentEncoding eq 'quoted-printable' ) {
+        $headers = MIME::QuotedPrint::decode($self->_Value('Headers', decode_utf8 => 0));
+    } else {
+        return( $self->loc("Unknown ContentEncoding [_1]", $self->ContentEncoding));
+    }
+
+    # Turn *off* the SvUTF8 bits here so decode_utf8 and from_to below can work.
+    local $@;
+    Encode::_utf8_off($headers);
+
+    if (!$enc || $enc eq '' ||  $enc eq 'utf8' || $enc eq 'utf-8') {
+        # If we somehow fail to do the decode, at least push out the raw bits
+        eval { return( Encode::decode_utf8($headers)) } || return ($headers);
+    }
+
+    eval { Encode::from_to($headers, 'utf8' => $enc) } if $enc;
+    if ($@) {
+        $RT::Logger->error("Could not convert attachment headers from assumed utf8 to '$enc' :".$@);
+    }
+    return $headers;
+}
+
 =head2 OriginalEncoding
 
 Returns the attachment's original encoding.

Modified: rt/3.8/branches/forward-message-encoding/share/html/Ticket/Attachment/WithHeaders/dhandler
==============================================================================
--- rt/3.8/branches/forward-message-encoding/share/html/Ticket/Attachment/WithHeaders/dhandler	(original)
+++ rt/3.8/branches/forward-message-encoding/share/html/Ticket/Attachment/WithHeaders/dhandler	Tue May 12 18:10:08 2009
@@ -70,7 +70,7 @@
     # XXX: should we check handle html here and integrate headers into html?
     $r->content_type( $content_type );
     $m->clear_buffer;
-    $m->out( $AttachmentObj->Headers );
+    $m->out( $AttachmentObj->OriginalHeaders );
     $m->out( "\n\n" );
     $m->out( $AttachmentObj->OriginalContent );
     $m->abort;


More information about the Rt-commit mailing list