一个imap的例子 - 参考,代码仅参考,复制后不可用

转载 2013年12月02日 22:14:39
    function getMsg($download_action, $mail_action) 
    {


        if(!$this->msg_uid) {
   $this->buildErrorMsg($this->ERR_STR_MSG_UID_INVALID, imap_last_error());
   return false;
}

$msg_no = imap_msgno($this->stream, $this->msg_uid);

$headers = @imap_header($this->stream, $msg_no);
if(!$headers) {
   $this->buildErrorMsg($this->ERR_STR_MSG_NO_INVALID, imap_last_error());
   return false;
}

$arr["date"] = gmstrftime ("%b %d %Y %H:%M:%S", strtotime($headers->date));
$arr["raw_from"] = $this->decodeHeader($headers->fromaddress);
$arr["raw_cc"] = $this->decodeHeader($headers->ccaddress);
$arr["from"] = $this->makeAddress($headers->from, "$mail_action&msg_uid=$this->msg_uid&mailbox=$this->mailbox");
$arr["cc"] = $this->makeAddress($headers->cc, "$mail_action&msg_uid=$this->msg_uid&mailbox=$this->mailbox");
$arr["subject"] = $this->decodeHeader($headers->subject);
if(empty($arr["subject"])) $arr["subject"] = $this->STR_NO_SUBJECT;

$arr["message_id"] = $headers->message_id;
$arr["references"] = $headers->references;
//from here - need to work out the MIME type etc and produce the download link accordingly.
$struct = @imap_fetchstructure($this->stream, $this->msg_uid, FT_UID);
$arr["struct"]=$struct;
$arr["num_parts"] = count($struct->parts) - 1;
$html = 0;
//this will give a list of all necessary mime type headers to sort out the message & attachments. 
/*echo "<font color=green>type ".$struct->type."\n<br>";
echo "encoding ".$struct->encoding."\n<br>";
echo "subtype ".$struct->subtype."\n<br>";
echo "sub-subtype".$struct->parts[0]->parts[1]->subtype."\n<br>";
echo "parts ".count($struct->parts)."\n<br></font><br>";
echo "id ".$struct->parts[1]->id."\n<br>";
//echo "<br>".imap_body($this->stream,$this->msg_uid,FT_UID);

/*This is the main message body handling area*/
/*********************************************/
if (($struct->parts !=0 && strtolower($struct->disposition) != "attachment") || $struct->bytes!=0) {
if ($struct->type == 1) //multipart message
{
if (strtolower($struct->subtype)=="alternative" || strtolower($struct->subtype)=="mixed")
{
for($i=0; $i< count($struct->parts); $i++) {
$type[$i]=$struct->parts[$i]->subtype;
}
if (strtolower($type[0])=="html")
{
$text=imap_fetchbody($this->stream, $this->msg_uid, "1", FT_UID);
if ($struct->parts[1]->encoding ==3) {
$arr["body"] = imap_base64($text);
$html = 1;
}
else if ($struct->parts[1]->encoding == 4 ) {
$arr["body"] = imap_qprint($text);
$html = 1;
}
else {
$arr["body"] = $text;
$html = 1;
}
}
elseif (strtolower($type[1])=="html")
{
$text=imap_fetchbody($this->stream, $this->msg_uid, "2", FT_UID);
if ($struct->parts[1]->encoding ==3) {
$arr["body"] = imap_base64($text);
$html = 1;
}
else if ($struct->parts[1]->encoding == 4 ) {
$arr["body"] = imap_qprint($text);
$html = 1;
}
else {
$arr["body"] = $text;
$html = 1;
}
}
elseif (strtolower($type[0])=="plain" || strtolower($type[1])=="plain")
{
for ($i=0;$i<count($type);$i++)
{
$text=imap_fetchbody($this->stream, $this->msg_uid, $i+1, FT_UID);
if ($arr["body"]=='' && $text && strtolower($struct->parts[$i]->subtype)=="plain")
{
$arr["body"]=$text;
}
}
}
elseif (strtolower($type[0])=="rfc822" || strtolower($type[1])=="rfc822" || strtolower($type[2])=="rfc822")
{
for ($i=1;$i<count($type);$i++)
{
if (strtolower($type[0])=="alternative")
{
for($z=0;$z< count($struct->parts);$z++)
{
if ($struct->parts[$z+1]->ifdescription)
{
$arr["parts"][$z]=$this->build_url("$download_action&mailbox=$this->mailbox&msg_uid=$this->msg_uid&part_no=".($z+1)."&filename=".$struct->parts[$z+1]->description."", $struct->parts[$z+1]->description);
}
}
}
}
}
}
if (strtolower($struct->parts[0]->subtype)=="alternative")
{
for($i=0; $i< count($struct->parts); $i++) {
$type[$i]=$struct->parts[$i]->parts[1]->subtype;
}
if (strtolower($type[0])=="html")
{
$text=imap_fetchbody($this->stream, $this->msg_uid, "1.2", FT_UID);
if ($struct->parts[0]->parts[1]->encoding ==3) {
$arr["body"] = imap_base64($text);
$arr["body"];
$html = 1;
}
else if ($struct->parts[0]->parts[1]->encoding == 4 ) {
$arr["body"] = imap_qprint($text);
$html = 1;
}
else {
$arr["body"] = $text;
$html = 1;
}
}
elseif (strtolower($type[1])=="html")
{
$text=imap_fetchbody($this->stream, $this->msg_uid, "1", FT_UID);
if ($struct->parts[0]->parts[1]->encoding ==3) {
$arr["body"] = imap_base64($text);
$html = 1;
}
else if ($struct->parts[0]->parts[1]->encoding == 4 ) {
$arr["body"] = imap_qprint($text);
$html = 1;
}
else {
$arr["body"] = $text;
$html = 1;
}
}
for($z=1; $z< count($struct->parts); $z++) {
$id=substr($struct->parts[$z]->id,1,-1);
foreach($struct->parts[$z]->parameters as $attr)
if(strtolower($attrib->attribute) == 'name') {
$filenam = $this->decodeHeader($attrib->value);
break;
}
$arr["body"]=str_replace("src=\"cid:".$id."\"","src=\"http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/viewimage.php?uid=".$this->msg_uid."&part=$z&filename=$filenam&host=$_SESSION[host]&protocol=$_SESSION[protocol]&port=$_SESSION[port]&userid=$_SESSION[userid]&userpassword=$_SESSION[userpassword]\"",$arr["body"]);
}
}
}
else {
if($struct->parts[0]->encoding == 3) {
    $arr["body"] = imap_base64(imap_fetchbody($this->stream, $this->msg_uid, 1, FT_UID));
    if(strtolower($struct->parts[0]->subtype) == 'html') $html = 1;
} else if($struct->parts[0]->encoding == 4) {
    $arr["body"] = imap_qprint(imap_fetchbody($this->stream, $this->msg_uid, 1, FT_UID));
    if(strtolower($struct->parts[0]->subtype) == 'html') $html = 1;
} else {
    if($struct->encoding == 3) {
    $arr["body"] = imap_base64(imap_fetchbody($this->stream, $this->msg_uid, 1, FT_UID));
    if(strtolower($struct->subtype) == 'html') $html = 1;
} else if($struct->encoding == 4) {
    $arr["body"] = imap_qprint(imap_fetchbody($this->stream, $this->msg_uid, 1, FT_UID));
    if(strtolower($struct->subtype) == 'html') $html = 1;
} else { 
    $arr["body"] = imap_fetchbody($this->stream, $this->msg_uid, 1, FT_UID);
    if(strtolower($struct->subtype) == 'html') $html = 1;
}
}
}
}
//this next line is the test line to print all the body text as one text document
//$arr["body"]=imap_body($this->stream,$this->msg_uid,FT_UID);
//remove the above line in reality
if(!$html) {
            $arr["body"] = str_replace("\r\n", "<BR>", $arr["body"]);
   $arr["body"] = eregi_replace( "http://([-a-z0-9\_\./~@?=%(&amp;)|]+)", "<A HREF=\"http://\\1\">http://\\1</A>", $arr["body"]);
   $arr["body"] = eregi_replace( "ftp://([-a-z0-9\_\./~@?=%&amp;]+)", "<A HREF=\"ftp://\\1\">ftp://\\1</A>", $arr["body"]);
   $arr["body"] = eregi_replace( "([-a-z0-9\_\.]+)@([-a-z0-9\_\.]+)", "<A HREF=\"$PHP_SELF?$mail_action&email=\\1@\\2\">\\1@\\2</A>", $arr["body"]);
}
    $arr["body"] = preg_replace('/<style[^>]*>.*<\/style>/Usi', '', $arr["body"]);
$arr["body"] = preg_replace('/<script[^>]*>.*<\/script>/Usi', '', $arr["body"]);
$arr["body"] = preg_replace('/<embed[^>]*>.*<\/embed>/Usi', '', $arr["body"]);
$arr["body"] = preg_replace('/<iframe[^>]*>.*<\/iframe>/Usi', '', $arr["body"]);
$arr["body"] = preg_replace('/<meta[^>]*>/Usi', '', $arr["body"]);
$arr["body"] = preg_replace('/<object[^>]*>.*<\/object>/Usi', '', $arr["body"]);
/*End of the message body handling area*/
/***************************************/

/*This is the start of all attachment handling in the main message */
/******************************************************************/
if ($struct->ifdparameters)
{
for($i=0; $i< count($struct->dparameters); $i++) {
if (strtolower($struct->dparameters[$i]->attribute) == "filename"){
$filename= $this->decodeHeader($struct->dparameters[$i]->value);
$arr["parts"][$i] = $this->build_url("$download_action&mailbox=$this->mailbox&msg_uid=$this->msg_uid&part_no=$i&filename=$filename", $filename);
}
}
}
$num=count($struct->parts);
for($i=0; $i< $num; $i++) {
if (strtolower($struct->parts[$i]->disposition)=="attachment" )//|| strtolower($struct->parts[$i]->disposition)=="rfc822")
{
for($z=0; $z< count($struct->parts[$i]->dparameters); $z++) {
if (strtolower($struct->parts[$i]->dparameters[$z]->attribute) == "filename"){
$filename= $this->decodeHeader($struct->parts[$i]->dparameters[$z]->value);
$arr["parts"][$i] = $this->build_url("$download_action&mailbox=$this->mailbox&msg_uid=$this->msg_uid&part_no=$i&filename=$filename", $filename);
}
}
}
else
{
foreach($struct->parts[$i]->parameters as $attr)
if(strtolower($attr->attribute) == 'name') {
$filename = $this->decodeHeader($attr->value);
break;
}
if ($filename){
            $arr["parts"][$i] = $this->build_url("$download_action&mailbox=$this->mailbox&msg_uid=$this->msg_uid&part_no=$i&filename=$filename", $filename);
        }
    }
}
/*The attachment handling stops here*/
/************************************/
return $arr;
    }   

H.264参考软件JM12.2RC代码详细流程

代码:JM12.2.编码结构:IPP。GOP:3. 跟踪代码:(注:表示编码主流程,表示RC流程) --------------------------------------------------...
  • leixiaohua1020
  • leixiaohua1020
  • 2013年09月24日 16:14
  • 7090

HM编码器代码阅读(5)——参考帧的选择

参考帧是怎么来的以及如何设置这个问题困扰了我很久,现在理出了一点头绪。 参考帧的选择主要涉及几个函数: selectReferencePictureSet createExplicitRefer...
  • NB_vol_1
  • NB_vol_1
  • 2016年04月12日 17:53
  • 1930

《无参考视频质量评价方法研究 》

1.
  • u012711366
  • u012711366
  • 2014年09月16日 20:45
  • 890

HEVC的参考帧管理

HEVC中提出了RPS的概念来对参考mhm
  • lessconcern
  • lessconcern
  • 2014年06月20日 22:39
  • 1439

jsoup使用例子(仅作参考)

package com.gxzhuangxing.seed.modules.release.utils; import java.io.BufferedReader; import java.io.I...
  • qq_30034681
  • qq_30034681
  • 2015年08月12日 15:03
  • 477

ArcGIS空间参考

ArcGIS空间参考   转自:http://www.gdsky.com.cn/news/showatc.asp?id=1722     空间参考描述了一个地物在地球上的...
  • marstonyjiang
  • marstonyjiang
  • 2016年07月15日 10:36
  • 534

笔记 计算机网络-OSI参考模型

OSI参考模型   OSI全称Open System Interconnection,译为开放式系统互联。 国际标准化组织(ISO)制定了OSI模型,该模型定义了不同计算机互联的标准,是设计和描...
  • Cytosine
  • Cytosine
  • 2017年03月03日 18:59
  • 576

无参考图像的质量评价

转自: http://nkwavelet.blog.163.com/blog/static/227756038201461532247117         在无参考图像的质量评价中,图像的清晰度是...
  • X_windy
  • X_windy
  • 2016年12月06日 21:22
  • 289

OSI 参考模型与TCP/IP 参考模型的比较

OSI 参考模型与TCP/IP 参考模型的比较     【尊重原创,转载请注明出处】http://blog.csdn.net/guyuealian/article/details/51187240 ...
  • guyuealian
  • guyuealian
  • 2016年04月29日 09:56
  • 2736

GIS中的空间参考

GIS一般都是研究的基于地球的某个区域,例如一个国家
  • mytudousi
  • mytudousi
  • 2014年06月13日 15:40
  • 5041
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:一个imap的例子 - 参考,代码仅参考,复制后不可用
举报原因:
原因补充:

(最多只允许输入30个字)