On Fri, 3 Nov 2017 22:37:46 -0700
Amit Gupta <[email protected]> wrote:

> When iterating through the parts of a MIME::Entity using parts_DFS,
> what would be the best way to get a reference to a part's parent
> entity or parent entity type?

Pass it in when you recurse.

sub process {
        my ($entity, $parent_entity) = @_;

        if ($entity->is_multipart()) {
                foreach my $p (@{$entity->parts()}) {
                        process ($p, $entity);
                }
                return;
        }

        # Process non-multiparts here
}

Call it with:  process($toplevel, undef)

If you need the entire chain of entities all the way to the top,
use an array:

sub process
{
        my ($entity, $parents) = @_;
        $parents ||= [];
        if ($entity->is_multipart) {
                my @parents_copy = @$parents;
                push(@parents_copy, $entity);
                foreach my $p (@{$entity->parts()}) {
                        process($p, \@parents_copy);
                }
                return;
        }
        # Process non-multiparts here
}

Regards,

Dianne.
_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID.  You may ignore it.

Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list [email protected]
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang

Reply via email to