Wie kann ich die Emails wieder auslesen, sodaß bei Plain-Nachrichten die Formatierung beibehalten wird. Momentan laufen die Mails in ein Blob-Feld, ist das Falsch? Kann es sein, daß ich die Mails irgendwie kodieren muß, damit ich sie richtig formatiert zurückbekomme?
Dasselbe Problem hab ich nicht nur mit dem Mailbody, sondern auch mit Anhängen.
Hab ich irgeneinen größeren Fehler gemacht?
Code:
function pop($UserID, $popserver, $username, $password, $host_webmail, $user_webmail, $pwd_webmail, $database_webmail) { $Server = "{".$popserver."/pop3:110}" ; $mbox = imap_open($Server, $username, $password); if ($mbox) { echo("Sie sind mit dem Postfach verbunden! "); } else { die(imap_last_error()); } for ($i = 1; $i <= imap_num_msg($mbox); $i++) { $header = imap_header($mbox, $i); $Structure = imap_fetchstructure($mbox, $i); /* ?><PRE><? print_r($header) ?></PRE><? */ /* ?><PRE><? print_r($Structure) ?></PRE><? */ $SenderInfo = imap_fetchbody($mbox, $i, 0); $answered = $header->Answered; $ccaddress = $header->ccaddress; $ccMailbox = ""; $ccHost = ""; for ($j = 0; $j < count($header->cc); $j++) { $ccMailbox .= $header->cc[$j]->mailbox.";"; $ccHost .= $header->cc[$j]->host.";"; } $ccMailbox = substr($ccMailbox, 0, strlen($ccMailbox)-1); $ccHost = substr($ccHost, 0, strlen($ccHost)-1); $bccaddress = $header->bccaddress; $bccMailbox = ""; $bccHost = ""; for ($j = 0; $j < count($header->cc); $j++) { $bccMailbox .= $header->bcc[$j]->mailbox.";"; $bccHost .= $header->bcc[$j]->host.";"; } $bccMailbox = substr($bccMailbox, 0, strlen($bccMailbox)-1); $bccHost = substr($bccHost, 0, strlen($bccHost)-1); /* print_r ($ccMailbox); */ $date = $header->Date; $fromaddress = $header->fromaddress; $fromPersonal =""; $fromHost = ""; $fromMailbox =""; for ($j = 0; $j < count($header->from); $j++) { $fromPersonal .= $header->from[$j]->personal.";"; $fromMailbox .= $header->from[$j]->mailbox.";"; $fromHost .= $header->from[$j]->host.";"; } /* print_r($fromPersonal); */ $fromPersonal = substr($fromPersonal, 0, strlen($fromPersonal)-1); $fromMailbox = substr($fromMailbox, 0, strlen($fromMailbox)-1); $fromHost = substr($fromHost, 0, strlen($fromHost)-1); $MailDate = $header->MailDate; $message_id = $header->message_id; $Msgno = $header->Msgno; $recent = $header->Recent; $replytoaddress = $header->reply_toaddress; $replytoPersonal =""; $replytoMailbox =""; $replytoHost =""; for ($j = 0; $j < count($header->reply_to); $j++) { $replytoMailbox .= $header->reply_to[$j]->personal.";"; $replytoPersonal .= $header->reply_to[$j]->mailbox.";"; $replytoHost .= $header->reply_to[$j]->host.";"; } $replytoMailbox = substr($replytoMailbox, 0, strlen($replytoMailbox)-1); $replytoPersonal = substr($replytoPersonal, 0, strlen($replytoPersonal)-1); $replytoHost = substr($replytoHost, 0, strlen($replytoHost)-1); $senderaddress = $header->senderaddress; $senderMailbox =""; $senderPersonal =""; $senderHost =""; for ($j = 0; $j < count($header->sender); $j++) { $senderMailbox .= $header->sender[$j]->mailbox.";"; $senderPersonal .= $header->sender[$j]->personal.";"; $senderHost .= $header->sender[$j]->host.";"; } $senderMailbox = substr($senderMailbox, 0, strlen($senderMailbox)-1); //$senderPersonal = substr($senderPersonal, 0, strlen($senderPersonal)-1); $senderHost = substr($senderHost, 0, strlen($senderHost)-1); $Size = $header->Size; $subject = $header->Subject; $toaddress = $header->toaddress; $toaddress = $header->senderaddress; $toMailbox =""; $toHost =""; for ($j = 0; $j < count($header->to); $j++) { $toMailbox .= $header->to[$j]->mailbox.";"; $toHost .= $header->to[$j]->host.";"; } $toMailbox = substr($toMailbox, 0, strlen($toMailbox)-1); $toHost = substr($toHost, 0, strlen($toHost)-1); $udate = $header->udate; $unseen = $header->Unseen; $Flagged = $header->Flagged; $Deleted = $header->Deleted; $Draft = $header->Draft; $body = ( imap_body ($mbox, $i)); $body = ereg_replace("'","\'",$body); $body = ereg_replace('"',"\"",$body); $subject = ereg_replace("'","\'",$subject); $subject = ereg_replace('"',"\"",$subject); $SenderInfo = ereg_replace("'","\'",$SenderInfo); $SenderInfo = ereg_replace('"',"\"",$SenderInfo); $Werte = "answered".chr(2).$answered.chr(2)."ccaddress".chr(2).$ccaddress.chr(2)."ccMailbox".chr(2).$ccMailbox.chr(2)."ccHost".chr(2).$ccHost.chr(2)."date".chr(2).$date.chr(2)."fromaddress".chr(2).$fromaddress.chr(2)."fromPersonal".chr(2).$fromPersonal.chr(2)."fromMailbox".chr(2).$fromMailbox.chr(2)."fromHost".chr(2).$fromHost.chr(2)."MailDate".chr(2).$MailDate.chr(2)."message_id".chr(2).$message_id.chr(2)."Msgno".chr(2).$Msgno.chr(2)."recent".chr(2).$recent.chr(2)."replytoaddress".chr(2).$replytoaddress.chr(2)."replytoPersonal".chr(2).$replytoPersonal.chr(2)."replytoMailbox".chr(2).$replytoMailbox.chr(2)."replytoHost".chr(2).$replytoHost.chr(2)."senderaddress".chr(2).$senderaddress.chr(2)."senderMailbox".chr(2).$senderMailbox.chr(2)."senderPersonal".chr(2).$senderPersonal.chr(2)."senderHost".chr(2).$senderHost.chr(2)."Size".chr(2).$Size.chr(2)."subject".chr(2).$subject.chr(2)."toaddress".chr(2).$toaddress.chr(2)."toMailbox".chr(2).$toMailbox.chr(2)."toHost".chr(2).$toHost.chr(2)."udate".chr(2).$udate.chr(2)."unseen".chr(2).$unseen.chr(2)."Flagged".chr(2).$Flagged.chr(2)."Deleted".chr(2).$Deleted.chr(2)."Draft".chr(2).$Draft.chr(2)."body".chr(2).$body.chr(2)."UserNr".chr(2).$UserID.chr(2)."SenderInfo".chr(2).$SenderInfo.chr(2)."bccaddress".chr(2).$bccaddress.chr(2)."bccMailbox".chr(2).$bccMailbox.chr(2)."bccHost".chr(2).$bccHost; $pruefUID = selectString($host_webmail, $user_webmail, $pwd_webmail, $database_webmail, "Mail", "message_id", "message_id", $message_id); if ($pruefUID != $message_id) { SectionEintrag($mbox, $i, $Structure, $message_id, $host_webmail, $user_webmail, $pwd_webmail, $database_webmail); insertString ($host_webmail, $user_webmail, $pwd_webmail, $database_webmail, "Mail", $Werte); } } imap_close($mbox); } function SectionEintrag($mbox, $Msgno, $Structure, $message_id, $host_webmail, $user_webmail, $pwd_webmail, $database_webmail) { if (! $Structure->parts) { $type = $Structure->type; $subtype = $Structure->subtype; $encoding = $Structure->encoding; $bytes = $Structure->bytes; $attribute = $Structure->parameters[0]->attribute; $value = $Structure->parameters[0]->value; $disposition = $Structure->disposition; $section = imap_fetchbody($mbox, $Msgno, 1); $section = ereg_replace("'","\'",$section); $section = ereg_replace('"',"\"",$section); $Werte = "type".chr(2).$type.chr(2)."subtype".chr(2).$subtype.chr(2)."encoding".chr(2).$encoding.chr(2)."bytes".chr(2).$bytes.chr(2)."attribute".chr(2).$attribute.chr(2)."value".chr(2).$value.chr(2)."disposition".chr(2).$disposition.chr(2)."Section".chr(2).$section.chr(2)."message_id".chr(2).$message_id.chr(2)."SectionID".chr(2)."1"; insertString($host_webmail, $user_webmail, $pwd_webmail, $database_webmail, "Sections", $Werte); } else { for ($zz = 0; $zz < (count($Structure->parts)); $zz++) { $type = $Structure->parts[$zz]->type; $subtype = $Structure->parts[$zz]->subtype; $encoding = $Structure->parts[$zz]->encoding; $bytes = $Structure->parts[$zz]->bytes; $attribute = $Structure->parts[$zz]->parameters[0]->attribute; $value = $Structure->parts[$zz]->parameters[0]->value; $disposition = $Structure->parts[$zz]->disposition; ?><PRE><? print_r($Structure) ?></PRE><? $section = imap_fetchbody($mbox, $Msgno, $zz+1); /* print($section); echo("<hr>"); */ $section = ereg_replace("'","\'",$section); $section = ereg_replace('"',"\"",$section); $Werte = "type".chr(2).$type.chr(2)."subtype".chr(2).$subtype.chr(2)."encoding".chr(2).$encoding.chr(2)."bytes".chr(2).$bytes.chr(2)."attribute".chr(2).$attribute.chr(2)."value".chr(2).$value.chr(2)."disposition".chr(2).$disposition.chr(2)."Section".chr(2).$section.chr(2)."message_id".chr(2).$message_id.chr(2)."SectionID".chr(2).$zz; insertString($host_webmail, $user_webmail, $pwd_webmail, $database_webmail, "Sections", $Werte); } } }
Einen Kommentar schreiben: