" . nl2br(trim($tmpbody)) . ""; } // 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(trim($tmpbody)) . ""; } else if (containsType($message, "message", "any_type", $ent_num)) { $tmpbody = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]); $body .= "" . nl2br(trim($tmpbody)) . ""; } } /** If there are other types that shouldn't be formatted, add them here **/ if ($message["ENTITIES"][$ent_num]["TYPE1"] != "html") $body = translateText($body); $body .= "
Download this as a file

"; /** Display the ATTACHMENTS: message if there's more than one part **/ if (count($message["ENTITIES"]) > 1) { $body .= "
"; $body .= "ATTACHMENTS:"; $body .= "
"; $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"]; if (trim($filename) == "") { $display_filename = "untitled$i"; } else { $display_filename = $filename; } $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") { $body_ary = explode("\n", $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"; } } 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"; } $newbody = $body; } else if ($encoding == "base64") { $newbody = base64_decode($body); } else { $newbody = $body; } return $newbody; } ?>