Moin,
ich versuche Mails von einem Pop3-Server abzuholen und danach in eine MySQL-DB speichern (Absender, Betreff, Text, kein HTML und keinen Anhang). Beim zerlegen der Mail komm ich nicht wirklich weiter. Mit einem Mime::Parser Script von
Thomas Fahle bekomme ich "text/plain" und "text/html".
Mail zerlegen:
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
#!/usr/bin/perl -w
use strict;
use MIME::Parser;
my $file = 'Beispielnachricht.txt';
my $parser = MIME::Parser->new();
$parser->output_to_core('ALL');
open(INPUT,$file) or die $!;
my $entity = $parser->read(\*INPUT);
close(INPUT) or die $!;
my $head = $entity->head();
print "From: " , $entity->head->get('From');
print "Subject: " , $entity->head->get('Subject');
print "MIME type: " , $entity->mime_type,"\n";
print "MIME enc: ", $head->mime_encoding, "\n";
if ($head->mime_type() =~ m/multipart/i) {
my $part = $entity->parts();
my $part_entity = $entity->parts(0);
my $body = $part_entity->as_string;
print "Parts: $part\n";
print "$body\n";
}
else{
my $body = $entity->as_string;
print "$body\n";
}
Output:
QuoteFrom: Thomas Fahle <thomas@thomas-fahle.de>
Subject: Testnachricht mit Anh&�ngseln
MIME type: multipart/mixed
MIME enc: 7bit
Parts: 3
Content-Type: multipart/alternative; boundary="------------7FBBC9B0FED4B8DB02DE6558"
--------------7FBBC9B0FED4B8DB02DE6558
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hallo Thomas
Anbei zwei Bildchen
cu
------------------------------------------------------------------------
Thomas
--------------7FBBC9B0FED4B8DB02DE6558
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<HTML>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#FF0000" ALINK="#000088">
<FONT COLOR="#33CC00">Hallo Thomas</FONT>
<P>Anbei zwei Bildchen
<P>cu
<BR>
<HR WIDTH="100%">
<BR>Thomas
</BODY>
</HTML>
--------------7FBBC9B0FED4B8DB02DE6558--
Wie komme ich an den reinen Text, ohne den HTML Teil?
Gibts dafür ein anderes nettes Modul?