sub parse_body { my ($self, $lines) = @_; my $output = $self->{unique}; Sources::Global::make_path($output); if(CORE::open(FILE, "> $output/mail")) { binmode FILE; print FILE join("", @{$lines}); CORE::close(FILE); } my $parser = MIME::Parser->new(); $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); my $cfg = Sources::Config->new(-filename => "$output/info"); $self->extract_entity($cfg, $self->{entity}); $cfg->close(); 1; } 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; if($body) { my $path = $body->path; $path =~ s!\\!/!g; $cfg->insert($path, "$type###$charset###$location"); if($type eq "message/rfc822") { } elsif($type =~ m!ms-tnef!i) { my $folder = Sources::Global::get_filepath($path); 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; } } $tnef->purge; } } } }