From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 842952022A; Thu, 18 Aug 2016 01:39:41 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Cc: Thomas Ferris Nicolaisen , Johannes Schindelin Subject: [PATCH 2/3] view: try to display bogus charsets for text/plain Date: Thu, 18 Aug 2016 01:39:40 +0000 Message-Id: <20160818013941.8673-3-e@80x24.org> In-Reply-To: <20160818013941.8673-1-e@80x24.org> References: <20160818013941.8673-1-e@80x24.org> List-Id: Alpine seems to set charset=X-UNKNOWN for valid UTF-8 text, which causes Email::MIME::body_str to fail as X-UNKNOWN is not a valid encoding. So, blindly display the body as plain-text but warn users about possibly mangled text. Reported-by: Thomas Ferris Nicolaisen --- lib/PublicInbox/View.pm | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 3057221..3f0e122 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -407,14 +407,17 @@ sub flush_quote { $$s .= qq() . $rv . '' } -sub attach_link ($$$$) { - my ($upfx, $ct, $p, $fn) = @_; +sub attach_link ($$$$;$) { + my ($upfx, $ct, $p, $fn, $err) = @_; my ($part, $depth, @idx) = @$p; my $nl = $idx[-1] > 1 ? "\n" : ''; my $idx = join('.', @idx); my $size = bytes::length($part->body); $ct ||= 'text/plain'; - $ct =~ s/;.*//; # no attributes + + # hide attributes normally, unless we want to aid users in + # spotting MUA problems: + $ct =~ s/;.*// unless $err; $ct = ascii_html($ct); my $desc = $part->header('Content-Description'); $desc = $fn unless defined $desc; @@ -427,7 +430,12 @@ sub attach_link ($$$$) { } else { $sfn = 'a.bin'; } - my $ret = qq($nl[-- Attachment #$idx: ); + my $ret = qq($nl); + if ($err) { + $ret .= +"[-- Warning: decoded text below may be mangled --]\n"; + } + $ret .= "[-- Attachment #$idx: "; my $ts = "Type: $ct, Size: $size bytes"; $ret .= ($desc eq '') ? "$ts --]" : "$desc --]\n[-- $ts --]"; $ret .= "\n"; @@ -446,12 +454,20 @@ sub add_text_body { my $s = eval { $part->body_str }; # badly-encoded message? tell the world about it! - return attach_link($upfx, $ct, $p, $fn) if $@; + my $err = $@; + if ($err) { + if ($ct =~ m!\btext/plain\b!i) { + # attach_link will warn further down... + $s = $part->body; + } else { + return attach_link($upfx, $ct, $p, $fn); + } + } my @lines = split(/^/m, $s); $s = ''; - if (defined($fn) || $depth > 0) { - $s .= attach_link($upfx, $ct, $p, $fn); + if (defined($fn) || $depth > 0 || $err) { + $s .= attach_link($upfx, $ct, $p, $fn, $err); $s .= "\n"; } my @quot; -- EW