当前位置:编程学习 > php >>

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

答案:<?
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<count($headers);$i++) {
            $thisheader = $headers[$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 = "<"; $gt = ">";
        $closed = 1;

        for($i=0;$i<strlen($strmail);$i++) {
            $thischar = $strmail[$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) != "")
            $a

上一个:发现一个发送mime邮件的类2
下一个:用PHP发电子邮件1,很简单?我也是这样认为的...

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,