所以我使用 PERL 和 Email::MIME 从 gmail 获取电子邮件。这是我的代码:
use Net::IMAP::Simple::Gmail;
use Email::Mime;
# Creat the object that will read the emails
$server = 'imap.gmail.com';
$imap = Net::IMAP::Simple::Gmail->new($server);
# User and password
$user = 'username@gmail.com';
$password = 'passowrd';
$imap->login($user => $password);
# Select the INBOX and returns the number of messages
$numberOfMessages = $imap->select('INBOX');
# Now let's go through the messages from the top
for ($i = 1; $i <= $numberOfMessages; $i++)
{
$top = $imap->top($i);
print "top = $top\n";
$email = Email::MIME->new( join '', @{ $imap->top($i) } );
$body = $email->body_str;
print "Body = $body\n";
}#end for i
当我运行它时,我收到以下错误:
can't get body as a string for multipart/related; boundary="----=_Part_6796768_17893472.1369009276778"; type="text/html" at /Library/Perl/5.8.8/Email/Mime.pm line 341
Email::MIME::body_str('Email::MIME=HASH(0x87afb4)') called at readPhoneEmailFeed.pl line 37
如果我更换
$body = $email->body_str;
和
$body = $email->body;
我得到输出:
Body =
(即空字符串)
这里发生了什么?有没有办法让我得到消息的原始正文(->body_raw 也不起作用)?我可以使用正则表达式解析身体