X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FMsgIter.pm;h=9e2d797fecc240d4f191ba8f3fe7fd84b410148e;hb=7d82a8bc04ce2e686371abc6b438ab121b9fa7d0;hp=a795f6175b93003118e64b229e10197f94b5c847;hpb=c3a8ba378c7d3548a5d3ede110b90f8aa8e2473e;p=public-inbox.git diff --git a/lib/PublicInbox/MsgIter.pm b/lib/PublicInbox/MsgIter.pm index a795f617..9e2d797f 100644 --- a/lib/PublicInbox/MsgIter.pm +++ b/lib/PublicInbox/MsgIter.pm @@ -5,7 +5,7 @@ package PublicInbox::MsgIter; use strict; use warnings; use base qw(Exporter); -our @EXPORT = qw(msg_iter); +our @EXPORT = qw(msg_iter msg_part_text); use PublicInbox::MIME; # Like Email::MIME::walk_parts, but this is: @@ -34,4 +34,27 @@ sub msg_iter ($$) { } } +sub msg_part_text ($$) { + my ($part, $ct) = @_; + + my $s = eval { $part->body_str }; + my $err = $@; + + # text/plain is the default, multipart/mixed happened a few + # times when it should not have been: + # <87llgalspt.fsf@free.fr> + # <200308111450.h7BEoOu20077@mail.osdl.org> + if ($ct =~ m!\btext/plain\b!i || $ct =~ m!\bmultipart/mixed\b!i) { + # Try to assume UTF-8 because Alpine seems to + # do wacky things and set charset=X-UNKNOWN + $part->charset_set('UTF-8'); + $s = eval { $part->body_str }; + + # If forcing charset=UTF-8 failed, + # caller will warn further down... + $s = $part->body if $@; + } + ($s, $err); +} + 1;