[Mimedefang] Part’s parent content-type

Dianne Skoll dfs at roaringpenguin.com
Sat Nov 4 09:37:23 EDT 2017


On Fri, 3 Nov 2017 22:37:46 -0700
Amit Gupta <amit777 at gmail.com> 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.



More information about the MIMEDefang mailing list