开发者

How to get the name from content-disposition in MIME::Entity part?

开发者 https://www.devze.com 2023-04-06 00:43 出处:网络
my $Parser = new MIME::Parser; my $entity = $Parser->parse_data( $body ); my @parts开发者_开发技巧 = $entity->parts;
my $Parser = new MIME::Parser;
my $entity = $Parser->parse_data( $body );
my @parts开发者_开发技巧 = $entity->parts;
for $part(@parts){   
    my $type=$part->mime_type;
    my $bhandle=$part->bodyhandle;

    $header = $part->head();
    $content_disp = $header->get('Content-Disposition');

     if ($type =~ /text/i){
         $bodydata = "";
         if (my $io = $part->open("r")) {
             while (defined($_ = $io->getline)) {
                 $bodydata .= $_;
             }
            $io->close;
            print $bodydata;
         }
     }
}


I think you're looking for the recommended_filename method:

$header = $part->head();
$filename = $header->recommended_filename;

Be sure to check the return value for sanity. Note that it can also be undef.

0

精彩评论

暂无评论...
验证码 换一张
取 消