saftmeister
Nutze den Saft!
Hey - ho! Schau mal ob dir das hier was bringt:
PHP:
<?php
$imap = imap_open("{$server}INBOX", "$user", "$pass");
if(!$imap)
{
die(imap_last_error());
}
$sorted = imap_sort($imap, SORTDATE, 0);
$total = imap_num_msg($imap);
$cur = 0;
while ($cur < $total) {
// Header abholen
$headerstr = imap_fetchheader($imap, $sorted[$cur]);
// Header parsen
$headers = imap_rfc822_parse_headers($headerstr);
// Mail-Struktur abholen
$structure = imap_fetchstructure($imap, $sorted[$cur]);
// Ein bisschen vor-initialisieren
$body = "undef";
$encoding = -1;
// Datum aus Header holen
$date = $headers->date;
// Absender aus Header holen
$senderaddress = $headers->senderaddress;
// Header decodieren
$senderaddressdecoded = imap_mime_header_decode($senderaddress);
if(count($senderaddressdecoded))
{
$senderaddress = $senderaddressdecoded[0]->text;
}
// Betreff aus Header holen
$subject = $headers->subject;
// Nachrichten-Struktur auf Text prüfen - simpel
if($structure->type == TYPETEXT) {
$body = imap_body($imap, $sorted[$cur]);
$encoding = $structure->encoding;
}
else
{
// Multipart-Nachricht - hier fehlt die Auswertung weiterer Parts
$body = imap_fetchbody($imap, $sorted[$cur], "1");
$structure = imap_bodystruct($imap, $sorted[$cur], "1");
$encoding = $structure->encoding;
}
// Encoding der Mail prüfen und ggf. decodieren
switch($encoding)
{
case 0: // 7bit
$body = quoted_printable_decode($body);
break;
case 1: // 8bit
case 2: // binary
// Nix
break;
case 3: // Base64
$body = imap_base64($body);
break;
case 4: // quoted printable
$body = imap_qprint($body);
break;
default:
$body = "Holy shit!";
break;
}
// Ausgabe - auf 3 header infos und 50 zeichen mailtext beschränkt
printf("Mail on %s from %s with subject '%s':\n\n ", $date, $senderaddress, $subject);
printf("%50.50s\n\n==========================\n\n", $body);
$cur++;
}
imap_close($imap);