そこで、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 も機能しません)。正規表現を使用して本文を解析しても問題ありません