+ 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"];
+ }
+ }
+
+ 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;
+ }
+ }
+ return $body;
+ }
+
+ 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;
+ }
+ return $newbody;