Thread Mime::Parser und Umlaute im Dateinamen der Attachments
(10 answers)
Opened by Kai at 2010-06-24 21:40
hab mal vor einigen jahren nen webmail geschrieben.
hier ein auszug davon. kann nicht versprechen, dass noch alles so funktioniert, aber der hat auch die einzelnen teile auf platte gespeichert. ich kopiere es einfach hier ohne unnötige sachen wegzumachen Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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; } } } } |