about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-03-10 19:45:39 -0600
committerEric Wong <e@80x24.org>2021-03-12 02:18:15 +0000
commit0ec3ddaeea0e3eac3f4e686cd4383840414fbc4d (patch)
tree62872151aa17cecbbc1f055f907678d625e209b4 /lib/PublicInbox
parent7534692cd42797deeb9142598e031ca3184951cf (diff)
downloadpublic-inbox-0ec3ddaeea0e3eac3f4e686cd4383840414fbc4d.tar.gz
Some poorly-configured MUAs will send application/octet-stream
even for text-only attachments.  We can't make expect all MUAs
are configured with proper MIME types, and there is plenty of
historical mail that falls into this unfortunate criteria.

v2: simplify the check and ensures returned text is Perl "utf8"
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/MsgIter.pm8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/PublicInbox/MsgIter.pm b/lib/PublicInbox/MsgIter.pm
index c503eb98..9c6581cc 100644
--- a/lib/PublicInbox/MsgIter.pm
+++ b/lib/PublicInbox/MsgIter.pm
@@ -84,6 +84,14 @@ sub msg_part_text ($$) {
                 # If forcing charset=UTF-8 failed,
                 # caller will warn further down...
                 $s = $part->body if $@;
+        } elsif ($err && $ct =~ m!\bapplication/octet-stream\b!i) {
+                # Some unconfigured/poorly-configured MUAs will set
+                # application/octet-stream even for all text attachments.
+                # Try to see if it's printable text that we can index
+                # and display:
+                $s = $part->body;
+                utf8::decode($s);
+                undef($s =~ /[^\p{XPosixPrint}\s]/s ? $s : $err);
         }
         ($s, $err);
 }