The best email encoding and decoding class is no better than this one.

Source: Internet
Author: User
SyntaxHighlighter. all (); news & nbsp; | & nbsp; Security & nbsp; | & nbsp; Forum & nbsp; | & nbsp; download & nb

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 ("", $ header); $ decodedheaders = Array (); for ($ I = 0; $ I ", $ 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 =" ") $ na Me = $ 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 ($ cty Pe); 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 Fetch_structure ($ part [$ 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 ); elsei F ($ 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) = "<" & substr ($ cid,-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 ("", $ message); unset ($ message); for ($ I = 0; $ I <count ($ line); $ I ++) {$ line_part = explode ("", trim ($ line [$ I]); unset ($ buf ); for ($ e = 0; $ e $ Length and $ buf_o! = "") {$ Message. = "$ buf_o"; $ buf = $ line_part [$ e] ;}}$ message. = "$ buf";} return ($ message );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.