On Sep 28, 2012, at 3:26 PM, Ronald F. Guilmette wrote:

> 
> 
> I'm not actually a total Perl beginner, but there are sizeable parts of
> the language that I know nothing about, and I'm kind-of in a hurry today,
> so maybe somebody will take pity and just point me in the right direction.
> 
> The sitiation is simple... I have an e-mail message whose topmost header
> says that it is multipart/mixed.  Under that, there is really only one part,
> and that part has a header that declares the part as being:
> 
>    Content-Type: text/html; charset=UTF-8
>    Content-Transfer-Encoding: quoted-printable
> 
> Ok, so forget about the content type and encoding for the moment.  I just
> want to print out the content of that one MIME part... really, _just_ the
> body of just that one MIME part.
> 
> I don't think I ever used MIME Tools or MIME::Parser before, so I'm not really
> familiar with these particular packages.
> 
> I tried this:
> 
> ==========================================================================
> #!/usr/local/bin/perl -w
> 
> use strict;
> 
> use MIME::Parser;
> 
> my $parser = new MIME::Parser;
> 
> my $entire = $parser->parse(\*STDIN) or die "parse failed\n";
> 
> my $part0 = $entire->parts(0);
> 
> my $gunk = $part0->body;
> 
> print $gunk->as_lines;
> 
> ==========================================================================
> 
> Unfortunately, running the above code only causes the following error
> message:
> 
>  Can't call method "as_lines" on unblessed reference at ./showhtml line 15.
> 
> Do I need to apply for special dispensation from the Pope, or what?
> 
> Any help would be appreciated.  I really have no idea what I did wrong.

I am not familiar with that module, so just guessing here.

From the documentation, it looks like you want to call;

  my $gunk = $part0-bodyhandle();

instead of body(). The bodyhandle() method returns an IO::Handle object that 
can be used to read the MIME entity, including using the as_lines() method to 
slurp in the file,

The body() method returns a reference to an array holding the entity body, so 
you could also do this:

  print @{$part0->body()};

Since $gunk is a reference to an array, you get the "Can't call method 
"as_lines" on unblessed reference ..." error message when you try to call the 
as_lines() method.

You can also call $entire->dump_skeleton() or 
$part0->bodyhandle()->print(\*STDOUT); to print out the data and see if it is 
what you expect.

Good luck!


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to