# Like Email::MIME::walk_parts, but this is:
 # * non-recursive
 # * passes depth and indices to the iterator callback
-sub msg_iter ($$;$) {
-       my ($mime, $cb, $cb_arg) = @_;
+sub msg_iter ($$;$$) {
+       my ($mime, $cb, $cb_arg, $do_undef) = @_;
        my @parts = $mime->subparts;
        if (@parts) {
+               $mime = $_[0] = undef if $do_undef; # saves some memory
                my $i = 0;
                @parts = map { [ $_, 1, ++$i ] } @parts;
                while (my $p = shift @parts) {
 
        my $diffs = [];
        foreach my $smsg (@$msgs) {
                $ibx->smsg_mime($smsg) or next;
-               my $mime = delete $smsg->{mime};
-               msg_iter($mime, \&extract_diff,
-                               [$self, $diffs, $pre, $post, $ibx, $smsg]);
+               msg_iter(delete $smsg->{mime}, \&extract_diff,
+                               [$self, $diffs, $pre, $post, $ibx, $smsg], 1);
        }
        @$diffs ? $diffs : undef;
 }
 
        # scan through all parts, looking for displayable text
        $ctx->{mhref} = $mhref;
        $ctx->{rv} = \$rv;
-       msg_iter($mime, \&add_text_body, $ctx);
+       msg_iter($mime, \&add_text_body, $ctx, 1);
        delete $ctx->{rv};
 
        # add the footer
 }
 
 sub multipart_text_as_html {
-       my ($mime, $mhref, $ctx) = @_;
+       my (undef, $mhref, $ctx) = @_; # $mime = $_[0]
        $ctx->{mhref} = $mhref;
        $ctx->{rv} = \(my $rv = '');
 
        # scan through all parts, looking for displayable text
-       msg_iter($mime, \&add_text_body, $ctx);
+       msg_iter($_[0], \&add_text_body, $ctx, 1);
        ${delete $ctx->{rv}};
 }
 
 
 sub feed_entry {
        my ($self, $smsg) = @_;
        my $ctx = $self->{ctx};
-       my $mime = $smsg->{mime};
+       my $mid = $smsg->mid; # may extract Message-ID from {mime}
+       my $mime = delete $smsg->{mime};
        my $hdr = $mime->header_obj;
-       my $mid = $smsg->mid;
        my $irt = PublicInbox::View::in_reply_to($hdr);
        my $uuid = to_uuid($mid);
        my $base = $ctx->{feed_base_url};
 
        my $mime = $ctx->{-inbox}->msg_by_mid($ctx->{mid}) or return $res;
        $mime = PublicInbox::MIME->new($mime);
        $res->[3] = $idx;
-       msg_iter($mime, \&get_attach_i, $res);
+       msg_iter($mime, \&get_attach_i, $res, 1);
        pop @$res; # cleanup before letting PSGI server see it
        $res
 }