[Rt-commit] r19578 - in rt/3.8/trunk: share/html/Ticket/Attachment/WithHeaders
elacour at bestpractical.com
elacour at bestpractical.com
Thu May 7 06:13:06 EDT 2009
Author: elacour
Date: Thu May 7 06:13:05 2009
New Revision: 19578
Modified:
rt/3.8/trunk/lib/RT/Attachment_Overlay.pm
rt/3.8/trunk/share/html/Ticket/Attachment/WithHeaders/dhandler
Log:
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/trunk/lib/RT/Attachment_Overlay.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/Attachment_Overlay.pm (original)
+++ rt/3.8/trunk/lib/RT/Attachment_Overlay.pm Thu May 7 06:13:05 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/trunk/share/html/Ticket/Attachment/WithHeaders/dhandler
==============================================================================
--- rt/3.8/trunk/share/html/Ticket/Attachment/WithHeaders/dhandler (original)
+++ rt/3.8/trunk/share/html/Ticket/Attachment/WithHeaders/dhandler Thu May 7 06:13:05 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