From b1dadc61dfbbd09270e21b6083102755d537c2f3 Mon Sep 17 00:00:00 2001 From: lkehresman Date: Sun, 2 Jan 2000 20:04:01 +0000 Subject: [PATCH] updated the MIME support. It's much better git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@95 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/mime.php | 119 ++++++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 56 deletions(-) diff --git a/functions/mime.php b/functions/mime.php index 7054b41f..4ddc0e5e 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -63,91 +63,98 @@ $msg[0]["CHARSET"] = $charset; $msg[0]["FILENAME"] = $filename; - echo "$type0 / $type1
"; if ($type0 == "text") { // error correcting if they didn't follow RFC standards if (trim($type1) == "") $type1 = "plain"; if ($type1 == "plain") { - $msg[0]["PRIORITY"] = 10; for ($p = 0;$p < count($body);$p++) { $msg[0]["BODY"][$p] = parsePlainTextMessage($body[$p]); } - } else if ($type1 == "html") { - $msg[0]["PRIORITY"] = 20; - $msg[0]["BODY"] = $body; } else { - $msg[0]["PRIORITY"] = 1; - $msg[0]["BODY"][0] = "This entity is of an unknown format. Doing my best to display anyway...

"; - for ($p = 1;$p < count($body);$p++) { - $q = $p - 1; - $msg[0]["BODY"][$p] = $body[$q]; - } + $msg[0]["BODY"] = $body; } } else { - $msg[0]["PRIORITY"] == 5; $msg[0]["BODY"][0] = $body; } return $msg; } - function formatBody($message) { - for ($i=0; $i < count($message["ENTITIES"]); $i++) { - if ($message["ENTITIES"][$i]["TYPE0"] == "text") { - if ($message["ENTITIES"][$i]["PRIORITY"] > $priority) - $priority = $message["ENTITIES"][$i]["PRIORITY"]; - } - } - + function containsType($message, $type0, $type1, &$ent_num) { + $type0 = strtolower($type0); + $type1 = strtolower($type1); for ($i = 0; $i < count($message["ENTITIES"]); $i++) { - switch ($priority) { - /** HTML **/ - case 20: for ($i=0; $i < count($message["ENTITIES"]); $i++) { - if (($message["ENTITIES"][$i]["TYPE0"] == "text") && ($message["ENTITIES"][$i]["TYPE1"] == "html")) { - $body = decodeBody($message["ENTITIES"][$i]["BODY"], $message["ENTITIES"][$i]["ENCODING"]); - } - } - break; - /** PLAIN **/ - case 10: for ($i=0; $i < count($message["ENTITIES"]); $i++) { - if (($message["ENTITIES"][$i]["TYPE0"] == "text") && ($message["ENTITIES"][$i]["TYPE1"] == "plain")) { - $body = decodeBody($message["ENTITIES"][$i]["BODY"], $message["ENTITIES"][$i]["ENCODING"]); - } - } - break; - /** UNKNOWN...SEND WHAT WE GOT **/ - case 1: for ($i=0; $i < count($message["ENTITIES"]); $i++) { - if (($message["ENTITIES"][$i]["TYPE0"] == "text")) { - $pos = count($body); - for ($b=0; $b < count($message["ENTITIES"][$i]["BODY"]); $b++) { - $pos = $pos + $b; - $body[$pos] = $message["ENTITIES"][$i]["BODY"][$b]; - } - } - } - break; + /** Check only on type0 **/ + if ( $type1 == "any_type" ) { + if ( ($message["ENTITIES"][$i]["TYPE0"] == $type0) ) { + $ent_num = $i; + return true; + } + + /** Check on type0 and type1 **/ + } else { + if ( ($message["ENTITIES"][$i]["TYPE0"] == $type0) && ($message["ENTITIES"][$i]["TYPE1"] == $type1) ) { + $ent_num = $i; + return true; + } } } + return false; + } - for ($i = 0; $i < count($message["ENTITIES"]); $i++) { - $pos = count($body); - if ($message["ENTITIES"][$i]["TYPE0"] != "text") { - $body[$pos] = "
ATTACHMENTS:
"; - $i = count($message["ENTITIES"]); + function formatBody($message) { + if (containsType($message, "text", "html", $ent_num)) { + $body = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]); + } else if (containsType($message, "text", "plain", $ent_num)) { + $body = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]); + } // add other primary displaying message types here + + else { + // find any type that's displayable + if (containsType($message, "text", "any_type", $ent_num)) { + $body = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]); + } else if (containsType($message, "message", "any_type", $ent_num)) { + $body = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]); } } - for ($i = 0; $i < count($message["ENTITIES"]); $i++) { + + /** Display the ATTACHMENTS: message if there's more than one part **/ + if (count($message["ENTITIES"]) > 1) { $pos = count($body); - if (($message["ENTITIES"][$i]["TYPE0"] == "image") || ($message["ENTITIES"][$i]["TYPE0"] == "application")){ + $body[$pos] .= "
ATTACHMENTS:
"; + $num = 0; + + for ($i = 0; $i < count($message["ENTITIES"]); $i++) { + /** If we've displayed this entity, go to the next one **/ + if ($ent_num == $i) + continue; + + $type0 = strtolower($message["ENTITIES"][$i]["TYPE0"]); + $type1 = strtolower($message["ENTITIES"][$i]["TYPE1"]); + + $num++; $filename = $message["ENTITIES"][$i]["FILENAME"]; - $body[$pos] = "   " . $filename . "
"; + if (trim($filename) == "") { + $filename = "UNKNOWN_FORMAT_" . time() . $i; + $display_filename = "Attachment $i"; + } else { + $display_filename = $filename; + } + $body[$pos] .= "   " . $display_filename . "  (TYPE: $type0/$type1)
"; $file = fopen("../data/$filename", "w"); - $image = base64_decode($message["ENTITIES"][$i]["BODY"][0]); - fwrite($file, $image); + + /** 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); } } -- 2.25.1