我在 perl 中编写了一个脚本来制作附加图像的多部分 MIME 消息这里是脚本
use MIME::Parser;
use FileHandle;
$ffh = FileHandle->new;
if ( $ffh->open(">m2.txt") ) {
#print <$fh>;
}
### Create an entity:
$top = MIME::Entity->build(
From => 'me@myhost.com',
To => 'you@yourhost.com',
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);
}
现在每件事都正确解析并返回正确的值,除了输出图像作为附件图像有些损坏我试图用十六进制比较它们提取的图像和原始图像之间有一些差异谁能告诉我这里有什么问题?谢谢