PHP的imap问题 [英] PHP imap problems

查看:146
本文介绍了PHP的imap问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够使用我的gmail从php脚本。但无论我尝试什么,消息体都会出现,像= 3D和随机符号等字符一样肮脏。有时它作为base64出现,或者什么也没有。如何获取电子邮件并在HTMLPurifier中清除html或纯文本,如果没有html可用。

I need to be able to use my gmail from a php script. But whatever I try, the message body comes out all crappy with characters like =3D and random equals signs. Sometimes it comes out as base64 or nothing at alls. How can I fetch an email and dispay it in HTMLPurifier clean html or plain text in a pre if no html is available.

$overview = imap_fetch_overview($inbox,$email_number,0);

$body_pre = imap_fetchbody($inbox, $email_number, 2.1); 

$message = imap_fetchbody($inbox, $email_number, 2.2); 

$message = base64_decode($message);

if (empty($message))
 {
  $message = $body_pre;
  $message = preg_replace('@(https?://([-\w\.]+)+(:\d+)?((/[\w/_\.%\-+~]*)?(\?\S+)?)?)@', '<a href="$1">$1</a>',$message);
$message = '<pre>'.htmlentities($message).'</pre>';  

}else{

 $cleanconfig = HTMLPurifier_Config::createDefault();
 $cleanconfig->set('Core.Encoding', 'UTF-8');
 $cleanconfig->set('HTML.Doctype', 'HTML 4.01 Transitional');
 $purifier = new HTMLPurifier($cleanconfig);

  $message = $purifier->purify($message);

 }

此代码,$消息只是空白。 >

this code, $message just comes blank.

推荐答案

你假设你的邮件总是在位置2.2?绝对没有保证...取决于发送什么消息你计划文本(只一个身体),html /文本(两个),附件(三加)回复另一个电子邮件(然后其他电子邮件将是一个身体与它是自己的子体)。

You're assuming your mail message is always at position 2.2? There's absolutely no guarantees... depends on what message is sent you plan text (just one body), html/text (two), with attachment (three plus) in reply to another email (then the other email will be a body with it's own sub bodies).

= 3D (引用的可打印)和base64数据是因为消息体编码。看看 imap_fetchstructure 它解释了他们在消息中有多少部分(您可以通过它查找文本来查找),并查看每个机构的 - >类型组件,以学习关于它的编码(type = 4是quotable可打印的,type = 3是base64)

The =3D (quoted printable) and base64 data are because of message body encodings. Have a look at imap_fetchstructure which explains how many parts their are on a message (you can search through it to find text), and review the ->type component of each body to learn about it's encoding (type=4 is quoted printable, type=3 is base64)

这篇关于PHP的imap问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆