From: Ted Byers on
I am using Activestate perl 5.10.0 on WXP, if that matters.

I tried function dump_entity from mimedump, distributed with the
latest release of MIME::tools. It looked simple enough, but when I
pass to it the emails I get from the IMAP server (using
Net::IMAP::Simple::SSL), it prints nothing.

I can print any and all of the headers, using, e.g. other examples
provided in the documentation, and using length($es->body), I get a
length of anywhere from a few kilobytes to over 1 MB. But still,
function dump_entity prints nothing. For some reason that is
presently beyond me, MIME::Parser fails to correctly identify any of
the message parts. If I use the appended functions to print the
messages I get from the IMAP server, I see all the lines containing
all the content of the message, including html and uuencoded image
data from messages where the body is html and includes jpg, gif and
png files referred to by img tags in the html.

The following sequence prints all of the hierarchical data in
$message in a way in which I can see the hierarchical nature of the
data:

my $message = $imap->get($j);
print "Message: $j\n";
print_obj($message);# my function, given below

but, the following:

my $parser = new MIME::Parser;
$parser->output_to_core(1);
$parser->extract_nested_messages(1);
$parser->extract_uuencode(1);

my @l2 = @{$message};
my $entity = $parser->parse_data(@l2);
$entity->dump_skeleton;
dump_entity($entity);

Prints the correct skeleton (undoubtedly from the call to
dump_skeleton), but no content. I don't understand why. I tried to
use the code in the examples, and the documentation, carefully, but I
don't see why I can't get at the html content (so i can parse it) or
to save to usable files, and describe, any binary content.

Any help would be appreciated.

Thanks

Ted

========my functions = not pretty, but servicable for what they were
writen for=======
========NB: print_obj is only for scalars and references to arrays and
hashes=======
===========it is NOT intended to be used on arrays or hashes
directly============
===========thus to print a hash, call print_obj(\%myhash), not
print_obj(%myhash)====
sub print_obj {
my ($obj,$lvl) = @_;
$lvl = 0 unless defined $lvl;
if (ref($obj) eq 'HASH') {
my %h = %{$obj};
foreach my $key (keys %h) {
print_n_tabs($lvl);
print "KEY: $key\nVALUE(s)";
print_obj($h{$key},$lvl+1);
}
} else {
if (ref($obj) eq 'ARRAY') {
my @a = @{$obj};
foreach my $ai (@a) {
print_n_tabs($lvl);
print "ARRAY item\n";
print_obj($ai,$lvl+1);
}
} else {
if (ref($obj) eq 'SCALAR') {
print_n_tabs($lvl);
print "$$obj\n";
} else {
print_n_tabs($lvl);
print "$obj\n";
}
}
}
}

sub print_n_tabs {
my $n = shift;
my $i = 0;
while ($i < $n) {
print "\t";
$i++;
}
}