... use MIME::Parser; ... my $parser = new MIME::Parser(); $parser->ignore_errors(1); $parser->output_dir($output); $parser->output_prefix("msg"); $parser->extract_nested_messages(0); $parser->output_to_core(0); $parser->tmp_to_core(0); $parser->use_inner_files(0); $self->{entity} = $parser->parse_data($lines); ... $self->extract_entity($cfg, $self->{entity}); ... sub extract_entity { my ($self, $cfg, $entity) = @_; my @parts = $entity->parts; if(scalar(@parts)) { $self->extract_entity($cfg, $_) foreach (@parts); } else { my $type = $entity->head->mime_type || ""; my $location = $entity->head->mime_attr("content-location") || ""; my $charset = $entity->head->mime_attr('content-type.charset') || ""; my $body = $entity->bodyhandle; my $cntid = $entity->head->mime_attr('content-id'); if($body) { my $path = $body->path; $path =~ s!\\!/!g; my $folder = Sources::Global::get_filepath($path); if($cntid) { $cntid =~ s!^<|>$!!g; my $temp = "$folder/$cntid"; Sources::Global::move_file($path, $temp); $path = $temp; } $cfg->insert($path, "$type###$charset###$location"); # Sources::Global::encrypt($path); if($type eq "message/rfc822") { } elsif($type =~ m!ms-tnef!i) { my $tnef = Sources::Tnef->read_ent($entity, { output_dir => $folder }); my @atts = $tnef->attachments; foreach my $attch (@atts) { my $fullpath = "$folder/".$attch->longname; $cfg->insert($fullpath, "######"); if(open(FILE, "> $fullpath")) { binmode FILE; print FILE $attch->data; close FILE; } # Sources::Global::encrypt($fullpath); } $tnef->purge; } } } }