]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/MsgIter.pm
msg_part_text: discover text in application/octet-stream
[public-inbox.git] / lib / PublicInbox / MsgIter.pm
index 5ec2a4d9c7f1d3e06f76d4c4abb639ddacb00ac4..9c6581cc9dd63415a32a0a8f59bafae1cdb2b86d 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # read-only utilities for Email::MIME
@@ -34,7 +34,7 @@ sub em_each_part ($$;$$) {
                        }
                }
        } else {
-               $cb->([$mime, 0, 0], $cb_arg);
+               $cb->([$mime, 0, 1], $cb_arg);
        }
 }
 
@@ -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);
 }