]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/MsgIter.pm
msg_iter: provide means to stop using anonymous subs
[public-inbox.git] / lib / PublicInbox / MsgIter.pm
index 6453d9f1043630d267d19c8c1445ef8a288f3abe..cdd78b39b2afaf75dea36062c40354afab2c1e18 100644 (file)
@@ -12,8 +12,8 @@ use PublicInbox::MIME;
 # Like Email::MIME::walk_parts, but this is:
 # * non-recursive
 # * passes depth and indices to the iterator callback
-sub msg_iter ($$) {
-       my ($mime, $cb) = @_;
+sub msg_iter ($$;$) {
+       my ($mime, $cb, $cb_arg) = @_;
        my @parts = $mime->subparts;
        if (@parts) {
                my $i = 0;
@@ -27,11 +27,11 @@ sub msg_iter ($$) {
                                @sub = map { [ $_, $depth, @idx, ++$i ] } @sub;
                                @parts = (@sub, @parts);
                        } else {
-                               $cb->($p);
+                               $cb->($p, $cb_arg);
                        }
                }
        } else {
-               $cb->([$mime, 0, 0]);
+               $cb->([$mime, 0, 0], $cb_arg);
        }
 }