download_attachment($mbox_stream, $msg_number); $filename = $a[$idx_file]['name']; } else $filename = $idx_file; $filename = $filename ? $filename : "attachment.bin"; $newfilename = $newfilename ? $newfilename : $filename; $strFileType = strrev(substr(strrev(strtolower($filename)),0,4)); downloadFile($strFileType, $filename, $newfilename, $fileContent, $encoding); function downloadFile($strFileType, $strFileName, $newFileName, $fileContent, $encoding) { $ContentType = "application/octet-stream"; if ($strFileType == ".asf") $ContentType = "video/x-ms-asf"; if ($strFileType == ".avi") $ContentType = "video/avi"; if ($strFileType == ".doc") $ContentType = "application/msword"; if ($strFileType == ".zip") $ContentType = "application/zip"; if ($strFileType == ".xls") $ContentType = "application/vnd.ms-excel"; if ($strFileType == ".gif") $ContentType = "image/gif"; if ($strFileType == ".jpg" || $strFileType == "jpeg") $ContentType = "image/jpeg"; if ($strFileType == ".wav") $ContentType = "audio/wav"; if ($strFileType == ".mp3") $ContentType = "audio/mpeg3"; if ($strFileType == ".mpg" || $strFileType == "mpeg") $ContentType = "video/mpeg"; if ($strFileType == ".rtf") $ContentType = "application/rtf"; if ($strFileType == ".htm" || $strFileType == "html") $ContentType = "text/html"; if ($strFileType == ".xml") $ContentType = "text/xml"; if ($strFileType == ".xsl") $ContentType = "text/xsl"; if ($strFileType == ".css") $ContentType = "text/css"; if ($strFileType == ".php") $ContentType = "text/php"; if ($strFileType == ".asp") $ContentType = "text/asp"; if ($strFileType == ".pdf") $ContentType = "application/pdf"; if ($strFileType == ".txt") $ContentType = "text/plain"; if ($strFileType == ".log") $ContentType = "text/plain"; if ($strFileType == ".wmv") $ContentType = "video/x-ms-wmv"; if ($strFileType == ".sxc") $ContentType = "application/vnd.sun.xml.calc"; if ($strFileType == ".odt") $ContentType = "application/vnd.oasis.opendocument.text"; if ($strFileType == ".stc") $ContentType = "application/vnd.sun.xml.calc.template"; if ($strFileType == ".sxd") $ContentType = "application/vnd.sun.xml.draw"; if ($strFileType == ".std") $ContentType = "application/vnd.sun.xml.draw.template"; if ($strFileType == ".sxi") $ContentType = "application/vnd.sun.xml.impress"; if ($strFileType == ".sti") $ContentType = "application/vnd.sun.xml.impress.template"; if ($strFileType == ".sxm") $ContentType = "application/vnd.sun.xml.math"; if ($strFileType == ".sxw") $ContentType = "application/vnd.sun.xml.writer"; if ($strFileType == ".sxq") $ContentType = "application/vnd.sun.xml.writer.global"; if ($strFileType == ".stw") $ContentType = "application/vnd.sun.xml.writer.template"; if ($strFileType == ".ps") $ContentType = "application/postscript"; if ($strFileType == ".pps") $ContentType = "application/vnd.ms-powerpoint"; if ($strFileType == ".odt") $ContentType = "application/vnd.oasis.opendocument.text"; if ($strFileType == ".ott") $ContentType = "application/vnd.oasis.opendocument.text-template"; if ($strFileType == ".oth") $ContentType = "application/vnd.oasis.opendocument.text-web"; if ($strFileType == ".odm") $ContentType = "application/vnd.oasis.opendocument.text-master"; if ($strFileType == ".odg") $ContentType = "application/vnd.oasis.opendocument.graphics"; if ($strFileType == ".otg") $ContentType = "application/vnd.oasis.opendocument.graphics-template"; if ($strFileType == ".odp") $ContentType = "application/vnd.oasis.opendocument.presentation"; if ($strFileType == ".otp") $ContentType = "application/vnd.oasis.opendocument.presentation-template"; if ($strFileType == ".ods") $ContentType = "application/vnd.oasis.opendocument.spreadsheet"; if ($strFileType == ".ots") $ContentType = "application/vnd.oasis.opendocument.spreadsheet-template"; if ($strFileType == ".odc") $ContentType = "application/vnd.oasis.opendocument.chart"; if ($strFileType == ".odf") $ContentType = "application/vnd.oasis.opendocument.formula"; if ($strFileType == ".odi") $ContentType = "application/vnd.oasis.opendocument.image"; if ($strFileType == ".ndl") $ContentType = "application/vnd.lotus-notes"; header ("Content-Type: $ContentType"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: public"); header("Expires: 0"); // set expiration time header ("Content-Disposition: attachment; filename=\"". addslashes($newFileName)."\""); if($fileContent) { if($encoding == 'base64') echo imap_base64($fileContent); else if($encoding == 'quoted-printable') echo quoted_printable_decode($fileContent); else echo $fileContent; } else readfile($strFileName); } ?>