Changeset 5134 for trunk/expressoMail1_2/inc/get_archive.php
- Timestamp:
- 11/03/11 13:24:28 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/inc/get_archive.php
r5069 r5134 1 1 <?php 2 /**3 *4 * Copyright (C) 2011 Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)5 *6 * This program is free software; you can redistribute it and/or modify it under7 * the terms of the GNU Affero General Public License version 3 as published by8 * the Free Software Foundation with the addition of the following permission9 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED10 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE11 * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.12 *13 * This program is distributed in the hope that it will be useful, but WITHOUT14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more16 * details.17 *18 * You should have received a copy of the GNU Affero General Public License19 * along with this program; if not, see www.gnu.org/licenses or write to20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,21 * MA 02110-1301 USA.22 *23 * This code is based on the OpenXchange Connector and on the Prognus pSync24 * Connector both developed by the community and licensed under the GPL25 * version 2 or above as published by the Free Software Foundation.26 *27 * You can contact Prognus Software Livre headquarters at Av. Tancredo Neves,28 * 6731, PTI, Bl. 05, Esp. 02, Sl. 10, Foz do Iguaçu - PR - Brasil or at29 * e-mail address prognus@prognus.com.br.30 *31 *32 * @package expressoMail33 * @license http://www.gnu.org/copyleft/gpl.html GPL34 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)35 * @version 1.036 * @sponsor Caixa Econômica Federal37 */38 39 2 /* 40 3 * Definitions … … 52 15 //-----------------------// 53 16 54 /*55 * Requires56 */57 require_once 'class.attachment.inc.php';58 require_once '../../header.inc.php';59 17 //-----------------------// 60 18 … … 62 20 * Get variables 63 21 */ 64 $newFilename = urldecode($_GET['newFilename']); 65 $indexFile = $_GET['idx_file']; 22 if(array_key_exists('newFilename', $_GET ) && urldecode($_GET['newFilename']) !== 'application.octet-stream') 23 $newFilename = urldecode($_GET['newFilename']); 24 else 25 $newFilename = null; 26 if(array_key_exists('idx_file', $_GET )) 27 $indexFile = $_GET['idx_file']; 28 else 29 $indexFile = null; 30 66 31 $indexPart = $_GET['indexPart']; 67 32 $msgNumber = $_GET['msgNumber']; 68 33 $msgFolder = $_GET['msgFolder']; 34 if(array_key_exists('fileType', $_GET )) 35 $ContentType = $_GET['fileType']; 36 else 37 $ContentType = null; 38 if(array_key_exists('image', $_GET )) 39 $image = $_GET['image']; 40 else 41 $image = null; 69 42 //----------------------------------------------// 70 43 71 72 /** 73 * Método que faz o download do arquivo 74 * 75 * @license http://www.gnu.org/copyleft/gpl.html GPL 76 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 77 * @sponsor Caixa Econômica Federal 78 * @param $strFileType 79 * @param $strFileName 80 * @param $newFileName 81 * @param $fileContent 82 */ 83 function downloadFile($strFileType, $strFileName, $newFileName, $fileContent) { 84 85 $ContentType = "application/octet-stream"; 86 87 if ($strFileType == ".asf") 88 $ContentType = "video/x-ms-asf"; 89 if ($strFileType == ".avi") 90 $ContentType = "video/avi"; 91 if ($strFileType == ".doc") 92 $ContentType = "application/msword"; 93 if ($strFileType == ".zip") 94 $ContentType = "application/zip"; 95 if ($strFileType == ".xls") 96 $ContentType = "application/vnd.ms-excel"; 97 if ($strFileType == ".gif") 98 $ContentType = "image/gif"; 99 if ($strFileType == ".jpg" || $strFileType == "jpeg") 100 $ContentType = "image/jpeg"; 101 if ($strFileType == ".wav") 102 $ContentType = "audio/wav"; 103 if ($strFileType == ".mp3") 104 $ContentType = "audio/mpeg3"; 105 if ($strFileType == ".mpg" || $strFileType == "mpeg") 106 $ContentType = "video/mpeg"; 107 if ($strFileType == ".rtf") 108 $ContentType = "application/rtf"; 109 if ($strFileType == ".htm" || $strFileType == "html") 110 $ContentType = "text/html"; 111 if ($strFileType == ".xml") 112 $ContentType = "text/xml"; 113 if ($strFileType == ".xsl") 114 $ContentType = "text/xsl"; 115 if ($strFileType == ".css") 116 $ContentType = "text/css"; 117 if ($strFileType == ".php") 118 $ContentType = "text/php"; 119 if ($strFileType == ".asp") 120 $ContentType = "text/asp"; 121 if ($strFileType == ".pdf") 122 $ContentType = "application/pdf"; 123 if ($strFileType == ".txt") 124 $ContentType = "text/plain"; 125 if ($strFileType == ".log") 126 $ContentType = "text/plain"; 127 if ($strFileType == ".wmv") 128 $ContentType = "video/x-ms-wmv"; 129 if ($strFileType == ".sxc") 130 $ContentType = "application/vnd.sun.xml.calc"; 131 if ($strFileType == ".odt") 132 $ContentType = "application/vnd.oasis.opendocument.text"; 133 if ($strFileType == ".stc") 134 $ContentType = "application/vnd.sun.xml.calc.template"; 135 if ($strFileType == ".sxd") 136 $ContentType = "application/vnd.sun.xml.draw"; 137 if ($strFileType == ".std") 138 $ContentType = "application/vnd.sun.xml.draw.template"; 139 if ($strFileType == ".sxi") 140 $ContentType = "application/vnd.sun.xml.impress"; 141 if ($strFileType == ".sti") 142 $ContentType = "application/vnd.sun.xml.impress.template"; 143 if ($strFileType == ".sxm") 144 $ContentType = "application/vnd.sun.xml.math"; 145 if ($strFileType == ".sxw") 146 $ContentType = "application/vnd.sun.xml.writer"; 147 if ($strFileType == ".sxq") 148 $ContentType = "application/vnd.sun.xml.writer.global"; 149 if ($strFileType == ".stw") 150 $ContentType = "application/vnd.sun.xml.writer.template"; 151 if ($strFileType == ".ps") 152 $ContentType = "application/postscript"; 153 if ($strFileType == ".pps") 154 $ContentType = "application/vnd.ms-powerpoint"; 155 if ($strFileType == ".odt") 156 $ContentType = "application/vnd.oasis.opendocument.text"; 157 if ($strFileType == ".ott") 158 $ContentType = "application/vnd.oasis.opendocument.text-template"; 159 if ($strFileType == ".oth") 160 $ContentType = "application/vnd.oasis.opendocument.text-web"; 161 if ($strFileType == ".odm") 162 $ContentType = "application/vnd.oasis.opendocument.text-master"; 163 if ($strFileType == ".odg") 164 $ContentType = "application/vnd.oasis.opendocument.graphics"; 165 if ($strFileType == ".otg") 166 $ContentType = "application/vnd.oasis.opendocument.graphics-template"; 167 if ($strFileType == ".odp") 168 $ContentType = "application/vnd.oasis.opendocument.presentation"; 169 if ($strFileType == ".otp") 170 $ContentType = "application/vnd.oasis.opendocument.presentation-template"; 171 if ($strFileType == ".ods") 172 $ContentType = "application/vnd.oasis.opendocument.spreadsheet"; 173 if ($strFileType == ".ots") 174 $ContentType = "application/vnd.oasis.opendocument.spreadsheet-template"; 175 if ($strFileType == ".odc") 176 $ContentType = "application/vnd.oasis.opendocument.chart"; 177 if ($strFileType == ".odf") 178 $ContentType = "application/vnd.oasis.opendocument.formula"; 179 if ($strFileType == ".odi") 180 $ContentType = "application/vnd.oasis.opendocument.image"; 181 if ($strFileType == ".ndl") 182 $ContentType = "application/vnd.lotus-notes"; 183 if ($strFileType == ".eml") 184 $ContentType = "text/plain"; 185 186 header ("Content-Type: $ContentType"); 187 header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); 188 header("Pragma: public"); 189 header("Expires: 0"); // set expiration time 190 header ("Content-Disposition: attachment; filename=\"". addslashes($newFileName)."\""); 191 192 if($fileContent) 44 /* 45 * Requires 46 */ 47 if( $indexFile ) 48 require_once '../../header.inc.php'; 49 else 50 require_once '../../header.session.inc.php'; 51 52 53 /* 54 * Functions 55 */ 56 57 function unhtmlentities($string) 58 { 59 $string = utf8_encode($string); 60 61 static $trans_tbl; 62 63 $string = preg_replace('~&#x([0-9a-f]+);~ei', 'code2utf(hexdec("\\1"))', $string); 64 $string = preg_replace('~&#([0-9]+);~e', 'code2utf(\\1)', $string); 65 66 if (!isset($trans_tbl)) 193 67 { 194 echo $fileContent; 68 $trans_tbl = array(); 69 70 foreach (get_html_translation_table(HTML_ENTITIES) as $val=>$key) 71 $trans_tbl[$key] = utf8_encode($val); 195 72 } 196 else 197 { 198 $tempDir = $GLOBALS['phpgw_info']['server']['download_temp_dir']; 199 if (preg_match("#^".$tempDir."/(".$GLOBALS['phpgw']->session->sessionid."/)*[A-z0-9_]+_".$GLOBALS['phpgw']->session->sessionid."[A-z0-9]*(\.[A-z]{3,4})?$#",$strFileName)) 200 { 201 //avoid stuck request 202 session_write_close(); 203 204 //reset time limit for big files 205 set_time_limit(0); 206 ob_end_flush(); 207 208 if ($fp = fopen ($strFileName, 'rb')) 209 { 210 $bufferSize=1024; 211 for ($i=$bufferSize; $i<=(filesize($strFileName)+$bufferSize); $i+=$bufferSize) 73 return strtr($string, $trans_tbl); 74 } 75 76 function code2utf($num) 77 { 78 if ($num < 128) return chr($num); 79 if ($num < 2048) return chr(($num >> 6) + 192) . chr(($num & 63) + 128); 80 if ($num < 65536) return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); 81 if ($num < 2097152) return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); 82 return ''; 83 } 84 85 //-----------------------// 86 87 /* 88 * Main 89 */ 90 91 92 if($msgNumber != 'null' && $indexPart !== null && $msgFolder) 93 { 94 require_once $_SESSION['rootPath'].'/expressoMail1_2/inc/class.attachment.inc.php'; 95 96 $attachment = new attachment(); 97 $attachment->setStructureFromMail($msgFolder, $msgNumber); 98 $fileContent = $attachment->getAttachment($indexPart); 99 $info = $attachment->getAttachmentInfo($indexPart); 100 $filename = $newFilename ? $newFilename : $info['name']; 101 $filename = unhtmlentities($filename); 102 } 103 else 104 { 105 if( $image && $_SESSION['phpgw_info']['expressomail']['contact_photo'] ) 212 106 { 213 echo fread($fp, $i); 214 flush(); 215 } 216 fclose ($fp); 217 } 218 219 //removendo pelo php, garante a suportabilidade cross-platform 220 cleanup( dirname( $strFileName ) ); 221 107 $image = "thumbnail"; 108 109 $photo = array( 'width' => 60, 'height' => 80, 'quality' => 100 ); 110 111 $fileContent = $_SESSION['phpgw_info']['expressomail']['contact_photo'][0]; 112 unset( $_SESSION['phpgw_info']['expressomail']['contact_photo'] ); 222 113 } 114 115 $filename = $indexFile; 116 } 117 118 $filename = $filename ? $filename : "attachment.bin"; 119 $newFilename = $newFilename ? $newFilename : $filename; 120 $newFilename = unhtmlentities($newFilename); 121 $disposition = $image ? "inline" : "attachment; filename=\"". addslashes($newFilename)."\""; 122 123 if( !$ContentType || $ContentType == 'application/octet-stream') 124 { 125 126 if( strstr($_SERVER['HTTP_USER_AGENT'],'MSIE') && $disposition != 'inline' ) 127 $ContentType = 'application-download'; 223 128 else 224 129 { 225 if (preg_match("#^".dirname( __FILE__ ) . '/../tmpLclAtt'."/source_#",$strFileName)) { 226 readfile($strFileName); 130 function guessContentType( $fileName ) 131 { 132 $strFileType = strtolower(substr ( $fileName , strrpos($fileName, '.') )); 133 134 switch( $strFileType ) 135 { 136 case ".asf": return "video/x-ms-asf"; 137 case ".avi": return "video/avi"; 138 case ".doc": return "application/msword"; 139 case ".zip": return "application/zip"; 140 case ".xls": return "application/vnd.ms-excel"; 141 case ".gif": return "image/gif"; 142 case ".bmp": return "image/bmp"; 143 case ".jpeg": 144 case ".jpg": return "image/jpeg"; 145 case ".wav": return "audio/wav"; 146 case ".mp3": return "audio/mpeg3"; 147 case ".mpeg": 148 case ".mpg": return "video/mpeg"; 149 case ".rtf": return "application/rtf"; 150 case ".html": 151 case ".htm": return "text/html"; 152 case ".xml": return "text/xml"; 153 case ".xsl": return "text/xsl"; 154 case ".css": return "text/css"; 155 case ".php": return "text/php"; 156 case ".asp": return "text/asp"; 157 case ".pdf": return "application/pdf"; 158 case ".png": return "image/png"; 159 case ".txt": return "text/plain"; 160 case ".log": return "text/plain"; 161 case ".wmv": return "video/x-ms-wmv"; 162 case ".sxc": return "application/vnd.sun.xml.calc"; 163 case ".odt": return "application/vnd.oasis.opendocument.text"; 164 case ".stc": return "application/vnd.sun.xml.calc.template"; 165 case ".sxd": return "application/vnd.sun.xml.draw"; 166 case ".std": return "application/vnd.sun.xml.draw.template"; 167 case ".sxi": return "application/vnd.sun.xml.impress"; 168 case ".sti": return "application/vnd.sun.xml.impress.template"; 169 case ".sxm": return "application/vnd.sun.xml.math"; 170 case ".sxw": return "application/vnd.sun.xml.writer"; 171 case ".sxq": return "application/vnd.sun.xml.writer.global"; 172 case ".stw": return "application/vnd.sun.xml.writer.template"; 173 case ".pps": return "application/vnd.ms-powerpoint"; 174 case ".odt": return "application/vnd.oasis.opendocument.text"; 175 case ".ott": return "application/vnd.oasis.opendocument.text-template"; 176 case ".oth": return "application/vnd.oasis.opendocument.text-web"; 177 case ".odm": return "application/vnd.oasis.opendocument.text-master"; 178 case ".odg": return "application/vnd.oasis.opendocument.graphics"; 179 case ".otg": return "application/vnd.oasis.opendocument.graphics-template"; 180 case ".odp": return "application/vnd.oasis.opendocument.presentation"; 181 case ".otp": return "application/vnd.oasis.opendocument.presentation-template"; 182 case ".ods": return "application/vnd.oasis.opendocument.spreadsheet"; 183 case ".ots": return "application/vnd.oasis.opendocument.spreadsheet-template"; 184 case ".odc": return "application/vnd.oasis.opendocument.chart"; 185 case ".odf": return "application/vnd.oasis.opendocument.formula"; 186 case ".odi": return "application/vnd.oasis.opendocument.image"; 187 case ".ndl": return "application/vnd.lotus-notes"; 188 case ".eml": return "text/plain"; 189 case ".ps" : return "application/postscript"; 190 default : return "application/octet-stream"; 227 191 } 228 192 } 193 194 $ContentType = guessContentType( $filename ); 229 195 } 230 196 } 231 197 232 233 /** 234 * Método que limpa o diretório 235 * 236 * @license http://www.gnu.org/copyleft/gpl.html GPL 237 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 238 * @sponsor Caixa Econômica Federal 239 * @param $dir 240 */ 241 function cleanup( $dir ) 242 { 198 header("Content-Type: $ContentType"); 199 header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); 200 header("Pragma: public"); 201 header("Expires: 0"); // set expiration time 202 header("Content-Disposition: $disposition"); 203 204 if( $fileContent ) 205 { 206 header("Content-transfer-encoding: ".$info["encoding"] ); 207 208 if( $image === "thumbnail" ) 209 { 210 $pic = imagecreatefromstring( $fileContent ); 211 212 if( $pic ) 213 { 214 $width = imagesx($pic); 215 $height = imagesy($pic); 216 217 if(!isset($photo)) 218 $photo = array( 'width' => 160, 'height' => max( ( 160 * $height / $width ), 1 ) ); 219 220 $thumb = imagecreatetruecolor( $photo['width'], $photo['height'] ); 221 222 if(array_key_exists('quality', $photo) && $photo['quality'] ) 223 imagecopyresampled($thumb, $pic, 0, 0, 0, 0, $photo['width'], $photo['height'], $width, $height); 224 else 225 imagecopyresized($thumb, $pic, 0, 0, 0, 0, $photo['width'], $photo['height'], $width, $height); # resize image into thumb 226 227 imagejpeg( $thumb,"", 100 ); # Thumbnail as JPEG 228 } 229 } 230 else 231 echo $fileContent; 232 } 233 else 234 { 235 /** 236 * Delete Diretorio 237 * @param string $dir 238 */ 239 function cleanup( $dir ) 240 { 243 241 if ( is_dir( $dir ) ) 244 242 { … … 260 258 } 261 259 262 } 263 //-----------------------// 264 265 /* 266 * Main 267 */ 268 269 270 if($msgNumber != 'null' && $indexPart !== null && $msgFolder) 271 { 272 273 $attachment = new attachment(PHPGW_INCLUDE_ROOT); 274 $attachment->setStructureFromMail($msgFolder, $msgNumber); 275 $fileContent = $attachment->getAttachment($indexPart); 276 277 if($newFilename) 278 $filename = $newFilename; 260 } 261 262 $tempDir = $GLOBALS['phpgw_info']['server']['download_temp_dir']; 263 264 if (preg_match("#^".$tempDir."/(".$GLOBALS['phpgw']->session->sessionid."/)*[A-z0-9_]+_".$GLOBALS['phpgw']->session->sessionid."[A-z0-9]*(\.[A-z]{3,4})?$#",$filename)) 265 { 266 session_write_close(); 267 set_time_limit(0); 268 ob_clean(); 269 flush(); 270 readfile($filename); 271 272 //removendo pelo php, garante a suportabilidade cross-platform 273 cleanup( $filename ); 274 275 } 279 276 else 280 277 { 281 $info = $attachment->getAttachmentInfo($indexPart); 282 $filename = $info['name']; 283 } 284 285 286 } 287 else 288 $filename = $indexFile; 289 290 291 $filename = $filename ? $filename : "attachment.bin"; 292 $newFilename = $newFilename ? $newFilename : $filename; 293 294 295 $strFileType = strrev(substr(strrev(strtolower($filename)),0,4)); 296 297 downloadFile($strFileType, $filename, $newFilename, $fileContent) 278 if (preg_match("#^".dirname( __FILE__ ) . '/../tmpLclAtt'."/source_#",$filename)) { 279 readfile($filename); 280 } 281 } 282 } 283 298 284 //-----------------------// 299 285
Note: See TracChangeset
for help on using the changeset viewer.