Ignore:
Timestamp:
11/03/11 13:24:28 (12 years ago)
Author:
wmerlotto
Message:

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus, do modulo ExpressoMail?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/expressoMail1_2/inc/class.exporteml.inc.php

    r5079 r5134  
    1717        var $tempDir; 
    1818         
    19          
    20         /** 
    21         * Construtor da classe ExportEml 
    22         * 
    23         * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    24         * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    25         * @sponsor    Caixa Econômica Federal 
    26         */ 
    2719        function ExportEml() { 
    2820            
     
    303295    } 
    304296 
     297    function export_eml( $params ){ 
     298 
     299        return $this->export_msg_data( $params['msgs_to_export'], 
     300                                       $params['folder'] ); 
     301    } 
     302 
    305303        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']; 
    309304                $tempDir = $this->tempDir; 
    310                 $this->connectImap(); 
    311                 $header         = $this-> getHeader($id_number); 
    312                 $body           = $this-> getBody($id_number); 
    313                  
    314305                $file = "source_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".php"; 
    315306                $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'] ) ); 
    317308                fclose($f); 
    318309                 
    319                 imap_close($this->mbox_stream); 
    320310                return $tempDir.'/'.$file; 
    321311        } 
     
    336326 
    337327                function export_to_archive($id_msg,$folder) { 
    338                 $this-> folder = $folder;  
     328                $this->folder = $folder; 
    339329                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","ISO_8859-1"); 
    340                     
    341330                $tempDir = $this->tempDir; 
    342331                                  
     
    344333                $header         = $this-> getHeader($id_msg);  
    345334                $body           = $this-> getBody($id_msg);  
    346                 $name = md5($_SESSION[ 'phpgw_session' ][ 'session_id' ].microtime()); 
    347335                 
    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); 
    352341                fclose($f);  
     342                $urlPath = 'tmpLclAtt/' . $fileName; 
    353343                                  
    354344                imap_close($this->mbox_stream);  
    355345                return "inc/gotodownload.php?idx_file=".$tempDir . '/'.$file."&newfilename=fonte_da_mensagem.txt"; 
     346        } 
    356347                                  
    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 time 
    394                                 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  
    416348        function remove_accents($string) { 
    417349                /* 
     
    423355                        "áàâãäéèêëíìîïóòôõöúùûüç?\"'!@#$%š&*()-=+Ž`[]{}~^,<>;:/?\\|¹²³£¢¬§ªº°ÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ", 
    424356                        "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         
    428405        private function getFileType($nameFile) { 
    429406                $strFileType = strrev(substr(strrev(strtolower($nameFile)),0,4)); 
     
    529506                if ($strFileType == ".eml") 
    530507                        $ContentType = "text/plain"; 
     508                if ($strFileType == ".png") 
     509                        $ContentType = "image/png"; 
    531510                return $ContentType; 
    532511        } 
     
    534513        function download_all_attachments($params) { 
    535514                 
     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(); 
    536519                $id_number = $params['num_msg'];                 
    537                 $attachments =unserialize(rawurldecode($params['s_attachments'])); 
    538                  
    539520                $tempDir = $this->tempDir; 
    540521                $tempSubDir = $_SESSION['phpgw_session']['session_id']; 
     
    543524                $this-> folder = $params['folder']; 
    544525                $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); 
    549526                 
    550527                $fileNames = Array(); 
     
    583560                        if(!$f) 
    584561                                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'] );         
    590563                                fputs($f,$fileContent); 
    591564                                 
Note: See TracChangeset for help on using the changeset viewer.