我有一個應該提取電子郵件附件並將其放置在特定位置的模塊。該代碼創建POP3客戶端來獲取郵件,並使用EMAIL :: MIME :: Attachment :: Stripper模塊來提取附件,如下所示。如何從電子郵件附件中提取壓縮的xls文件?
my $mail=$pop->HeadAndBody($i);
my $parsed = Email::MIME->new($mail);
my $stripper = Email::MIME::Attachment::Stripper->new($parsed);
my @attachments = $stripper->attachments;
foreach my $a(@attachments)
{
next if $a->{content_type} !~ /octet-stream/i;
my $f = new IO::File "C:/MAIL_PARSING_DATA/" . "<filename>.<file-extension>", "w" or die "Can not create file!";
print $f $a->{payload};
goto EXITPOINT;
}
的代碼由Perl模塊,識別標準文件做工精細,像電子表格等,但不具有拉上Excel文件作爲附件的特定郵件。在提取文件時,由Perl腳本爲該文件識別的content_type是application/octet-stream。使用上述代碼提取文件時,文件似乎被破壞,因爲:
- 該文件未通過WinZip,WinRAR或7-Zip打開。
- 通過此腳本提取的文件的文件大小與使用Outlook提取的同一文件略有不同。
請在問題上提供一些意見。