1) { $pos = count($body); $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"]; 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"); /** 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); } } 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; } ?>