perl Email::MIME 问题
我在 perl 中使用 Email:MIME 模块时遇到问题。这可能是因为我使用错误,但找到使用它的示例很困难。我很确定我应该使用完整消息的标量作为输入,但它不起作用。这是我的代码和输出
代码:
#!/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 $msg = join("",@$msgr);
my $parsed = Email::MIME->new($msg);
foreach my $key (keys %$parsed) {print $key.":".$parsed{$key}."\n";}
}
输出:
Logging in....logged in successfully
body:
mycrlf:
body_raw:
parts:
ct:
header:
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 $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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
始终
使用严格;
和使用警告;
。这将立即指出错误:全局符号“%parsed”需要在第 21 行显式包名称。
第 21 行应该是:
Always
use strict;
anduse warnings;
. This will immediately point out an error:Global symbol "%parsed" requires explicit package name at p line 21.
Line 21 should be:
我认为打印语句中应该是
$parsed->{ $key }
I think that should be
$parsed->{ $key }
in your print statement