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

"; /** Display the ATTACHMENTS: message if there's more than one part **/ if (count($message["ENTITIES"]) > 1) { - $pos = count($body); - $body[$pos] .= "
ATTACHMENTS:
"; + $body .= "
"; + $body .= "ATTACHMENTS:"; + $body .= "
"; $num = 0; for ($i = 0; $i < count($message["ENTITIES"]); $i++) { @@ -138,52 +181,61 @@ $num++; $filename = $message["ENTITIES"][$i]["FILENAME"]; if (trim($filename) == "") { - $filename = "UNKNOWN_FORMAT_" . time() . $i; - $display_filename = "Attachment $i"; + $display_filename = "untitled$i"; } else { $display_filename = $filename; } - $body[$pos] .= "   " . $display_filename . "  (TYPE: $type0/$type1)
"; - $file = fopen("../data/$filename", "w"); - - /** Determine what encoding type is used **/ - if ($message["ENTITIES"][$i]["ENCODING"] == "base64") { - $thefile = base64_decode($message["ENTITIES"][$i]["BODY"][0]); - } else { - $thefile = $message["ENTITIES"][$i]["BODY"][0]; - } - - fwrite($file, $thefile); - fclose($file); + $urlMailbox = urlencode($message["INFO"]["MAILBOX"]); + $id = $message["INFO"]["ID"]; + $body .= "   " . $display_filename . "  (TYPE: $type0/$type1)
"; } + $body .= "
"; } - return $body; } + + + /** this function decodes the body depending on the encoding type. **/ 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") { - for ($q=0; $q < count($body); $q++) { - if (substr(trim($body[$q]), -1) == "=") { - $body[$q] = trim($body[$q]); - $body[$q] = substr($body[$q], 0, strlen($body[$q])-1); - } else if (substr(trim($body[$q]), -3) == "=20") { - $body[$q] = trim($body[$q]); - $body[$q] = substr($body[$q], 0, strlen($body[$q])-3); - $body[$q] = "$body[$q]\n"; // maybe should be \n.. dunno - } - } - for ($q=0;$q < count($body);$q++) { - $body[$q] = ereg_replace("=3D", "=", $body[$q]); - } - $newbody = $body; - } else { - $newbody = $body; + + if ($encoding == "quoted-printable") { + $body = quoted_printable_decode($body); + + while (ereg("=\n", $body)) + $body = ereg_replace ("=\n", "", $body); + } else if ($encoding == "base64") { + $body = base64_decode($body); } - return $newbody; + + // 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); } -?> \ No newline at end of file + +?>