Changeset 5134 for trunk/expressoMail1_2/inc/class.exporteml.inc.php
- Timestamp:
- 11/03/11 13:24:28 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/inc/class.exporteml.inc.php
r5079 r5134 17 17 var $tempDir; 18 18 19 20 /**21 * Construtor da classe ExportEml22 *23 * @license http://www.gnu.org/copyleft/gpl.html GPL24 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)25 * @sponsor Caixa Econômica Federal26 */27 19 function ExportEml() { 28 20 … … 303 295 } 304 296 297 function export_eml( $params ){ 298 299 return $this->export_msg_data( $params['msgs_to_export'], 300 $params['folder'] ); 301 } 302 305 303 function export_msg($params) { 306 $this-> folder = $params['folder'];307 $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","ISO_8859-1");308 $id_number = $params['msgs_to_export'];309 304 $tempDir = $this->tempDir; 310 $this->connectImap();311 $header = $this-> getHeader($id_number);312 $body = $this-> getBody($id_number);313 314 305 $file = "source_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".php"; 315 306 $f = fopen($tempDir.'/'.$file,"w"); 316 fputs($f, $header ."\r\n\r\n". $body);307 fputs($f, $this->export_msg_data( $params['msgs_to_export'], $params['folder'] ) ); 317 308 fclose($f); 318 309 319 imap_close($this->mbox_stream);320 310 return $tempDir.'/'.$file; 321 311 } … … 336 326 337 327 function export_to_archive($id_msg,$folder) { 338 $this-> folder = $folder;328 $this->folder = $folder; 339 329 $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","ISO_8859-1"); 340 341 330 $tempDir = $this->tempDir; 342 331 … … 344 333 $header = $this-> getHeader($id_msg); 345 334 $body = $this-> getBody($id_msg); 346 $name = md5($_SESSION[ 'phpgw_session' ][ 'session_id' ].microtime());347 335 348 //$file = $_SESSION[ 'phpgw_session' ][ 'session_id' ].$name; 349 $file = "source_".$_SESSION[ 'phpgw_session' ][ 'session_id' ]."_".time().".php"; //source_[sessao]_[timestamp].php 350 $f = fopen($tempDir . '/'.$file,"w"); 351 fputs($f,utf8_encode($header) ."\r\n\r\n". utf8_encode($body)); 336 $file = tempnam ($tempDir, 'source_#'.$id_msg); 337 $file .= '.php'; 338 $fileName = basename ($file); 339 $f = fopen($file, "w"); 340 fputs($f,$phpheader.$header ."\r\n\r\n". $body); 352 341 fclose($f); 342 $urlPath = 'tmpLclAtt/' . $fileName; 353 343 354 344 imap_close($this->mbox_stream); 355 345 return "inc/gotodownload.php?idx_file=".$tempDir . '/'.$file."&newfilename=fonte_da_mensagem.txt"; 346 } 356 347 357 }358 359 function get_attachments_in_array($params) {360 $return_attachments = array();361 362 $id_number = $params['num_msg'];363 $attachments =unserialize(rawurldecode($params['s_attachments']));364 365 $tempDir = dirname( __FILE__ ) . '/../tmpLclAtt';366 $tempSubDir = md5(microtime());367 exec('mkdir ' . $tempDir . '/'.$tempSubDir.'; cd ' . $tempDir . '/'.$tempSubDir);368 369 $this-> folder = $params['folder'];370 $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");371 $this->connectImap();372 373 include_once("class.imap_attachment.inc.php");374 375 $imap_attachment = new imap_attachment();376 $attachments = $imap_attachment->download_attachment($this->mbox_stream, $id_number);377 foreach($attachments as $i => $attachment){378 if($i && $i == 'names')379 continue;380 $fileNameReal = $this->remove_accents($attachment['name']);381 $ContentType = $this->getFileType($fileNameReal);382 $fileName = $fileNameReal . ".php";383 $f = fopen($tempDir . '/'.$tempSubDir.'/'.$fileName,"wb");384 if(!$f)385 return $tempDir . '/'.$tempSubDir.'/'.$fileName;386 387 $fileContent = imap_fetchbody($this->mbox_stream, $id_number,$attachment['pid'], FT_UID);388 $urlPath = 'tmpLclAtt/'.$tempSubDir.'/'.$fileName;389 390 $headers = "<?php header('Content-Type: ".$ContentType."');391 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');392 header('Pragma: public');393 header('Expires: 0'); // set expiration time394 header('Content-Disposition: attachment; filename=\"". addslashes($fileNameReal) ."\"');\n echo ";395 396 if($attachment['encoding'] == 'base64') {397 $headers.=" imap_base64('".$fileContent."');?>";398 }399 else if($attachment['encoding'] == 'quoted_printable_decode') {400 $headers.=" quoted_printable_decode('".$fileContent."');?>";401 }402 else {403 $headers.=" '".$fileContent."';?>";404 }405 406 fputs($f,$headers);407 408 array_push($return_attachments,array('name' => $fileName,'url' => $urlPath,'pid' =>$attachment['pid']));409 fclose($f);410 }411 imap_close($this->mbox_stream);412 return $return_attachments;413 }414 415 416 348 function remove_accents($string) { 417 349 /* … … 423 355 "áàâãäéèêëíìîïóòôõöúùûüç?\"'!@#$%š&*()-=+Ž`[]{}~^,<>;:/?\\|¹²³£¢¬§ªº°ÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ", 424 356 "aaaaaeeeeiiiiooooouuuuc___________________________________________AAAAAEEEEIIIIOOOOOUUUUC"); 425 } 426 427 357 } 358 359 function get_attachments_headers( $folder, $id_number ){ 360 361 $this->folder = mb_convert_encoding($folder, "UTF7-IMAP","UTF-8"); 362 363 $return_attachments = array(); 364 365 include_once("class.attachment.inc.php"); 366 367 $imap_attachment = new attachment(); 368 $imap_attachment->setStructureFromMail( $folder, $id_number ); 369 $attachments = $imap_attachment->getAttachmentsInfo(); 370 371 foreach($attachments as $i => $attachment){ 372 373 $fileContent = $imap_attachment->getAttachment( $attachment['pid'] ); 374 375 $headers = "<?php header('Content-Type: {$attachment['type']}'); 376 header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 377 header('Pragma: public'); 378 header('Expires: 0'); // set expiration time 379 header('Content-Disposition: attachment; filename=\"{$attachment['name']}\"');\n 380 echo '$fileContent';?>"; 381 382 $return_attachments[ $attachment['name'] ] = array( "content" => $headers, "pid" => $attachment['pid'] ); 383 } 384 385 return( $return_attachments ); 386 } 387 388 function get_attachments_in_array($params) { 389 $return_attachments = array(); 390 391 $attachments = $this->get_attachments_headers( $params['folder'], $params['num_msg'] ); 392 393 if( !empty( $attachments ) ) 394 { 395 foreach($attachments as $fileNameReal => $attachment){ 396 397 array_push($return_attachments,array('name' => $fileNameReal, 'pid' =>$attachment['pid'], 'contentType' => $this->getFileType( $fileNameReal ) )); 398 } 399 } 400 401 return $return_attachments; 402 403 } 404 428 405 private function getFileType($nameFile) { 429 406 $strFileType = strrev(substr(strrev(strtolower($nameFile)),0,4)); … … 529 506 if ($strFileType == ".eml") 530 507 $ContentType = "text/plain"; 508 if ($strFileType == ".png") 509 $ContentType = "image/png"; 531 510 return $ContentType; 532 511 } … … 534 513 function download_all_attachments($params) { 535 514 515 require_once $_SESSION['rootPath'].'/expressoMail1_2/inc/class.attachment.inc.php'; 516 $atObj = new attachment(); 517 $atObj->setStructureFromMail($params['folder'],$params['num_msg']); 518 $attachments = $atObj->getAttachmentsInfo(); 536 519 $id_number = $params['num_msg']; 537 $attachments =unserialize(rawurldecode($params['s_attachments']));538 539 520 $tempDir = $this->tempDir; 540 521 $tempSubDir = $_SESSION['phpgw_session']['session_id']; … … 543 524 $this-> folder = $params['folder']; 544 525 $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8"); 545 $this->connectImap();546 include("class.imap_attachment.inc.php");547 $imap_attachment = new imap_attachment();548 $attachments = $imap_attachment->download_attachment($this->mbox_stream, $id_number);549 526 550 527 $fileNames = Array(); … … 583 560 if(!$f) 584 561 return False; 585 586 $fileContent = imap_fetchbody($this->mbox_stream, $id_number,$attachments[$i]['pid'], FT_UID); 587 if($attachments[$i]['encoding'] == 'base64') 588 fputs($f,imap_base64($fileContent)); 589 else 562 $fileContent = $atObj->getAttachment( $attachments[$i]['pid'] ); 590 563 fputs($f,$fileContent); 591 564
Note: See TracChangeset
for help on using the changeset viewer.