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

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

答案:function build_text_body($body) {
        return "\n<pre>".$this->make_link_clickable($this->linesize(htmlspecialchars($body),85))."</pre>\n";
    }

    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:]#?/&=])",
            "<a class=\"autolink\" href=>        $text = eregi_replace("([0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3})","<a class=\"autolink\"  href=>        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<count($part);$i++) {
                    $thispart = trim($part[$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[&qu

上一个:用PHP发电子邮件2
下一个:用PHP读取IMAP邮件

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,