开发者

Trouble with perl Email::MIME

I'm having trouble using the Email:MIME module in perl. It's probably because I'm using it wrong, but finding examples for using it is difficult. I'm pretty sure I'm supposed to be using a scalar of the full message as an input, but it's not working. Here is my code and my output

Code:

#!/usr/bin/perl

use Net::POP3;
use Email::MIME;
local $| = 1;

my $pop = Net::POP3->new('pop.mail.server');

print "Logging in....";
if ($pop->login('username','password')) {
 print "logged in successfully\n";
 my $msgs = $pop->list;
 my @keys = keys(%$msgs);
 my $msgr = $pop->get($keys[1]); #Selects a more or less random email for testing
 my 开发者_StackOverflow社区$msg = join("",@$msgr);

 my $parsed = Email::MIME->new($msg);
 foreach my $key (keys %$parsed) {print $key.":".$parsed{$key}."\n";}
}

Output:

Logging in....logged in successfully
body:
mycrlf:
body_raw:
parts:
ct:
header:


Always use strict; and use warnings;. This will immediately point out an error:

Global symbol "%parsed" requires explicit package name at p line 21.

Line 21 should be:

foreach my $key (keys %$parsed) {print $key.":".$parsed->{$key}."\n";}


I think that should be $parsed->{ $key } in your print statement

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜