X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fmime.php;h=ecbc6abcf217047c0cfd5e3986afa34e64b77222;hb=81a897dced6deb1e5fc9a332dfe572818f1da0f0;hp=dc5ef1aec08ec1b3d5433023260369753a61fa8c;hpb=d29aac0e3969fcd88d2dc76698ea802718c200e6;p=squirrelmail.git diff --git a/functions/mime.php b/functions/mime.php index dc5ef1ae..ecbc6abc 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -1,14 +1,20 @@
". _("Download this as a file") ."

"; @@ -185,39 +201,41 @@ function decodeBody($body, $encoding) { $encoding = strtolower($encoding); - if ($encoding == "us-ascii") { - $newbody = $body; // if only they all were this easy + if ($encoding == "quoted-printable") { + $body = quoted_printable_decode($body); - } else if ($encoding == "quoted-printable") { - $body_ary = explode("\n", $body); + while (ereg("=\n", $body)) + $body = ereg_replace ("=\n", "", $body); + } else if ($encoding == "base64") { + $body = base64_decode($body); + } - for ($q=0; $q < count($body_ary); $q++) { - if (substr(trim($body_ary[$q]), -1) == "=") { - $body_ary[$q] = trim($body_ary[$q]); - $body_ary[$q] = substr($body_ary[$q], 0, strlen($body_ary[$q])-1); - } else if (substr(trim($body_ary[$q]), -3) == "=20") { - $body_ary[$q] = trim($body_ary[$q]); - $body_ary[$q] = substr($body_ary[$q], 0, strlen($body_ary[$q])-3); - $body_ary[$q] = "$body_ary[$q]\n"; - } - } + // All other encodings are returned raw. + return $body; + } - for ($q=0;$q < count($body_ary);$q++) { - $body_ary[$q] = ereg_replace("=3D", "=", $body_ary[$q]); - } - $body = ""; - for ($i = 0; $i < count($body_ary); $i++) { - $body .= "$body_ary[$i]\n"; + // 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); } - $newbody = $body; - } else if ($encoding == "base64") { - $newbody = base64_decode($body); + $replace = charset_decode ($res[1], $replace); - } else { - $newbody = $body; - } - return $newbody; + $string = eregi_replace + ('=\?([^?]+)\?(q|b)\?([^?]+)\?=', + $replace, $string); + // In case there should be more encoding in the string: recurse + return (decodeHeader($string)); + } else + return ($string); } + ?>