use MIME::Parser;
use Data::Dumper qw(Dumper);
$parser = MIME::Parser->new( );
$parser->output_to_core(1); # don't write attachments to disk
while (<STDIN>) {
$MESSAGE .= $_;
}
$message = $parser->parse_data($MESSAGE); # die( )s if can't parse
$head = $message->head( ); # object--see docs
$preamble = $message->preamble; # ref to array of lines
$epilogue = $message->epilogue; # ref to array of lines
$num_parts = $message->parts;
for (my $i=0; $i < $num_parts; $i++) {
print "part number = $i\n";
my $part = $message->parts(1);
my $content_type = $part->mime_type;
my $body = $part->as_string;
print $body;
}
在输出中,我也可以看到内容标题。我们是否有任何进程只将邮件正文内容收集到数组中?
提前感谢。
答案 0 :(得分:3)
my $body = $part->as_string;
错了。 MIME部分($part
是类MIME::Entity的实例)由标题,正文和结尾组成。
这应该是my @body_encoded_lines = $part->body
(行列表)或my $body_decoded_handle = $part->bodyhandle
(MIME::Body的实例)。