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