在MIME解碼附件我寫在Perl腳本,使多部分MIME消息這裏將一個圖像被腳本錯誤在用perl
use MIME::Parser;
use FileHandle;
$ffh = FileHandle->new;
if ($ffh->open(">m2.txt")) {
#print <$fh>;
}
### Create an entity:
$top = MIME::Entity->build(
From => '[email protected]',
To => '[email protected]',
Subject => "Hello, nurse!",
Data => "How are you today"
);
### Attach stuff to it:
$top->attach(
Path => "im.jpg",
Type => "image/jpg",
Encoding => "base64"
);
### Output it:
$top->print($ffh);
後,我試圖解析從上面的腳本所產生的輸出消息使用下面的代碼
use MIME::Parser;
use FileHandle;
$fh = FileHandle->new;
if ($fh->open("<m2.txt")) {
#print <$fh>;
}
### Create parser, and set some parsing options:
my $parser = new MIME::Parser;
$parser->output_to_core(1);
### Parse input:
$entity = $parser->parse($fh) or die "parse failed\n";
print $entity->head->get('subject');
print $entity->head->get('from');
print $entity->head->get('to');
print $entity->head->get('cc');
print $entity->head->get('date');
print $entity->head->get('content-type');
my $parts = $entity->parts(1);
my $body = $parts->bodyhandle;
print $parts->head->get('content-type');
$ffh = FileHandle->new;
if ($ffh->open(">C:/Users/Aamer/Desktop/im.jpg")) {
$body->print($ffh);
}
現在每一件事情正確分析和返回的值正確,除了輸出圖像作爲附件圖像一些如何被損壞我試圖詛咒比較它們有提取圖像與原始有些區別圖像可以任何人告訴我這裏有什麼問題?謝謝
非常感謝你,這個問題和你說的完全一樣,雖然「wb」在windows上不適合我。 binmode($ ffh)代替我工作。只是分享這個未來的幫助,但真的非常感謝 –
''wb「'應該工作。當您添加'「wb」'時,是否從文件名的前面刪除了'>'? – cjm
是的,並給出相同的錯誤 –