
ruslan.zakirov at gmail
May 8, 2009, 1:59 PM
Post #1 of 1
(368 views)
Permalink
|
|
Re: [Rt-commit] r19578 - in rt/3.8/trunk: share/html/Ticket/Attachment/WithHeaders
|
|
Emmanuel, there is no such thing as original encoding for headers. Anything not ascii is illegal in the head. Even the message has been in some encoding then it doesn't mean that the head was in the same or even in one encoding. I never saw "download with headers" as something useful for anything except some debugging. I don't mind that we make it consistent and readable, but let's make it in a branch with tests and for 3.8.4. Are you ok with that? On Thu, May 7, 2009 at 2:13 PM, <elacour[at]bestpractical.com> wrote: > 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; > _______________________________________________ > Rt-commit mailing list > Rt-commit[at]lists.bestpractical.com > http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-commit > -- Best regards, Ruslan. _______________________________________________ List info: http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel
|