Leser: 28
1 2 3 4
use MIME::QuotedPrint; $encoded = encode_qp($decoded); $decoded = decode_qp($encoded);
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
#!/usr/bin/perl -w
use strict;
use MIME::Parser;
use MIME::QuotedPrint;
use CGI::Carp qw(fatalsToBrowser);
my $infile = $ARGV[0];
my $pfad = $ARGV[1];
my $top_entity;
my $prefix = $ARGV[2];
# Datei mit MIME-Nachricht einlesen und parsen
$top_entity = &parse_MIME_Stream($infile);
exit;
sub parse_MIME_Stream #(Eingabedatei)
{
my $file = shift;
my $parser = '';
die "NO FILE $!" unless defined $file;
# Neues Parser-Objekt
# Daten auf Festplatte speichern
$parser = MIME::Parser->new();
$parser->output_to_core('NONE');
$parser->output_dir($pfad);
$parser->output_prefix($prefix);
open(INPUT,$file) or die $!;
my $top_entity = $parser->read(\*INPUT);
close(INPUT) or die $!;
return $top_entity;
}
shell_exec('ks.pl '.$Filepath.$Filename.' '.$Filepath.' '.$Id);
Guest KaiKannst du mir vielleicht noch Tips geben? Das wäre Spitze...
Guest KaiIch verzweifle an der Sache echt, vorallem weil ich das schon längst hätte fertig haben müsste.
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; } } } }
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
while ("1")
{
my $pop = new Mail::POP3Client( USER => $cfg{pop3user},
PASSWORD => $cfg{pop3pass},
HOST => $cfg{pop3host} );
for(my $i = 1; $i <= $pop->Count(); $i++ )
{
print "\nLade E-Mail vom Server...";
my $CTIME_String = localtime(time);
print LOG ("\n###$CTIME_String###") if ($cfg{logging}==2);
print LOG ("\nLade E-Mail vom Server...") if ($cfg{logging}==2);
my $fh = new IO::File $mailfile, "w";
$pop->HeadAndBodyToFile($fh, $i);
$fh->close;
print "OK\n";
PARSE();
...
..
.
}
sub PARSE
{
my $parser = new MIME::Parser;
$parser->output_to_core(0);
$parser->output_dir($indir);
$parser->ignore_errors(1);
my $ent = $parser->parse_open($mailfile);
if ($Encoding and !$ent->is_multipart)
{
supported MIME::Decoder $Encoding or
die "unsupported encoding: $Encoding\n";
$ent->head->mime_attr("Content-transfer-encoding" => $Encoding);
}
my $head = MIME::Head->from_file($mailfile);
$to = $head->get('From', 0);
my @ar;
if (($to =~ m'\"') && ($to =~ m'\<') && ($to =~ m'\>'))
{
#Vorname und Name extrahieren
@ar = split('\" \<',$to);
$ar[1] =~ s'>''g;
$ar[1] =~ s'<''g;
$to = $ar[1];
$ar[0] =~ s'\"'';
$ar[0] =~ s','';
@ar = split(' ', $ar[0]);
}
$vorname = $ar[1];
$nachname = $ar[0];
$vorname = "unbekannter" unless ($vorname);
$nachname = "Benutzer" unless ($nachname);
$to =~ s'\n''g;
$to =~ s'\r''g;
$to =~ s'>''g;
$to =~ s'.*<''g;
#Löschen des nicht benötigten Mail-Body und die Mailfile
unlink $mailfile;
opendir (INDIR, $indir) or die "Verzeichniss nicht vorhanden";
while ($filename = readdir (INDIR))
{
if (($filename ne ".") && ($filename ne ".."))
{
if ($filename =~ /msg-.*-.*\.txt/i) #löschen des mail body
{
unlink("$indir$filename");
}
else
{
print LOG ("\nAnhang: $filename") if ($cfg{logging}==2);
}
}
}
closedir INDIR;
}