首页 > php教程 > php手册 > 正文

最好的邮件编码解码类,再没有比这个好的了贴不下了1

WBOY
发布: 2016-06-13 10:27:19
原创
1052 人浏览过

class mime_decode { var $content = Array(); function mime_encode_headers($string) { if($string == "") return; if(!eregi("^([[:print:]]*)$",$string)) $string = "=?ISO-8859-1?Q?".str_replace(" ","_",str_replace("%","=",urlencode($string)))."?="; return $string; } function decode_mime_string($string) { if(($pos = strpos($string,"=?")) === false) return $string; while(!($pos === false)) { $newresult .= substr($string,0,$pos); $string = substr($string,$pos 2,strlen($string)); $intpos = strpos($string,"?"); $charset = substr($string,0,$intpos); $enctype = strtolower(substr($string,$intpos 1,1)); $string = substr($string,$intpos 3,strlen($string)); $endpos = strpos($string,"?="); $mystring = substr($string,0,$endpos); $string = substr($string,$endpos 2,strlen($string)); if($enctype == "q") { $mystring = str_replace("_"," ",$mystring); $mystring = $this->decode_qp($mystring); } else if ($enctype == "b") $mystring = base64_decode($mystring); $newresult .= $mystring; $pos = strpos($string,"=?"); } 返回 $newresult.$string; } 函数decode_header($header) { $headers = 爆炸(" ",$header); $decodedheaders = Array(); for($i=0;$i"; $close = 1; for($i=0;$i", $thisPart, $ regs)) { $email = 修剪($regs[2]); $name = 修剪($regs[1]); } else { if (eregi("([-a-z0-9_$ .] @[- a-z0-9_.] [-a-z0-9_] )((.*))", $thisPart, $regs)) { $email = $regs[1]; $name = $regs[2]; } else $email = $thisPart; } $email = eregi_replace("^$", "1", $email); $name = eregi_replace("^"(.*)"$", "1",修剪($name)); $name = eregi_replace("^((.*))$", "1", $name); if ($name == "") $name = $email; == "") $email = $name; $ARfrom[$i]["name"] = $this->decode_mime_string($name); $ARfrom[$i]["mail"] = $email; $name);unset($email); } } return $ARfrom; 函数 build_alternative_body($ctype,$body) { global $mime_show_html; $boundary = $this->get_boundary($ctype); >split_parts($boundary,$body); $thispart = ($mime_show_html)?$part[1]:$part[0]; $email = $this->fetch_struct($thispart);标题"]; $body = $email["body"]; $headers = $this->decode_header($header); $body = $this->compile_body($body,$headers["内容传输编码"]);返回$body; }函数 build_lated_body($ctype,$body) { 全局 $mime_show_html,$sid,$lid,$ix,$folder; $Rtype = 修剪(substr($ctype,strpos($ctype,"type=") 5,strlen($ctype))); if(strpos($Rtype,";") != 0) $Rtype = substr($Rtype,0,strpos($Rtype,";")); if(substr($Rtype,0,1) == """ && substr($Rtype,-1) == """) $Rtype = substr($Rtype,1,strlen($Rtype)-2); $boundary = $this->get_boundary($ctype); $part = $this->split_parts($boundary,$body); for($i=0;$ifetch_struct($part[$i]); $header = $email["header"]; $body = $email["body"]; $headers = $this- >decode_header($header); $ctype = $headers["内容类型"]; $cid = $headers["内容ID"]; $Actype = split(";",$headers["内容类型" ]); $types = split("/",$Actype[0]); $rctype = strtolower($Actype[0]); if($rctype == "多部分/替代") $msgbody = $this-> build_alternative_body($ctype,$body); elseif($rctype == "text/plain" && strpos($headers["content-disposition"],"name") === false) { $body = $this-> compile_body($body,$headers["内容传输编码"]); $msgbody = $this->build_text_body($body); } elseif($rctype == "text/html" && strpos($headers[")内容处置"],"名称") === false) { $body = $this->compile_body($body,$headers["内容传输编码"]); if(!$mime_show_html) $body = $this->build_text_body(strip_tags($body)); $msgbody = $body; } else { $thisattach = $this->build_attach($header,$body,$boundary,$i); "") { if(substr($cid,0,1) == "") $cid = substr($cid,1,strlen($cid)-2); $cid = "cid:$cid"; $thisfile = "download.php?sid=$sid&lid=$lid&folder=".urlencode($folder)."&ix=".$ix."&bound=".base64_encode($thisattach["boundary"])."&part =".$thisattach["部分"]."&filename=".urlencode($thisattach["名称"]); $msgbody = str_replace($cid,$thisfile,$msgbody);返回 $msgbody; } 函数 linesize($message="", $length=70) { $line =explode(" ",$message); unset($message); for ($i=0 ;$i $length and $buf_o != "") { $message .= "$buf_o "; $buf = $line_part[$e]; } } $message .= "$buf "; } return($message); }

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板