Re: [Mimedefang] Part’s parent content-type

2017-11-04 Thread Dianne Skoll


On November 4, 2017 9:25:20 PM EDT, Amit Gupta  wrote:
>Thank you Dianne! This is going to sound silly, but what I'm looking
>for is a function like

>$parent_part = get_parent ($top_entity, $part);

No such function exists.  That's why you have to do it the way I illustrated.

You could probably use the framework I posted to write such a function,
but I would rethink what you're trying to do to make it fit more naturally
into the recursive MIME structure.  You are thinking non-recursively
when you request such a function.

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 MIMEDefang@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang


Re: [Mimedefang] Part’s parent content-type

2017-11-04 Thread Amit Gupta
Thank you Dianne! This is going to sound silly, but what I'm looking
for is a function like

$parent_part = get_parent ($top_entity, $part);

So given the top level entity and a specific part, the function will
return the MIME::Entity for the parent of $part.  I'm struggling with
getting the recursion on this.  Any tips on a simple way to do this?
___
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 MIMEDefang@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang


Re: [Mimedefang] Part’s parent content-type

2017-11-04 Thread Dianne Skoll
On Fri, 3 Nov 2017 22:37:46 -0700
Amit Gupta  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 MIMEDefang@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang


[Mimedefang] Part’s parent content-type

2017-11-03 Thread Amit Gupta
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? I’m trying to do some logic on an HTML part depending on if the parent 
type is multipart/related or not.  I was thinking of just setting a variable as 
I iterate through the parts, but it can get tricky if I don’t know the depth 
level I’m at. 
___
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 MIMEDefang@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang