[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)); |
---|
[4747] | 52 | if(strpos($strFileType ,"." )===false) |
---|
| 53 | $strFileType = strrev(substr(strrev(strtolower($newfilename)),0,4)); |
---|
[1036] | 54 | |
---|
| 55 | downloadFile($strFileType, $filename, $newfilename, $fileContent, $encoding); |
---|
| 56 | |
---|
| 57 | function downloadFile($strFileType, $strFileName, $newFileName, $fileContent, $encoding) { |
---|
[3369] | 58 | //avoid stuck request |
---|
| 59 | session_write_close(); |
---|
[1036] | 60 | $ContentType = "application/octet-stream"; |
---|
| 61 | |
---|
[3369] | 62 | if ($strFileType == ".asf") |
---|
[1036] | 63 | $ContentType = "video/x-ms-asf"; |
---|
| 64 | if ($strFileType == ".avi") |
---|
| 65 | $ContentType = "video/avi"; |
---|
| 66 | if ($strFileType == ".doc") |
---|
| 67 | $ContentType = "application/msword"; |
---|
| 68 | if ($strFileType == ".zip") |
---|
| 69 | $ContentType = "application/zip"; |
---|
| 70 | if ($strFileType == ".xls") |
---|
| 71 | $ContentType = "application/vnd.ms-excel"; |
---|
| 72 | if ($strFileType == ".gif") |
---|
| 73 | $ContentType = "image/gif"; |
---|
| 74 | if ($strFileType == ".jpg" || $strFileType == "jpeg") |
---|
| 75 | $ContentType = "image/jpeg"; |
---|
| 76 | if ($strFileType == ".wav") |
---|
| 77 | $ContentType = "audio/wav"; |
---|
| 78 | if ($strFileType == ".mp3") |
---|
| 79 | $ContentType = "audio/mpeg3"; |
---|
| 80 | if ($strFileType == ".mpg" || $strFileType == "mpeg") |
---|
| 81 | $ContentType = "video/mpeg"; |
---|
| 82 | if ($strFileType == ".rtf") |
---|
| 83 | $ContentType = "application/rtf"; |
---|
| 84 | if ($strFileType == ".htm" || $strFileType == "html") |
---|
| 85 | $ContentType = "text/html"; |
---|
[3369] | 86 | if ($strFileType == ".xml") |
---|
[1036] | 87 | $ContentType = "text/xml"; |
---|
[3369] | 88 | if ($strFileType == ".xsl") |
---|
[1036] | 89 | $ContentType = "text/xsl"; |
---|
[3369] | 90 | if ($strFileType == ".css") |
---|
[1036] | 91 | $ContentType = "text/css"; |
---|
[3369] | 92 | if ($strFileType == ".php") |
---|
[1036] | 93 | $ContentType = "text/php"; |
---|
[3369] | 94 | if ($strFileType == ".asp") |
---|
[1036] | 95 | $ContentType = "text/asp"; |
---|
| 96 | if ($strFileType == ".pdf") |
---|
| 97 | $ContentType = "application/pdf"; |
---|
| 98 | if ($strFileType == ".txt") |
---|
| 99 | $ContentType = "text/plain"; |
---|
| 100 | if ($strFileType == ".log") |
---|
| 101 | $ContentType = "text/plain"; |
---|
| 102 | if ($strFileType == ".wmv") |
---|
| 103 | $ContentType = "video/x-ms-wmv"; |
---|
| 104 | if ($strFileType == ".sxc") |
---|
| 105 | $ContentType = "application/vnd.sun.xml.calc"; |
---|
| 106 | if ($strFileType == ".odt") |
---|
| 107 | $ContentType = "application/vnd.oasis.opendocument.text"; |
---|
| 108 | if ($strFileType == ".stc") |
---|
| 109 | $ContentType = "application/vnd.sun.xml.calc.template"; |
---|
| 110 | if ($strFileType == ".sxd") |
---|
| 111 | $ContentType = "application/vnd.sun.xml.draw"; |
---|
| 112 | if ($strFileType == ".std") |
---|
| 113 | $ContentType = "application/vnd.sun.xml.draw.template"; |
---|
| 114 | if ($strFileType == ".sxi") |
---|
| 115 | $ContentType = "application/vnd.sun.xml.impress"; |
---|
| 116 | if ($strFileType == ".sti") |
---|
| 117 | $ContentType = "application/vnd.sun.xml.impress.template"; |
---|
| 118 | if ($strFileType == ".sxm") |
---|
| 119 | $ContentType = "application/vnd.sun.xml.math"; |
---|
| 120 | if ($strFileType == ".sxw") |
---|
| 121 | $ContentType = "application/vnd.sun.xml.writer"; |
---|
| 122 | if ($strFileType == ".sxq") |
---|
| 123 | $ContentType = "application/vnd.sun.xml.writer.global"; |
---|
| 124 | if ($strFileType == ".stw") |
---|
| 125 | $ContentType = "application/vnd.sun.xml.writer.template"; |
---|
| 126 | if ($strFileType == ".ps") |
---|
| 127 | $ContentType = "application/postscript"; |
---|
| 128 | if ($strFileType == ".pps") |
---|
| 129 | $ContentType = "application/vnd.ms-powerpoint"; |
---|
| 130 | if ($strFileType == ".odt") |
---|
| 131 | $ContentType = "application/vnd.oasis.opendocument.text"; |
---|
| 132 | if ($strFileType == ".ott") |
---|
| 133 | $ContentType = "application/vnd.oasis.opendocument.text-template"; |
---|
| 134 | if ($strFileType == ".oth") |
---|
| 135 | $ContentType = "application/vnd.oasis.opendocument.text-web"; |
---|
| 136 | if ($strFileType == ".odm") |
---|
| 137 | $ContentType = "application/vnd.oasis.opendocument.text-master"; |
---|
| 138 | if ($strFileType == ".odg") |
---|
| 139 | $ContentType = "application/vnd.oasis.opendocument.graphics"; |
---|
| 140 | if ($strFileType == ".otg") |
---|
| 141 | $ContentType = "application/vnd.oasis.opendocument.graphics-template"; |
---|
| 142 | if ($strFileType == ".odp") |
---|
| 143 | $ContentType = "application/vnd.oasis.opendocument.presentation"; |
---|
| 144 | if ($strFileType == ".otp") |
---|
| 145 | $ContentType = "application/vnd.oasis.opendocument.presentation-template"; |
---|
| 146 | if ($strFileType == ".ods") |
---|
| 147 | $ContentType = "application/vnd.oasis.opendocument.spreadsheet"; |
---|
| 148 | if ($strFileType == ".ots") |
---|
| 149 | $ContentType = "application/vnd.oasis.opendocument.spreadsheet-template"; |
---|
| 150 | if ($strFileType == ".odc") |
---|
| 151 | $ContentType = "application/vnd.oasis.opendocument.chart"; |
---|
| 152 | if ($strFileType == ".odf") |
---|
| 153 | $ContentType = "application/vnd.oasis.opendocument.formula"; |
---|
| 154 | if ($strFileType == ".odi") |
---|
| 155 | $ContentType = "application/vnd.oasis.opendocument.image"; |
---|
| 156 | if ($strFileType == ".ndl") |
---|
| 157 | $ContentType = "application/vnd.lotus-notes"; |
---|
[1899] | 158 | if ($strFileType == ".eml") |
---|
| 159 | $ContentType = "text/plain"; |
---|
[1036] | 160 | |
---|
| 161 | header ("Content-Type: $ContentType"); |
---|
[1040] | 162 | header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); |
---|
[1036] | 163 | header("Pragma: public"); |
---|
| 164 | header("Expires: 0"); // set expiration time |
---|
[3369] | 165 | header ("Content-Disposition: attachment; filename=\"". addslashes($newFileName)."\""); |
---|
[1036] | 166 | if($fileContent) { |
---|
| 167 | if($encoding == 'base64') |
---|
| 168 | echo imap_base64($fileContent); |
---|
| 169 | else if($encoding == 'quoted-printable') |
---|
| 170 | echo quoted_printable_decode($fileContent); |
---|
| 171 | else |
---|
| 172 | echo $fileContent; |
---|
| 173 | } |
---|
[2] | 174 | else |
---|
[3240] | 175 | |
---|
| 176 | if (strstr($strFileName,$GLOBALS['phpgw']->session->sessionid)&&file_exists($strFileName)) |
---|
| 177 | { |
---|
| 178 | header("Content-Type: $ContentType"); |
---|
| 179 | header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); |
---|
| 180 | header("Pragma: public"); |
---|
| 181 | header("Expires: 0"); // set expiration time |
---|
| 182 | header ("Content-Disposition: attachment; filename=\"". addslashes($newFileName)."\""); |
---|
| 183 | readfile($strFileName); |
---|
| 184 | }else{ |
---|
| 185 | header("HTTP/1.1 404 Not Found"); |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | |
---|
[1597] | 189 | 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] | 190 | { |
---|
[3139] | 191 | if ( ! preg_match("#^".dirname( __FILE__ ) . '/../tmpLclAtt'."/source_#",$strFileName)) { |
---|
[3240] | 192 | //reset time limit for big files |
---|
| 193 | set_time_limit(0); |
---|
| 194 | ob_end_flush(); |
---|
[3018] | 195 | |
---|
[3240] | 196 | if ($fp = fopen ($strFileName, 'rb')) |
---|
| 197 | { |
---|
| 198 | $bufferSize=1024; |
---|
| 199 | for ($i=$bufferSize; $i<=(filesize($strFileName)+$bufferSize); $i+=$bufferSize) |
---|
| 200 | { |
---|
| 201 | echo fread($fp, $i); |
---|
| 202 | flush(); |
---|
| 203 | } |
---|
| 204 | fclose ($fp); |
---|
| 205 | } |
---|
| 206 | //readfile($strFileName); |
---|
[3018] | 207 | |
---|
| 208 | exec("rm -f ".escapeshellcmd(escapeshellarg($strFileName))); |
---|
[1937] | 209 | } |
---|
[3240] | 210 | else |
---|
[3139] | 211 | readfile($strFileName); |
---|
[3018] | 212 | } |
---|
[3080] | 213 | } |
---|
[1036] | 214 | ?> |
---|