Take the 2-minute tour ×
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 .= $_;
            print $bodydata;
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
add comment

Your Answer


