diff options
author | Eric Wong <e@80x24.org> | 2016-05-18 20:30:31 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-05-19 19:24:21 +0000 |
commit | 4f7977b42aab1595b3a45b41e19499b38c46c8cc (patch) | |
tree | ed78ef85b3401a2ede29bbe15e201b864d643b06 /t/msg_iter.t | |
parent | 48b296d68d554499656cf8447f5ca841a8541ee7 (diff) | |
download | public-inbox-4f7977b42aab1595b3a45b41e19499b38c46c8cc.tar.gz |
Unlike Email::MIME::walk_parts, this is non-recursive and gives depth + index offset information about the part for creating links for later retrieval It is intended for read-only access and changes are not propagated to the parent; however future versions of it may clobber bodies or the original version as it iterates to reduce memory overhead. It is intended for making it easy to locate attachments within a message in the WWW view.
Diffstat (limited to 't/msg_iter.t')
-rw-r--r-- | t/msg_iter.t | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/t/msg_iter.t b/t/msg_iter.t new file mode 100644 index 00000000..cc58b93f --- /dev/null +++ b/t/msg_iter.t @@ -0,0 +1,40 @@ +# Copyright (C) 2016 all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> +use strict; +use warnings; +use Test::More; +use Email::MIME; +use_ok('PublicInbox::MsgIter'); + +{ + my $parts = [ Email::MIME->create(body => 'a'), + Email::MIME->create(body => 'b') ]; + my $mime = Email::MIME->create(parts => $parts, + header_str => [ From => 'root@localhost' ]); + my @parts; + msg_iter($mime, sub { + my ($part, $level, @ex) = @{$_[0]}; + push @parts, [ $part->body_str, $level, @ex ]; + }); + is_deeply(\@parts, [ [ qw(a 1 1) ], [ qw(b 1 2) ] ], 'order is fine'); +} + +{ + my $parts = [ Email::MIME->create(body => 'a'), + Email::MIME->create(body => 'b') ]; + $parts = [ Email::MIME->create(parts => $parts, + header_str => [ From => 'sub@localhost' ]), + Email::MIME->create(body => 'sig') ]; + my $mime = Email::MIME->create(parts => $parts, + header_str => [ From => 'root@localhost' ]); + my @parts; + msg_iter($mime, sub { + my ($part, $level, @ex) = @{$_[0]}; + push @parts, [ $part->body_str, $level, @ex ]; + }); + is_deeply(\@parts, [ [ qw(a 2 1 1)], [qw(b 2 1 2)], [qw(sig 1 2)] ], + 'nested part shows up properly'); +} + +done_testing(); +1; |