From bfac757e9e70c1f8fae60d154695dae65711c837 Mon Sep 17 00:00:00 2001 From: Shaun Amott Date: Sat, 23 Jul 2011 02:42:59 +0000 Subject: [PATCH] - Send "utf-8" as the charset for the page to match what we actually output. - Properly decode MIME parts from their source charset (in the case of a single-part message, we haven't got the relevant headers thanks to GNATS. Sigh.) - Don't strip the trailing newline on MIME parts, as this breaks encoded Quoted-Printable newlines (if there happened to be one at the end). --- en/cgi/GnatsPR/Section/MIME.pm | 30 ++++++++++++++++++++++++------ en/cgi/query-pr.cgi | 5 ++++- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/en/cgi/GnatsPR/Section/MIME.pm b/en/cgi/GnatsPR/Section/MIME.pm index d06380ca45..d6a42caad6 100644 --- a/en/cgi/GnatsPR/Section/MIME.pm +++ b/en/cgi/GnatsPR/Section/MIME.pm @@ -24,7 +24,7 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# $FreeBSD$ +# $FreeBSD: www/en/cgi/GnatsPR/Section/MIME.pm,v 1.1 2011/07/20 22:23:23 shaun Exp $ #------------------------------------------------------------------------------ package GnatsPR::Section::MIME; @@ -136,10 +136,10 @@ sub Parse { my $self = shift; - # XXX: decode other charsets? + my $charset; $self->{body} =~ s/^[\n\s]+//; - $self->{body} =~ s/[\n\s]+$//; + $self->{body} =~ s/[\n\s]+$/\n/; $self->ParseHeader(); @@ -157,14 +157,32 @@ sub Parse return; } + if ($self->header('content-type:charset')) { + my $cs = $self->header('content-type:charset'); + + if ($cs =~ /utf.*8/i) { + $cs = 'utf-8'; + } else { + $cs = Encode::resolve_alias($cs); + } + + if ($cs and $cs ne 'ascii') { + $charset = $cs; + } + } + # Look for Quoted-Printable (explicit or using a silly heuristic) if (lc $self->header('content-transfer-encoding') eq 'quoted-printable' or $self->{body} =~ /=[0-9A-Fa-f]{2}=[0-9A-Fa-f]{2}/) { - $self->{body} = decode('utf8', decode_qp($self->{body})); + $self->{body} = decode_qp($self->{body}); + $self->{body} = decode($charset, $self->{body}) + if ($charset); # Base64 -- probably better not to decode } elsif (lc $self->header('content-transfer-encoding') eq 'base64') { - $self->{decoded_body} = decode('utf8', decode_base64($self->{body})); + $self->{decoded_body} = decode_base64($self->{body}); + $self->{decoded_body} = decode($charset, $self->{decoded_body}) + if ($charset); $self->{encoded} = 1; } @@ -189,7 +207,7 @@ sub Parse } if ($self->{body} =~ /^begin \d\d\d (.*)/ && !$self->{encoded}) { - $self->{decoded_body} = decode('utf8', uudecode($self->{body})); + $self->{decoded_body} = uudecode($self->{body}); $self->{encoded} = 1; } } diff --git a/en/cgi/query-pr.cgi b/en/cgi/query-pr.cgi index 659ebd3506..5556069cae 100755 --- a/en/cgi/query-pr.cgi +++ b/en/cgi/query-pr.cgi @@ -26,7 +26,7 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# $FreeBSD: www/en/cgi/query-pr.cgi,v 1.78 2011/07/21 14:31:41 shaun Exp $ +# $FreeBSD: www/en/cgi/query-pr.cgi,v 1.79 2011/07/22 23:38:58 shaun Exp $ # # Useful PRs for testing: # @@ -93,6 +93,9 @@ if (!$iscgi && !exists $ENV{'REQUEST_METHOD'}) { $main::hsty_base ||= ''; $main::t_style ||= ''; +$main::hsty_charset ||= ''; + +$main::hsty_charset = 'utf-8'; $main::t_style = qq{