1 # Copyright (C) 2016 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 package PublicInbox::MsgIter;
8 our @EXPORT = qw(msg_iter);
10 use Scalar::Util qw(readonly);
12 # Workaround Email::MIME versions without
13 # commit dcef9be66c49ae89c7a5027a789bbbac544499ce
14 # ("removing all trailing newlines was too much")
15 # This is necessary for Debian jessie
18 my $ver = $Email::MIME::VERSION;
19 my $extra_nl = 1 if ($ver >= $bad && $ver < $good);
21 # Like Email::MIME::walk_parts, but this is:
23 # * passes depth and indices to the iterator callback
26 my @parts = $mime->subparts;
29 @parts = map { [ $_, 1, ++$i ] } @parts;
30 while (my $p = shift @parts) {
31 my ($part, $depth, @idx) = @$p;
32 my @sub = $part->subparts;
36 @sub = map { [ $_, $depth, @idx, ++$i ] } @sub;
37 @parts = (@sub, @parts);
40 my $lf = $part->{mycrlf};
41 my $bref = $part->{body};
42 if (readonly($$bref)) {