[1473] | 1 | <?php |
---|
[1037] | 2 | if(!isset($GLOBALS['phpgw_info'])){ |
---|
[1011] | 3 | $GLOBALS['phpgw_info']['flags'] = array( |
---|
| 4 | 'currentapp' => 'expressoMail1_2', |
---|
| 5 | 'nonavbar' => true, |
---|
| 6 | 'noheader' => true |
---|
| 7 | ); |
---|
[1037] | 8 | } |
---|
[1040] | 9 | require_once '../../header.inc.php'; |
---|
[1036] | 10 | |
---|
[1040] | 11 | |
---|
[2] | 12 | $msg_number = $_GET['msg_number']; |
---|
| 13 | $idx_file = $_GET['idx_file']; |
---|
[3369] | 14 | $newfilename = html_entity_decode(rawurldecode($_GET['newfilename'])); |
---|
[2] | 15 | $msg_part = $_GET['msg_part']; |
---|
| 16 | $msg_folder = $_GET['msg_folder']; |
---|
[178] | 17 | $msg_folder = mb_convert_encoding($msg_folder,"UTF7-IMAP", mb_detect_encoding($msg_folder, "UTF-8, ISO-8859-1", true)); |
---|
[1036] | 18 | |
---|
[2] | 19 | $encoding = strtolower($_GET['encoding']); |
---|
| 20 | $fileContent = ""; |
---|
[1036] | 21 | |
---|
[2] | 22 | if($msg_number && $msg_part && $msg_folder && (intval($idx_file == '0' ? '1' : $idx_file))) { |
---|
| 23 | $username = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 24 | $password = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; |
---|
| 25 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[3369] | 26 | $imap_port = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; |
---|
[27] | 27 | if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') |
---|
| 28 | { |
---|
| 29 | $imap_options = '/tls/novalidate-cert'; |
---|
| 30 | } |
---|
| 31 | else |
---|
| 32 | { |
---|
| 33 | $imap_options = '/notls/novalidate-cert'; |
---|
| 34 | } |
---|
[3369] | 35 | $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$msg_folder, $username, $password); |
---|
[1036] | 36 | $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID); |
---|
[1005] | 37 | /* |
---|
[1036] | 38 | *Removed by Bug #546 |
---|
| 39 | *include("class.imap_attachment.inc.php"); |
---|
[3369] | 40 | *$imap_attachment = new imap_attachment(); |
---|
[1036] | 41 | *$a = $imap_attachment->download_attachment($mbox_stream, $msg_number); |
---|
| 42 | *$filename = $a[$idx_file]['name']; |
---|
| 43 | */ |
---|
[1005] | 44 | $filename = $newfilename; |
---|
[2] | 45 | } |
---|
| 46 | else |
---|
| 47 | $filename = $idx_file; |
---|
| 48 | |
---|
[1036] | 49 | $filename = $filename ? $filename : "attachment.bin"; |
---|
| 50 | $newfilename = $newfilename ? $newfilename : $filename; |
---|
| 51 | $strFileType = strrev(substr(strrev(strtolower($filename)),0,4)); |
---|
| 52 | |
---|
| 53 | downloadFile($strFileType, $filename, $newfilename, $fileContent, $encoding); |
---|
| 54 | |
---|
| 55 | function downloadFile($strFileType, $strFileName, $newFileName, $fileContent, $encoding) { |
---|
[3369] | 56 | //avoid stuck request |
---|
| 57 | session_write_close(); |
---|
[1036] | 58 | $ContentType = "application/octet-stream"; |
---|
| 59 | |
---|
[3369] | 60 | if ($strFileType == ".asf") |
---|
[1036] | 61 | $ContentType = "video/x-ms-asf"; |
---|
| 62 | if ($strFileType == ".avi") |
---|
| 63 | $ContentType = "video/avi"; |
---|
| 64 | if ($strFileType == ".doc") |
---|
| 65 | $ContentType = "application/msword"; |
---|
| 66 | if ($strFileType == ".zip") |
---|
| 67 | $ContentType = "application/zip"; |
---|
| 68 | if ($strFileType == ".xls") |
---|
| 69 | $ContentType = "application/vnd.ms-excel"; |
---|
| 70 | if ($strFileType == ".gif") |
---|
| 71 | $ContentType = "image/gif"; |
---|
| 72 | if ($strFileType == ".jpg" || $strFileType == "jpeg") |
---|
| 73 | $ContentType = "image/jpeg"; |
---|
| 74 | if ($strFileType == ".wav") |
---|
| 75 | $ContentType = "audio/wav"; |
---|
| 76 | if ($strFileType == ".mp3") |
---|
| 77 | $ContentType = "audio/mpeg3"; |
---|
| 78 | if ($strFileType == ".mpg" || $strFileType == "mpeg") |
---|
| 79 | $ContentType = "video/mpeg"; |
---|
| 80 | if ($strFileType == ".rtf") |
---|
| 81 | $ContentType = "application/rtf"; |
---|
| 82 | if ($strFileType == ".htm" || $strFileType == "html") |
---|
| 83 | $ContentType = "text/html"; |
---|
[3369] | 84 | if ($strFileType == ".xml") |
---|
[1036] | 85 | $ContentType = "text/xml"; |
---|
[3369] | 86 | if ($strFileType == ".xsl") |
---|
[1036] | 87 | $ContentType = "text/xsl"; |
---|
[3369] | 88 | if ($strFileType == ".css") |
---|
[1036] | 89 | $ContentType = "text/css"; |
---|
[3369] | 90 | if ($strFileType == ".php") |
---|
[1036] | 91 | $ContentType = "text/php"; |
---|
[3369] | 92 | if ($strFileType == ".asp") |
---|
[1036] | 93 | $ContentType = "text/asp"; |
---|
| 94 | if ($strFileType == ".pdf") |
---|
| 95 | $ContentType = "application/pdf"; |
---|
| 96 | if ($strFileType == ".txt") |
---|
| 97 | $ContentType = "text/plain"; |
---|
| 98 | if ($strFileType == ".log") |
---|
| 99 | $ContentType = "text/plain"; |
---|
| 100 | if ($strFileType == ".wmv") |
---|
| 101 | $ContentType = "video/x-ms-wmv"; |
---|
| 102 | if ($strFileType == ".sxc") |
---|
| 103 | $ContentType = "application/vnd.sun.xml.calc"; |
---|
| 104 | if ($strFileType == ".odt") |
---|
| 105 | $ContentType = "application/vnd.oasis.opendocument.text"; |
---|
| 106 | if ($strFileType == ".stc") |
---|
| 107 | $ContentType = "application/vnd.sun.xml.calc.template"; |
---|
| 108 | if ($strFileType == ".sxd") |
---|
| 109 | $ContentType = "application/vnd.sun.xml.draw"; |
---|
| 110 | if ($strFileType == ".std") |
---|
| 111 | $ContentType = "application/vnd.sun.xml.draw.template"; |
---|
| 112 | if ($strFileType == ".sxi") |
---|
| 113 | $ContentType = "application/vnd.sun.xml.impress"; |
---|
| 114 | if ($strFileType == ".sti") |
---|
| 115 | $ContentType = "application/vnd.sun.xml.impress.template"; |
---|
| 116 | if ($strFileType == ".sxm") |
---|
| 117 | $ContentType = "application/vnd.sun.xml.math"; |
---|
| 118 | if ($strFileType == ".sxw") |
---|
| 119 | $ContentType = "application/vnd.sun.xml.writer"; |
---|
| 120 | if ($strFileType == ".sxq") |
---|
| 121 | $ContentType = "application/vnd.sun.xml.writer.global"; |
---|
| 122 | if ($strFileType == ".stw") |
---|
| 123 | $ContentType = "application/vnd.sun.xml.writer.template"; |
---|
| 124 | if ($strFileType == ".ps") |
---|
| 125 | $ContentType = "application/postscript"; |
---|
| 126 | if ($strFileType == ".pps") |
---|
| 127 | $ContentType = "application/vnd.ms-powerpoint"; |
---|
| 128 | if ($strFileType == ".odt") |
---|
| 129 | $ContentType = "application/vnd.oasis.opendocument.text"; |
---|
| 130 | if ($strFileType == ".ott") |
---|
| 131 | $ContentType = "application/vnd.oasis.opendocument.text-template"; |
---|
| 132 | if ($strFileType == ".oth") |
---|
| 133 | $ContentType = "application/vnd.oasis.opendocument.text-web"; |
---|
| 134 | if ($strFileType == ".odm") |
---|
| 135 | $ContentType = "application/vnd.oasis.opendocument.text-master"; |
---|
| 136 | if ($strFileType == ".odg") |
---|
| 137 | $ContentType = "application/vnd.oasis.opendocument.graphics"; |
---|
| 138 | if ($strFileType == ".otg") |
---|
| 139 | $ContentType = "application/vnd.oasis.opendocument.graphics-template"; |
---|
| 140 | if ($strFileType == ".odp") |
---|
| 141 | $ContentType = "application/vnd.oasis.opendocument.presentation"; |
---|
| 142 | if ($strFileType == ".otp") |
---|
| 143 | $ContentType = "application/vnd.oasis.opendocument.presentation-template"; |
---|
| 144 | if ($strFileType == ".ods") |
---|
| 145 | $ContentType = "application/vnd.oasis.opendocument.spreadsheet"; |
---|
| 146 | if ($strFileType == ".ots") |
---|
| 147 | $ContentType = "application/vnd.oasis.opendocument.spreadsheet-template"; |
---|
| 148 | if ($strFileType == ".odc") |
---|
| 149 | $ContentType = "application/vnd.oasis.opendocument.chart"; |
---|
| 150 | if ($strFileType == ".odf") |
---|
| 151 | $ContentType = "application/vnd.oasis.opendocument.formula"; |
---|
| 152 | if ($strFileType == ".odi") |
---|
| 153 | $ContentType = "application/vnd.oasis.opendocument.image"; |
---|
| 154 | if ($strFileType == ".ndl") |
---|
| 155 | $ContentType = "application/vnd.lotus-notes"; |
---|
[1899] | 156 | if ($strFileType == ".eml") |
---|
| 157 | $ContentType = "text/plain"; |
---|
[1036] | 158 | |
---|
| 159 | header ("Content-Type: $ContentType"); |
---|
[1040] | 160 | header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); |
---|
[1036] | 161 | header("Pragma: public"); |
---|
| 162 | header("Expires: 0"); // set expiration time |
---|
[3369] | 163 | header ("Content-Disposition: attachment; filename=\"". addslashes($newFileName)."\""); |
---|
[4595] | 164 | // No IE para que os nomes de arquivos com caracteres especiais no download fiquei corretos o nome deve ser codificado com urlencode. |
---|
| 165 | if (preg_match('/msie/i', $_SERVER['HTTP_USER_AGENT'])) |
---|
| 166 | $newFileName=urlencode($newFileName); |
---|
| 167 | if($fileContent) { |
---|
[1036] | 168 | if($encoding == 'base64') |
---|
| 169 | echo imap_base64($fileContent); |
---|
| 170 | else if($encoding == 'quoted-printable') |
---|
| 171 | echo quoted_printable_decode($fileContent); |
---|
| 172 | else |
---|
| 173 | echo $fileContent; |
---|
| 174 | } |
---|
[2] | 175 | else |
---|
[3240] | 176 | |
---|
| 177 | if (strstr($strFileName,$GLOBALS['phpgw']->session->sessionid)&&file_exists($strFileName)) |
---|
| 178 | { |
---|
| 179 | header("Content-Type: $ContentType"); |
---|
| 180 | header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); |
---|
| 181 | header("Pragma: public"); |
---|
| 182 | header("Expires: 0"); // set expiration time |
---|
| 183 | header ("Content-Disposition: attachment; filename=\"". addslashes($newFileName)."\""); |
---|
| 184 | readfile($strFileName); |
---|
| 185 | }else{ |
---|
| 186 | header("HTTP/1.1 404 Not Found"); |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | |
---|
[1597] | 190 | if (preg_match("#^".ini_get('session.save_path')."/(".$GLOBALS['phpgw']->session->sessionid."/)*[A-z]+_".$GLOBALS['phpgw']->session->sessionid."[A-z0-9]*(\.[A-z]{3,4})?$#",$strFileName)) |
---|
[1040] | 191 | { |
---|
[3139] | 192 | if ( ! preg_match("#^".dirname( __FILE__ ) . '/../tmpLclAtt'."/source_#",$strFileName)) { |
---|
[3240] | 193 | //reset time limit for big files |
---|
| 194 | set_time_limit(0); |
---|
| 195 | ob_end_flush(); |
---|
[3018] | 196 | |
---|
[3240] | 197 | if ($fp = fopen ($strFileName, 'rb')) |
---|
| 198 | { |
---|
| 199 | $bufferSize=1024; |
---|
| 200 | for ($i=$bufferSize; $i<=(filesize($strFileName)+$bufferSize); $i+=$bufferSize) |
---|
| 201 | { |
---|
| 202 | echo fread($fp, $i); |
---|
| 203 | flush(); |
---|
| 204 | } |
---|
| 205 | fclose ($fp); |
---|
| 206 | } |
---|
| 207 | //readfile($strFileName); |
---|
[3018] | 208 | |
---|
| 209 | exec("rm -f ".escapeshellcmd(escapeshellarg($strFileName))); |
---|
[1937] | 210 | } |
---|
[3240] | 211 | else |
---|
[3139] | 212 | readfile($strFileName); |
---|
[3018] | 213 | } |
---|
[3080] | 214 | } |
---|
[1036] | 215 | ?> |
---|