rendered paste bodydiff -rub /tmp/rt-3.4.5/html/Elements/Header /pkg/share/rt3/html/Elements/Header
--- /tmp/rt-3.4.5/html/Elements/Header 2005-12-02 07:14:40.000000000 +0300
+++ /pkg/share/rt3/html/Elements/Header 2006-11-17 14:23:58.000000000 +0300
@@ -47,6 +47,7 @@
<HTML>
<HEAD>
<TITLE><%$Title%></TITLE>
+<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
% if ($Refresh && $Refresh > 0) {
<META HTTP-EQUIV="REFRESH" CONTENT="<%$Refresh%>">
% }
diff -rub /tmp/rt-3.4.5/html/Ticket/Elements/ShowTransactionAttachments /pkg/share/rt3/html/Ticket/Elements/ShowTransactionAttachments
--- /tmp/rt-3.4.5/html/Ticket/Elements/ShowTransactionAttachments 2005-11-13 08:14:57.000000000 +0300
+++ /pkg/share/rt3/html/Ticket/Elements/ShowTransactionAttachments 2006-11-17 14:23:58.000000000 +0300
@@ -91,7 +91,7 @@
# {{{ if it has a content-disposition: attachment, don't show inline
unless ( ($message->GetHeader('Content-Disposition')||"") =~ /attachment/i ) {
- my $content;
+ my ($content, $charset);
# If it's text
if ( $message->ContentType =~ m{^(text|message)}i
@@ -121,20 +121,22 @@
if ( $AttachmentContent->{ $message->id } ) {
$content = $AttachmentContent->{ $message->id }->Content;
+ $charset = $AttachmentContent->{ $message->id }->OriginalEncoding;
}
else {
$content = $message->Content;
+ $charset = $message->OriginalEncoding;
}
# if it's a text/html clean the body and show it
if ( $message->ContentType =~ m{^text/(?:html|enriched)$}i ) {
$content =
$m->comp( '/Elements/ScrubHTML', Content => $content );
- $m->out($content);
+ $m->out( Encode::decode( $charset, $content ) );
}
# if it's a text/plain show the body
- elsif ( $message->ContentType =~ m{^(text|message|text)}i ) {
+ elsif ( $message->ContentType =~ m{^(text/plain|message)}i ) {
eval { $content = Text::Quoted::extract($content); };
if ($@) { 1; }
diff -rub /tmp/rt-3.4.5/html/Ticket/ShowEmailRecord.html /pkg/share/rt3/html/Ticket/ShowEmailRecord.html
--- /tmp/rt-3.4.5/html/Ticket/ShowEmailRecord.html 2005-02-01 17:20:40.000000000 +0300
+++ /pkg/share/rt3/html/Ticket/ShowEmailRecord.html 2006-11-17 14:23:58.000000000 +0300
@@ -51,6 +51,7 @@
my $AttachmentObj = new RT::Attachment($session{'CurrentUser'});
$AttachmentObj->Load($Attachment) || Abort(loc("Attachment '[_1]' could not be loaded", $Attachment));
+ $r->content_type("text/html; charset=" . $AttachmentObj->ContentEncoding) unless $AttachmentObj->ContentEncoding eq 'none';
unless ($AttachmentObj->id) {
Abort(loc("Attachment '[_1]' could not be loaded", $Attachment));
@@ -60,7 +61,8 @@
}
</%init>
-<& /Elements/Header, ShowBar => 0 &>
+<html>
+<body>
<pre>
<%$AttachmentObj->Headers%>
diff -rub /tmp/rt-3.4.5/lib/RT/Attachment_Overlay.pm /pkg/lib/rt3/RT/Attachment_Overlay.pm
--- /tmp/rt-3.4.5/lib/RT/Attachment_Overlay.pm 2005-07-12 20:22:01.000000000 +0400
+++ /pkg/lib/rt3/RT/Attachment_Overlay.pm 2007-02-05 16:04:21.000000000 +0300
@@ -275,11 +276,18 @@
sub OriginalContent {
my $self = shift;
+ # RT::I18N::SetMIMEEntityToEncoding converts text/plain
+ # and message/rfc822 parts to utf-8.
+
+ # $RT::Logger->warning("OC: content type '".$self->ContentType."', content encoding '".$self->ContentEncoding."', original charset '".$self->OriginalEncoding."'\n");
+
return $self->Content unless (
$self->ContentType =~ qr{^(text/plain|message/rfc822)$}i) ;
- my $enc = $self->OriginalEncoding;
+ my $enc = $self->OriginalEncoding;
my $content;
+ my $xcontent;
+
if ( $self->ContentEncoding eq 'none' || ! $self->ContentEncoding ) {
$content = $self->_Value('Content', decode_utf8 => 0);
} elsif ( $self->ContentEncoding eq 'base64' ) {
@@ -290,15 +298,22 @@
return( $self->loc("Unknown ContentEncoding [_1]", $self->ContentEncoding));
}
- # Encode::_utf8_on($content);
+ Encode::_utf8_on($content);
+
+ # At this point, $content holds UTF-8 perl string. We should return octets.
+
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($content))} || return ($content);
+ return Encode::encode_utf8($content);
}
- eval { Encode::from_to($content, 'utf8' => $enc);};
+ eval {
+ $xcontent = Encode::encode($enc, $content, Encode::FB_CROAK);
+ };
if ($@) {
- $RT::Logger->error("Could not convert attachment from assumed utf8 to '$enc' :".$@);
+ $RT::Logger->error("Could not convert attachment from ".(Encode::is_utf8($content)?"UTF-8 ":"")."perl string to '$enc' octets: ".$@);
+ } else {
+# $RT::Logger->warning("OC: source is ".(Encode::is_utf8($content)?"UTF-8 ":"")."perl string, charset '$enc', encoding '".$self->ContentEncoding."', content '$xcontent'\n");
+ return $xcontent;
}
return $content;
}
diff -rub /tmp/rt-3.4.5/lib/RT/Transaction_Overlay.pm /pkg/lib/rt3/RT/Transaction_Overlay.pm
--- /tmp/rt-3.4.5/lib/RT/Transaction_Overlay.pm 2005-09-23 23:39:36.000000000 +0400
+++ /pkg/lib/rt3/RT/Transaction_Overlay.pm 2007-02-16 12:11:13.000000000 +0300
@@ -82,6 +82,9 @@
use RT::Attachments;
use RT::Scrips;
+use HTML::FormatText;
+use HTML::TreeBuilder;
+
# {{{ sub Create
=head2 Create
@@ -278,9 +281,16 @@
);
my $content;
- my $content_obj = $self->ContentObj;
- if ($content_obj) {
+ if (my $content_obj = $self->ContentObj) {
$content = $content_obj->Content;
+
+ if ($content_obj->ContentType =~ m{^text/html$}i) {
+ # $RT::Logger->warning("Formatting HTML: encoding is '".$content_obj->OriginalEncoding."'\n");
+ $content = Encode::decode($content_obj->OriginalEncoding, $content)
+ unless Encode::is_utf8($content);
+ $content = HTML::FormatText->new(leftmargin => 0, rightmargin => 78)->format(HTML::TreeBuilder->new_from_content($content));
+ # $RT::Logger->warning("Formatted HTML: result ".(Encode::is_utf8($content)?"is":"is not")." UTF-8\n");
+ }
}
# If all else fails, return a message that we couldn't find any content
@@ -345,7 +355,7 @@
# If it's a message or a plain part, just return the
# body.
- if ( $Attachment->ContentType() =~ '^(text/plain$|message/)' ) {
+ if ( $Attachment->ContentType() =~ '^(?:text/plain|text/html|message/)' ) {
return ($Attachment);
}
@@ -367,7 +377,7 @@
else {
my $all_parts = $self->Attachments;
while ( my $part = $all_parts->Next ) {
- if (( $part->ContentType() =~ '^(text/plain$|message/)' ) && $part->Content() ) {
+ if (( $part->ContentType() =~ '^(?:text/plain|text/html|message/)' ) && $part->Content() ) {
return ($part);
}
}