最好的邮件编码解码类
编码
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,"=?");
}
return $newresult.$string;
}
function decode_header($header) {
$headers = explode("\r\n",$header);
$decodedheaders = Array();
for($i=0;$i
if(strpos($thisheader,": ") === false) {
$decodedheaders[$lasthead] .= " $thisheader";
} else {
$dbpoint = strpos($thisheader,": ");
$headname = strtolower(substr($thisheader,0,$dbpoint));
$headvalue = trim(substr($thisheader,$dbpoint+1));
if($decodedheaders[$headname] != "") $decodedheaders[$headname] .= "; $headvalue";
else $decodedheaders[$headname] = $headvalue;
$lasthead = $headname;
}
}
return $decodedheaders;
}
function fetch_structure($email) {
$ARemail = Array();
$separador = "\r\n\r\n";
$header = trim(substr($email,0,strpos($email,$separador)));
$bodypos = strlen($header)+strlen($separador);
$body = substr($email,$bodypos,strlen($email)-$bodypos);
$ARemail["header"] = $header; $ARemail["body"] = $body;
return $ARemail;
}
function get_names($strmail) {
$ARfrom = Array();
$strmail = stripslashes(ereg_replace("\t","",ereg_replace("\n","",ereg_replace("\r","",$strmail))));
if(trim($strmail) == "") return $ARfrom;
$armail = Array();
$counter = 0; $inthechar = 0;
$chartosplit = ",;"; $protectchar = "\""; $temp = "";
$lt = "";
$closed = 1;
for($i=0;$i
if($thischar == $lt && $closed) $closed = 0;
if($thischar == $gt && !$closed) $closed = 1;
if($thischar == $protectchar) $inthechar = ($inthechar)?0:1;
if(!(strpos($chartosplit,$thischar) === false) && !$inthechar && $closed) {
$armail[] = $temp; $temp = "";
} else
$temp .= $thischar;
}
if(trim($temp) != "")
$armail[] = trim($temp);
for($i=0;$i
if($thisPart != "") {
if (eregi("(.*)", $thisPart, $regs)) {
$email = trim($regs[2]);
$name = trim($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", trim($name));
$name = eregi_replace("^\((.*)\)$", "\\1", $name);
if ($name == "") $name = $email;
if ($email == "") $email = $name;
$ARfrom[$i]["name"] = $this->decode_mime_string($name);
$ARfrom[$i]["mail"] = $email;
unset($name);unset($email);
}
}
return $ARfrom;
}
function build_alternative_body($ctype,$body) {
global $mime_show_html;
$boundary = $this->get_boundary($ctype);
$part = $this->split_parts($boundary,$body);
$thispart = ($mime_show_html)?$part[1]:$part[0];
$email = $this->fetch_structure($thispart);
$header = $email["header"];
$body = $email["body"];
$headers = $this->decode_header($header);
$body = $this->compile_body($body,$headers["content-transfer-encoding"]);
return $body;
}
function build_related_body($ctype,$body) {
global $mime_show_html,$sid,$lid,$ix,$folder;
$Rtype = trim(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;$i
$header = $email["header"];
$body = $email["body"];
$headers = $this->decode_header($header);
$ctype = $headers["content-type"];
$cid = $headers["content-id"];
$Actype = split(";",$headers["content-type"]);
$types = split("/",$Actype[0]); $rctype = strtolower($Actype[0]);
if($rctype == "multipart/alternative")
$msgbody = $this->build_alternative_body($ctype,$body);
elseif($rctype == "text/plain" && strpos($headers["content-disposition"],"name") === false) {
$body = $this->compile_body($body,$headers["content-transfer-encoding"]);
$msgbody = $this->build_text_body($body);
} elseif($rctype == "text/html" && strpos($headers["content-disposition"],"name") === false) {
$body = $this->compile_body($body,$headers["content-transfer-encoding"]);
if(!$mime_show_html) $body = $this->build_text_body(strip_tags($body));
$msgbody = $body;
} else {
$thisattach = $this->build_attach($header,$body,$boundary,$i);
if($cid != "") {
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["part"]."&filename=".urlencode($thisattach["name"]);
$msgbody = str_replace($cid,$thisfile,$msgbody);
}
}
}
return $msgbody;
}
function linesize($message="", $length=70) {
$line = explode("\r\n",$message);
unset($message);
for ($i=0 ;$i $line_part = explode(" ",trim($line[$i]));
unset($buf);
for ($e = 0; $e
if ($e == 0) $buf .= $line_part[$e];
else $buf .= " ".$line_part[$e];
if (strlen($buf) > $length and $buf_o != "") {
$message .= "$buf_o\r\n";
$buf = $line_part[$e];
}
}
$message .= "$buf\r\n";
}
return($message);
}
function build_text_body($body) {
return "\n
".$this->make_link_clickable($this->linesize(htmlspecialchars($body),85))."
}
function decode_qp($text) {
$text = quoted_printable_decode($text);
/*
$text = str_replace("\r","",$text);
$text = ereg_replace("=\n", "", $text);
$text = str_replace("\n","\r\n",$text);
*/
$text = ereg_replace("=\r", "\r", $text);
return $text;
}
function make_link_clickable($text){
$text = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
"\\1://\\2\\3", $text);
$text = eregi_replace("([0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3})","\\1", $text);
return $text;
}
function process_message($header,$body) {
global $mime_show_html;
$mail_info = $this->get_mail_info($header);
$ctype = $mail_info["content-type"];
$ctenc = $mail_info["content-transfer-encoding"];
if($ctype == "") $ctype = "text/plain";
$type = $ctype;
$ctype = split(";",$ctype);
$types = split("/",$ctype[0]);
$maintype = strtolower($types[0]);
$subtype = strtolower($types[1]);
switch($maintype) {
case "text":
$body = $this->compile_body($body,$ctenc);
switch($subtype) {
case "html":
if(!$mime_show_html)
$body = $this->build_text_body(strip_tags($body));
$msgbody = $body;
break;
default:
$msgbody = $this->build_text_body($body);
break;
}
break;
case "multipart":
switch($subtype) {
case "mixed":
$boundary = $this->get_boundary($type);
$part = $this->split_parts($boundary,$body);
for($i=0;$i
if($thispart != "") {
$email = $this->fetch_structure($thispart);
$header = $email["header"];
$body = $email["body"];
$headers = $this->decode_header($header);
$ctype = $headers["content-type"];
$Actype = split(";",$headers["content-type"]);
$types = split("/",$Actype[0]); $rctype = strtolower($Actype[0]);
if($rctype == "multipart/alternative")
$msgbody = $this->build_alternative_body($ctype,$body);
elseif($rctype == "text/plain" && strpos($headers["content-disposition"],"name") === false) {
$msgbody = $this->build_text_body($this->compile_body($body,$headers["content-transfer-encoding"]));
} elseif($rctype == "text/html" && strpos($headers["content-disposition"],"name") === false) {
$body = $this->compile_body($body,$headers["content-transfer-encoding"]);
if(!$mime_show_html)
$body = $this->build_text_body(strip_tags($body));
$msgbody = $body;
} elseif($rctype == "multipart/related" && strpos($headers["content-disposition"],"name") === false) {
$msgbody = $this->build_related_body($ctype,$body);
} else {
$thisattach = $this->build_attach($header,$body,$boundary,$i);
}
}
}
break;
case "alternative":
$msgbody = $this->build_alternative_body($ctype[1],$body);
break;
case "related":
$msgbody = $this->build_related_body($type,$body);
break;
default:
$thisattach = $this->build_attach($header,$body,"",0);
}
break;
default:
$thisattach = $this->build_attach($header,$body,"",0);
}
return $msgbody;
}
function build_attach($header,$body,$boundary,$part) {
global $mail,$temporary_directory,$userfolder;
$headers = $this->decode_header($header);
$cdisp = $headers["content-disposition"];
$ctype = $headers["content-type"]; $ctype2 = explode(";",$ctype); $ctype2 = $ctype2[0];
$Atype = split("/",$ctype);
$Acdisp = split(";",$cdisp);
$tenc = $headers["content-transfer-encoding"];
if($temp) $dir_to_save = $userfolder; //"temporary_files/";
if($Atype[0] == "message") {
$divpos = strpos($body,"\n\r");
$attachheader = substr($body,0,$divpos);
$attachheaders = $this->decode_header($attachheader);
$filename = $this->decode_mime_string($attachheaders["subject"]);
if($filename == "")
$filename = uniqid("");
$filename = substr(ereg_replace("[^A-Za-z0-9]","_",$filename),0,20).".eml";
} else {
$fname = $Acdisp[1];
$filename = substr($fname,strpos($fname,"filename=")+9,strlen($fname));
if($filename == "")
$filename = substr($ctype,strpos($ctype,"name=")+5,strlen($ctype));
if(substr($filename,0,1) == "\"" && substr($filename,-1) == "\"")
$filename = substr($filename,1,strlen($filename)-2);
$filename = $this->decode_mime_string($filename);
}
if($Atype[0] != "message")
$body = $this->compile_body($body,$tenc);
$indice = count($this->content["attachments"]);
$this->content["attachments"][$indice]["name"] = $filename;
$this->content["attachments"][$indice]["size"] = strlen($body);
$this->content["attachments"][$indice]["temp"] = $temp;
$this->content["attachments"][$indice]["content-type"] = $ctype2; //$Atype[0];
$this->content["attachments"][$indice]["content-disposition"] = $Acdisp[0];
$this->content["attachments"][$indice]["boundary"] = $boundary;
$this->content["attachments"][$indice]["part"] = $part;
return $this->content["attachments"][$indice];
}
function compile_body($body,$enctype) {
$enctype = explode(" ",$enctype); $enctype = $enctype[0];
if(strtolower($enctype) == "base64")
$body = base64_decode($body);
elseif(strtolower($enctype) == "quoted-printable")
$body = $this->decode_qp($body);
return $body;
}
function download_attach($header,$body,$down=1) {
$headers = $this->decode_header($header);
$cdisp = $headers["content-disposition"];
$ctype = $headers["content-type"];
$type = split(";",$ctype); $type = $type[0];
$Atype = split("/",$ctype);
$Acdisp = split(";",$cdisp);
$tenc = strtolower($headers["content-transfer-encoding"]);
if($Atype[0] == "message") {
$divpos = strpos($body,"\n\r");
$attachheader = substr($body,0,$divpos);
$attachheaders = $this->decode_header($attachheader);
$filename = $this->decode_mime_string($attachheaders["subject"]);
if($filename == "")
$filename = uniqid("");
$filename = substr(ereg_replace("[^A-Za-z0-9]","_",$filename),0,20);
$filename .= ".eml";
} else {
$fname = $Acdisp[1];
$filename = substr($fname,strpos(strtolower($fname),"filename=")+9,strlen($fname));
if($filename == "")
$filename = substr($ctype,strpos(strtolower($ctype),"name=")+5,strlen($ctype));
if(substr($filename,0,1) == "\"" && substr($filename,-1) == "\"")
$filename = substr($filename,1,strlen($filename)-2);
$filename = $this->decode_mime_string($filename);
}
if($Atype[0] != "message")
$body = $this->compile_body($body,$tenc);
$content_type = ($down)?"application/octet-stream":strtolower($type);
$filesize = strlen($body);
header("Content-Type: $content_type; name=\"$filename\"\r\n"
."Content-Length: $filesize\r\n");
$cdisp = ($down)?"attachment":"inline";
header("Content-Disposition: $cdisp; filename=\"$filename\"\r\n");
echo($body);
}
function get_mail_info($header) {
$myarray = Array();
$headers = $this->decode_header($header);
/*
echo("
");<br> print_r($headers);<br> echo("
*/
$message_id = $headers["message-id"];
if(substr($message_id,0,1) == "")
$message_id = substr($message_id,1,strlen($message_id)-2);
$myarray["content-type"] = $headers["content-type"];
$myarray["content-transfer-encoding"] = str_replace("GM","-",$headers["content-transfer-encoding"]);
$myarray["message-id"] = $message_id;
$received = $headers["received"];
if($received != "") {
$received = explode(";",$received);
$mydate = $received[1];
} else
$mydate = $headers["date"];
$myarray["date"] = $this->build_mime_date($mydate);
$myarray["subject"] = $this->decode_mime_string($headers["subject"]);
$myarray["from"] = $this->get_names($headers["from"]);
$myarray["to"] = $this->get_names($headers["to"]);
$myarray["cc"] = $this->get_names($headers["cc"]);
$myarray["status"] = $headers["status"];
$myarray["read"] = ($headers["status"] == "N")?0:1;
return $myarray;
}
function build_mime_date($mydate) {
$mydate = explode(",",$mydate);
$mydate = trim($mydate[count($mydate)-1]);
$parts = explode(" ",$mydate);
if(count($parts) $day = $parts[0];
switch(strtolower($parts[1])) {
case "jan": $mon = 1; break;
case "feb": $mon = 2; break;
case "mar": $mon = 3; break;
case "apr": $mon = 4; break;
case "may": $mon = 5; break;
case "jun": $mon = 6; break;
case "jul": $mon = 7; break;
case "aug": $mon = 8; break;
case "sep": $mon = 9; break;
case "oct": $mon = 10; break;
case "nov": $mon = 11; break;
case "dec": $mon = 12; break;
}
$year = $parts[2];
$ahours = explode(":",$parts[3]);
$hour = $ahours[0]; $min = $ahours[1]; $sec = $ahours[2];
return mktime ($hour, $min, $sec, $mon, $day, $year);
}
function initialize($email) {
$email = $this->fetch_structure($email);
$body = $email["body"];
$header = $email["header"];
$mail_info = $this->get_mail_info($header);
$this->content["headers"] = $header;
$this->content["date"] = $mail_info["date"];
$this->content["subject"] = $mail_info["subject"];
$this->content["message-id"] = $mail_info["message-id"];
$this->content["from"] = $mail_info["from"];
$this->content["to"] = $mail_info["to"];
$this->content["cc"] = $mail_info["cc"];
$this->content["body"] = $this->process_message($header,$body);
$this->content["read"] = $mail_info["read"];
}
function split_parts($boundary,$body) {
$startpos = strpos($body,"$boundary")+strlen("$boundary")+2;
$lenbody = strpos($body,"\r\n$boundary--") - $startpos;
$body = substr($body,$startpos,$lenbody);
return split($boundary."\r\n",$body);
}
function get_boundary($ctype){
$boundary = trim(substr($ctype,strpos(strtolower($ctype),"boundary=")+9,strlen($ctype)));
$boundary = split(";",$boundary);$boundary = $boundary[0];
if(substr($boundary,0,1) == "\"" && substr($boundary,-1) == "\"")
$boundary = substr($boundary,1,strlen($boundary)-2);
$boundary = "--".$boundary;
return $boundary;
}
function set_as($email,$type=1) {
$status = ($type)?"Y":"N";
$tempmail = $this->fetch_structure($email);
$thisheader = $tempmail["header"];
$mail_info = $this->get_mail_info($thisheader);
$decoded_headers = $this->decode_header($thisheader);
while(list($key,$val) = each($decoded_headers))
if (eregi("status",$key)) {
$newmail .= ucfirst($key).": $status\r\n"; $headerok = 1;
} else $newmail .= ucfirst($key).": ".trim($val)."\r\n";
if(!$headerok) $newmail .= "Status: $status\r\n";
$newmail = trim($newmail)."\r\n\r\n".trim($tempmail["body"]);
return $newmail;
}
}
?>

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

“你的组织要求你更改PIN消息”将显示在登录屏幕上。当在使用基于组织的帐户设置的电脑上达到PIN过期限制时,就会发生这种情况,在该电脑上,他们可以控制个人设备。但是,如果您使用个人帐户设置了Windows,则理想情况下不应显示错误消息。虽然情况并非总是如此。大多数遇到错误的用户使用个人帐户报告。为什么我的组织要求我在Windows11上更改我的PIN?可能是您的帐户与组织相关联,您的主要方法应该是验证这一点。联系域管理员会有所帮助!此外,配置错误的本地策略设置或不正确的注册表项也可能导致错误。即

Windows11将清新优雅的设计带到了最前沿;现代界面允许您个性化和更改最精细的细节,例如窗口边框。在本指南中,我们将讨论分步说明,以帮助您在Windows操作系统中创建反映您的风格的环境。如何更改窗口边框设置?按+打开“设置”应用。WindowsI转到个性化,然后单击颜色设置。颜色更改窗口边框设置窗口11“宽度=”643“高度=”500“>找到在标题栏和窗口边框上显示强调色选项,然后切换它旁边的开关。若要在“开始”菜单和任务栏上显示主题色,请打开“在开始”菜单和任务栏上显示主题

默认情况下,Windows11上的标题栏颜色取决于您选择的深色/浅色主题。但是,您可以将其更改为所需的任何颜色。在本指南中,我们将讨论三种方法的分步说明,以更改它并个性化您的桌面体验,使其具有视觉吸引力。是否可以更改活动和非活动窗口的标题栏颜色?是的,您可以使用“设置”应用更改活动窗口的标题栏颜色,也可以使用注册表编辑器更改非活动窗口的标题栏颜色。若要了解这些步骤,请转到下一部分。如何在Windows11中更改标题栏的颜色?1.使用“设置”应用按+打开设置窗口。WindowsI前往“个性化”,然

您是否在Windows安装程序页面上看到“出现问题”以及“OOBELANGUAGE”语句?Windows的安装有时会因此类错误而停止。OOBE表示开箱即用的体验。正如错误提示所表示的那样,这是与OOBE语言选择相关的问题。没有什么可担心的,你可以通过OOBE屏幕本身的漂亮注册表编辑来解决这个问题。快速修复–1.单击OOBE应用底部的“重试”按钮。这将继续进行该过程,而不会再打嗝。2.使用电源按钮强制关闭系统。系统重新启动后,OOBE应继续。3.断开系统与互联网的连接。在脱机模式下完成OOBE的所

任务栏缩略图可能很有趣,但它们也可能分散注意力或烦人。考虑到您将鼠标悬停在该区域的频率,您可能无意中关闭了重要窗口几次。另一个缺点是它使用更多的系统资源,因此,如果您一直在寻找一种提高资源效率的方法,我们将向您展示如何禁用它。不过,如果您的硬件规格可以处理它并且您喜欢预览版,则可以启用它。如何在Windows11中启用任务栏缩略图预览?1.使用“设置”应用点击键并单击设置。Windows单击系统,然后选择关于。点击高级系统设置。导航到“高级”选项卡,然后选择“性能”下的“设置”。在“视觉效果”选

在Windows11上的显示缩放方面,我们都有不同的偏好。有些人喜欢大图标,有些人喜欢小图标。但是,我们都同意拥有正确的缩放比例很重要。字体缩放不良或图像过度缩放可能是工作时真正的生产力杀手,因此您需要知道如何对其进行自定义以充分利用系统功能。自定义缩放的优点:对于难以阅读屏幕上的文本的人来说,这是一个有用的功能。它可以帮助您一次在屏幕上查看更多内容。您可以创建仅适用于某些监视器和应用程序的自定义扩展配置文件。可以帮助提高低端硬件的性能。它使您可以更好地控制屏幕上的内容。如何在Windows11

屏幕亮度是使用现代计算设备不可或缺的一部分,尤其是当您长时间注视屏幕时。它可以帮助您减轻眼睛疲劳,提高易读性,并轻松有效地查看内容。但是,根据您的设置,有时很难管理亮度,尤其是在具有新UI更改的Windows11上。如果您在调整亮度时遇到问题,以下是在Windows11上管理亮度的所有方法。如何在Windows11上更改亮度[10种方式解释]单显示器用户可以使用以下方法在Windows11上调整亮度。这包括使用单个显示器的台式机系统以及笔记本电脑。让我们开始吧。方法1:使用操作中心操作中心是访问

Windows上的激活过程有时会突然转向显示包含此错误代码0xc004f069的错误消息。虽然激活过程已经联机,但一些运行WindowsServer的旧系统可能会遇到此问题。通过这些初步检查,如果这些检查不能帮助您激活系统,请跳转到主要解决方案以解决问题。解决方法–关闭错误消息和激活窗口。然后,重新启动计算机。再次从头开始重试Windows激活过程。修复1–从终端激活从cmd终端激活WindowsServerEdition系统。阶段–1检查Windows服务器版本您必须检查您使用的是哪种类型的W
