X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fmime.php;h=ef00957c74b2519bb77c3eeb645d7466fde66b63;hb=9d157cec2821461fe4d348a47e2312db5e84c052;hp=f81d08f07efb21981ff5044b810f0c3ee22084a3;hpb=78509c544d86d8e4260ec93faed8d2a17362082b;p=squirrelmail.git diff --git a/functions/mime.php b/functions/mime.php index f81d08f0..ef00957c 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -1,29 +1,38 @@ -" . nl2br($tmpbody) . ""; + $body = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]); + $charset = $message["ENTITIES"][$ent_num]["CHARSET"]; } // add other primary displaying message types here else { // find any type that's displayable if (containsType($message, "text", "any_type", $ent_num)) { - $tmpbody = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]); - $body .= "" . nl2br($tmpbody) . ""; + $body = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]); + $charset = $message["ENTITIES"][$ent_num]["CHARSET"]; } else if (containsType($message, "message", "any_type", $ent_num)) { - $tmpbody = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]); - $body .= "" . nl2br($tmpbody) . ""; + $body = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]); + $charset = $message["ENTITIES"][$ent_num]["CHARSET"]; } } - /** If there are other types that shouldn't be formatted, add them here **/ + /** If there are other types that shouldn't be formatted, add + them here **/ if ($message["ENTITIES"][$ent_num]["TYPE1"] != "html") - $body = translateText($body); + $body = translateText($body, $wrap_at, $charset); - $body .= "
Download this as a file

"; + + $body .= "
". _("Download this as a file") ."

"; /** Display the ATTACHMENTS: message if there's more than one part **/ if (count($message["ENTITIES"]) > 1) { @@ -188,22 +200,65 @@ function decodeBody($body, $encoding) { $encoding = strtolower($encoding); - if ($encoding == "us-ascii") { - $newbody = $body; // if only they all were this easy - - } else if ($encoding == "quoted-printable") { - echo "$body"; - $body = ereg_replace("=3D", "=", $body); - $body = ereg_replace("=\n", "", $body); - $body = ereg_replace("=20", "\n", $body); - $newbody= $body; + if ($encoding == "quoted-printable") { + $body = quoted_printable_decode($body); + while (ereg("=\n", $body)) + $body = ereg_replace ("=\n", "", $body); } else if ($encoding == "base64") { - $newbody = base64_decode($body); + $body = base64_decode($body); + } - } else { - $newbody = $body; + // All other encodings are returned raw. + return $body; + } + + + // This functions decode strings that is encoded according to + // RFC1522 (MIME Part Two: Message Header Extensions for Non-ASCII Text). + function decodeHeader ($string) { + if (eregi('=\?([^?]+)\?(q|b)\?([^?]+)\?=', + $string, $res)) { + if (ucfirst($res[2]) == "B") { + $replace = base64_decode($res[3]); + } else { + $replace = ereg_replace("_", " ", $res[3]); + $replace = quoted_printable_decode($replace); + } + + $replace = charset_decode ($res[1], $replace); + + $string = eregi_replace + ('=\?([^?]+)\?(q|b)\?([^?]+)\?=', + $replace, $string); + // In case there should be more encoding in the string: recurse + return (decodeHeader($string)); + } else + return ($string); + } + + // Encode a string according to RFC 1522 for use in headers if it + // contains 8-bit characters + function encodeHeader ($string) { + global $default_charset; + + // Encode only if the string contains 8-bit characters + if (ereg("[\200-\377]", $string)) { + $newstring = "=?$default_charset?Q?"; + $newstring .= str_replace(" ", "_", $string); + + while (ereg("([\200-\377])", $newstring, $regs)) { + $replace = $regs[1]; + $insert = "=" . bin2hex($replace); + $newstring = str_replace($replace, $insert, $newstring); + } + + $newstring .= "?="; + + return $newstring; } - return $newbody; + + return $string; } -?> \ No newline at end of file + +?>