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类,但我仍然有正确解码消息的问题 –