From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: Thomas Ferris Nicolaisen <tfnico@gmail.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH 2/3] view: try to display bogus charsets for text/plain
Date: Thu, 18 Aug 2016 01:39:40 +0000 [thread overview]
Message-ID: <20160818013941.8673-3-e@80x24.org> (raw)
In-Reply-To: <20160818013941.8673-1-e@80x24.org>
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 <tfnico@gmail.com>
---
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(<span\nclass="q">) . $rv . '</span>'
}
-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<a\nhref="$upfx$idx-$sfn">[-- Attachment #$idx: );
+ my $ret = qq($nl<a\nhref="$upfx$idx-$sfn">);
+ 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 .= "</a>\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
next prev parent reply other threads:[~2016-08-18 1:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-18 1:39 [PATCH 0/3] attempt to display text/plain with bogus charsets Eric Wong
2016-08-18 1:39 ` [PATCH 1/3] view: attach_link uses string concatentation Eric Wong
2016-08-18 1:39 ` Eric Wong [this message]
2016-08-18 1:39 ` [PATCH 3/3] view: try assuming UTF-8 for bogus charsets Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160818013941.8673-3-e@80x24.org \
--to=e@80x24.org \
--cc=Johannes.Schindelin@gmx.de \
--cc=meta@public-inbox.org \
--cc=tfnico@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).