Changeset 670 for trunk/expressoMail1_2/inc/class.exporteml.inc.php
- Timestamp:
- 02/06/09 15:34:17 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/inc/class.exporteml.inc.php
r601 r670 186 186 } 187 187 188 function export_to_archive($id_msg,$folder) { 189 $this->folder = $folder; 190 $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8"); 191 $tempDir = $_SERVER["DOCUMENT_ROOT"]."tmpLclAtt"; 192 193 $phpheader = "<?php header('Content-Type: text/plain'); 194 header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 195 header('Pragma: public'); 196 header('Expires: 0'); // set expiration time 197 header('Content-Disposition: attachment; filename=\"fonte_da_mensagem.txt\"');?>"; 198 199 $this->connectImap(); 200 $header = $this-> getHeader($id_msg); 201 $body = $this-> getBody($id_msg); 202 203 $file = "source_".md5(microtime()).".php"; 204 $f = fopen($tempDir.'/'.$file,"w"); 205 fputs($f,$phpheader.$header ."\r\n\r\n". $body); 206 fclose($f); 207 $urlPath = '../tmpLclAtt/'.$file; 208 209 imap_close($this->mbox_stream); 210 return $urlPath; 211 } 212 188 213 function remove_accents($string) { 189 214 /* … … 195 220 "áàâãäéèêëíìîïóòôõöúùûüç?\"!@#$%š&*()-=+Ž`[]{}~^,<>;:/?\\|¹²³£¢¬§ªº°ÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ", 196 221 "aaaaaeeeeiiiiooooouuuuc__________________________________________AAAAAEEEEIIIIOOOOOUUUUC"); 222 } 223 224 function get_attachments_in_array($params) { 225 $return_attachments = array(); 226 227 $id_number = $params['num_msg']; 228 $attachments =unserialize(rawurldecode($params['s_attachments'])); 229 230 $tempDir = $_SERVER["DOCUMENT_ROOT"]."tmpLclAtt"; 231 $tempSubDir = md5(microtime()); 232 exec('mkdir ' . $tempDir . '/'.$tempSubDir.'; cd ' . $tempDir . '/'.$tempSubDir); 233 234 $this-> folder = $params['folder']; 235 $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8"); 236 $this->connectImap(); 237 238 include_once("class.imap_attachment.inc.php"); 239 240 $imap_attachment = new imap_attachment(); 241 $attachments = $imap_attachment->download_attachment($this->mbox_stream, $id_number); 242 243 244 245 foreach($attachments as $i => $attachment){ 246 if($i && $i == 'names') 247 continue; 248 $fileNameReal = $this->remove_accents($attachment['name']); 249 $ContentType = $this->getFileType($fileNameReal); 250 $fileName = $fileNameReal . ".php"; 251 $f = fopen($tempDir . '/'.$tempSubDir.'/'.$fileName,"wb"); 252 if(!$f) 253 return $tempDir . '/'.$tempSubDir.'/'.$fileName; 254 255 $fileContent = imap_fetchbody($this->mbox_stream, $id_number,$attachment['pid'], FT_UID); 256 $urlPath = '../tmpLclAtt/'.$tempSubDir.'/'.$fileName; 257 258 $headers = "<?php header('Content-Type: ".$ContentType."'); 259 header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 260 header('Pragma: public'); 261 header('Expires: 0'); // set expiration time 262 header('Content-Disposition: attachment; filename=\"". addslashes($fileNameReal) ."\"');\n echo "; 263 264 if($attachment['encoding'] == 'base64') { 265 $headers.=" imap_base64('"; 266 } 267 else if($attachment['encoding'] == 'quoted_printable_decode') { 268 $headers.=" quoted_printable_decode('"; 269 } 270 $headers.=$fileContent."');?>"; 271 fputs($f,$headers); 272 273 array_push($return_attachments,array('name' => $fileName,'url' => $urlPath,'pid' =>$attachment['pid'])); 274 fclose($f); 275 } 276 imap_close($this->mbox_stream); 277 return $return_attachments; 278 } 279 280 private function getFileType($nameFile) { 281 $strFileType = strrev(substr(strrev(strtolower($nameFile)),0,4)); 282 $ContentType = "application/octet-stream"; 283 if ($strFileType == ".asf") 284 $ContentType = "video/x-ms-asf"; 285 if ($strFileType == ".avi") 286 $ContentType = "video/avi"; 287 if ($strFileType == ".doc") 288 $ContentType = "application/msword"; 289 if ($strFileType == ".zip") 290 $ContentType = "application/zip"; 291 if ($strFileType == ".xls") 292 $ContentType = "application/vnd.ms-excel"; 293 if ($strFileType == ".gif") 294 $ContentType = "image/gif"; 295 if ($strFileType == ".jpg" || $strFileType == "jpeg") 296 $ContentType = "image/jpeg"; 297 if ($strFileType == ".wav") 298 $ContentType = "audio/wav"; 299 if ($strFileType == ".mp3") 300 $ContentType = "audio/mpeg3"; 301 if ($strFileType == ".mpg" || $strFileType == "mpeg") 302 $ContentType = "video/mpeg"; 303 if ($strFileType == ".rtf") 304 $ContentType = "application/rtf"; 305 if ($strFileType == ".htm" || $strFileType == "html") 306 $ContentType = "text/html"; 307 if ($strFileType == ".xml") 308 $ContentType = "text/xml"; 309 if ($strFileType == ".xsl") 310 $ContentType = "text/xsl"; 311 if ($strFileType == ".css") 312 $ContentType = "text/css"; 313 if ($strFileType == ".php") 314 $ContentType = "text/php"; 315 if ($strFileType == ".asp") 316 $ContentType = "text/asp"; 317 if ($strFileType == ".pdf") 318 $ContentType = "application/pdf"; 319 if ($strFileType == ".txt") 320 $ContentType = "text/plain"; 321 if ($strFileType == ".log") 322 $ContentType = "text/plain"; 323 if ($strFileType == ".wmv") 324 $ContentType = "video/x-ms-wmv"; 325 if ($strFileType == ".sxc") 326 $ContentType = "application/vnd.sun.xml.calc"; 327 if ($strFileType == ".odt") 328 $ContentType = "application/vnd.oasis.opendocument.text"; 329 if ($strFileType == ".stc") 330 $ContentType = "application/vnd.sun.xml.calc.template"; 331 if ($strFileType == ".sxd") 332 $ContentType = "application/vnd.sun.xml.draw"; 333 if ($strFileType == ".std") 334 $ContentType = "application/vnd.sun.xml.draw.template"; 335 if ($strFileType == ".sxi") 336 $ContentType = "application/vnd.sun.xml.impress"; 337 if ($strFileType == ".sti") 338 $ContentType = "application/vnd.sun.xml.impress.template"; 339 if ($strFileType == ".sxm") 340 $ContentType = "application/vnd.sun.xml.math"; 341 if ($strFileType == ".sxw") 342 $ContentType = "application/vnd.sun.xml.writer"; 343 if ($strFileType == ".sxq") 344 $ContentType = "application/vnd.sun.xml.writer.global"; 345 if ($strFileType == ".stw") 346 $ContentType = "application/vnd.sun.xml.writer.template"; 347 if ($strFileType == ".ps") 348 $ContentType = "application/postscript"; 349 if ($strFileType == ".pps") 350 $ContentType = "application/vnd.ms-powerpoint"; 351 if ($strFileType == ".odt") 352 $ContentType = "application/vnd.oasis.opendocument.text"; 353 if ($strFileType == ".ott") 354 $ContentType = "application/vnd.oasis.opendocument.text-template"; 355 if ($strFileType == ".oth") 356 $ContentType = "application/vnd.oasis.opendocument.text-web"; 357 if ($strFileType == ".odm") 358 $ContentType = "application/vnd.oasis.opendocument.text-master"; 359 if ($strFileType == ".odg") 360 $ContentType = "application/vnd.oasis.opendocument.graphics"; 361 if ($strFileType == ".otg") 362 $ContentType = "application/vnd.oasis.opendocument.graphics-template"; 363 if ($strFileType == ".odp") 364 $ContentType = "application/vnd.oasis.opendocument.presentation"; 365 if ($strFileType == ".otp") 366 $ContentType = "application/vnd.oasis.opendocument.presentation-template"; 367 if ($strFileType == ".ods") 368 $ContentType = "application/vnd.oasis.opendocument.spreadsheet"; 369 if ($strFileType == ".ots") 370 $ContentType = "application/vnd.oasis.opendocument.spreadsheet-template"; 371 if ($strFileType == ".odc") 372 $ContentType = "application/vnd.oasis.opendocument.chart"; 373 if ($strFileType == ".odf") 374 $ContentType = "application/vnd.oasis.opendocument.formula"; 375 if ($strFileType == ".odi") 376 $ContentType = "application/vnd.oasis.opendocument.image"; 377 if ($strFileType == ".ndl") 378 $ContentType = "application/vnd.lotus-notes"; 379 return $ContentType; 197 380 } 198 381
Note: See TracChangeset
for help on using the changeset viewer.