0
請我試圖從面向解碼所有郵件顯示爲HTML的問題,提醒服務和IM IMAP電子郵件,我使出導入了Zend類成笨和我一直面臨的問題沒有名爲contentTransferEncoding的標題,所以我訴諸搜索他們的消息,並顯示他們,這還沒有工作。我的代碼粘貼下面,也註釋掉那些是我已經試過onced的那些..我希望我很快使用Zend電子郵件借鑑IMAP的所有電子郵件的HTML
public function getmessage(){
function decode_imap_text($str){
$result = '';
$decode_header = imap_mime_header_decode($str);
foreach ($decode_header AS $obj) {
$result .= htmlspecialchars(rtrim($obj->text, "\t"));
}
return $result;
}
$id=$this->input->get("id");
$mail = new Zend_Mail_Storage_Imap(array('host' => 'Imap.gmail.com', 'user' => "********", 'password' => "******", 'ssl' => 'SSL'));
$message =$mail->getMessage($id);
$foundPart =$mail->getMessage($id);
echo $message->subject;
// echo $message->getcontent();
/*echo $message->contentTransferEncoding;*/
echo("<br>");
//quoted_printable_decode($message->getContent());
$content = $foundPart->getContent();
if (strpos($content,'Content-Transfer-Encoding: base64') !== false) {
echo base64_decode(imap_base64($content));
echo "base true";
}else if (strpos($content,'Content-Transfer-Encoding: quoted-printable') !== false) {
if(strpos($content,'charset="utf-8"')!== false){
echo utf8_decode(quoted_printable_decode($content));
echo "quote true";
}
if(strpos($content,'charset="iso-8859-1"')!== false){
echo utf8_decode(quoted_printable_decode($content));
echo "quote true";
}
//echo preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x80-\x9F]/u', '', quoted_printable_decode($content));
}else if (strpos($content,'Content-Transfer-Encoding: 8BIT') !== false) {
echo "8bit true";
echo quoted_printable_decode(imap_8bit($content));
}else if (strpos($content,'Content-Transfer-Encoding: BINARY') !== false) {
echo "BINARY true";
echo imap_binary($content);
}else{
echo quoted_printable_decode($content);
}
/*switch ($foundPart->contentTransferEncoding) {
case 'base64':
$content = base64_decode($content);
break;
case 'quoted-printable':
$content = quoted_printable_decode($content);
break;
case '8BIT':
$content = quoted_printable_decode($content);
break;
case '7BIT':
$content = quoted_printable_decode($content);
break;
case 'BINARY':
$content = quoted_printable_decode($content);
break;
case 'x-token':
$content = quoted_printable_decode($content);
break;
case null:
$content = 'no';
break;
}*/
//find the charset
/*preg_match('/charset="(.+)"$/', $foundPart->contentType, $matches);
$charset = $matches;
if ($charset == 'iso-8859-1') {
$content = utf8_encode($content); //convert to utf8
}
if ($charset == 'utf-8') {
$content = utf8_encode($content); //convert to utf8
}else{
$content = quoted_printable_decode($content);
}
echo quoted_printable_decode($content);*/ //echo strip_tags($message->getContent());
/*$foundPart = null;
foreach (new RecursiveIteratorIterator($mail->getMessage($id)) as $part) {
try {
if (strtok($part->contentType, ';') == 'text/plain') {
$foundPart = $part;
break;
}
} catch (Zend_Mail_Exception $e) {
// ignore
}
}
if (!$foundPart) {
echo 'no plain text part found';
} else {
echo "plain text part: \n" . quoted_printable_decode($foundPart);
}*/
}
考慮從代碼中刪除您的電子郵件/密碼。澄清你想要完成的事情也有助於得到答案。 – Seabass
謝謝鱸魚,正在建設的ERP軟件,我想從那裏鏈接的電子郵件,以便他們得到thier應用電子郵件,回覆並刪除郵件。其背後的概念是,他們不會在做任何官方任務時離開應用程序。我已經嘗試了正常的IMAP哪去了這麼慢,我不得不解碼信息的問題,所以我進口Zend庫到我笨應用程序使用thier IMAP類,但我仍然有正確解碼消息的問題 –