Ignore:
Timestamp:
05/11/11 17:03:17 (13 years ago)
Author:
adriano
Message:

Ticket #1876 - Problemas na exportacao de mensagem - corrige problemas na exportacao de mensagens do Expresso Mail

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/2.2.0.2/expressoMail1_2/inc/class.exporteml.inc.php

    r4192 r4348  
    1515        var $folder; 
    1616        var $mbox_stream; 
     17        var $tempDir; 
     18         
     19        function ExportEml() { 
     20            
     21                //TODO: modificar o caminho hardcodificado '/tmp' para o definido na configuracao do expresso 
     22                //$this->tempDir = $GLOBALS['phpgw_info']['server']['temp_dir']; 
     23                $this->tempDir = '/tmp'; 
     24        } 
    1725         
    1826        function connectImap(){ 
     
    5967  
    6068                        //$subject = ereg_replace('/', '\'', $subject); 
    61                         $from = "áàâãäéèêëíìîïóòôõöúùûüç?\"!@#$%š&*()-=+Ž`[]{}~^,<>;:/?\\|¹²³£¢¬§ªº°ÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ"; 
    62                         $to =   "aaaaaeeeeiiiiooooouuuuc__________________________________________AAAAAEEEEIIIIOOOOOUUUUC"; 
     69                        $from = "áàâãäéèêëíìîïóòôõöúùûüç?\"!@#$%š&*()-=+Ž`[]{}~^,<>;:/?\\|¹²³£¢¬§ªº° .ÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ"; 
     70                        $to =   "aaaaaeeeeiiiiooooouuuuc______________________________________________AAAAAEEEEIIIIOOOOOUUUUC"; 
    6371                        $subject = strtr($subject,$from,$to); 
    64             $file =    $subject."_".$id.".eml"; 
     72 
     73                        $subject = eregi_replace("[^a-zA-Z0-9_]", "_", $subject);  
     74                        $file = $subject."_".$id.".eml";  
    6575                } else{ 
    6676                        // Se mensagem for arquivada localmente, $subject (assunto da mensagem) 
     
    6878 
    6979                        if($subject && $i){ 
    70                                 $from = "áàâãäéèêëíìîïóòôõöúùûüç?\"!@#$%š&*()-=+Ž`[]{}~^,<>;:/?\\|¹²³£¢¬§ªº°ÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ"; 
    71                                 $to =   "aaaaaeeeeiiiiooooouuuuc__________________________________________AAAAAEEEEIIIIOOOOOUUUUC"; 
     80                                $from = "áàâãäéèêëíìîïóòôõöúùûüç?\"!@#$%š&*()-=+Ž`[]{}~^,<>;:/?\\|¹²³£¢¬§ªº° .ÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ"; 
     81                                $to =   "aaaaaeeeeiiiiooooouuuuc______________________________________________AAAAAEEEEIIIIOOOOOUUUUC"; 
    7282                                $subject = strtr($subject,$from,$to); 
    73                                 //$subject = ereg_replace(':', '_', $subject); 
    74                                 //$subject = ereg_replace('/', '_', $subject); 
    75                                 $file = $subject."_".$i.".eml"; 
     83 
     84                                $subject = eregi_replace("[^a-zA-Z0-9_]", "_", $subject);  
     85 
     86                                // é necessário que a sessão faça parte do nome do arquivo para que o mesmo não venha vazio o.O  
     87                                $file = $subject."_".$i."_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".eml";   
    7688                        } else{ 
    7789                                $file = "email_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".eml"; 
     
    124136                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8"); 
    125137                $fileNames = ""; 
    126                 $tempDir = ini_get("session.save_path"); 
     138                $tempDir = $this->tempDir; 
    127139                $this->connectImap(); 
    128140                 
     
    167179        // Rommel Cysne (rommel.cysne@serpro.gov.br) 
    168180        // em 17/12/2008. 
     181        //   
     182        // Funcao alterada para que, quando houver   
     183        // apenas um arquivo a ser exportado,  
     184        // não seja criado em zip  
    169185        function makeAll($params) { 
    170186                // Exportacao de mensagens arquivadas localmente 
    171                 if($params['l_msg'] == "t"){ 
     187                if($params['l_msg'] == "t") 
     188                { 
    172189                // Recebe todos os subjects e bodies das mensagens locais selecionadas para exportacao 
    173190                // e gera arrays com os conteudos separados; 
     
    175192                $array_subjects = explode('@@',$params['subjects']); 
    176193            $array_ids = explode(',', $params['msgs_to_export']); 
    177             $tempDir = ini_get("session.save_path"); 
    178                         // Para cada mensagem selecionada sera gerado um arquivo .eml cujo titulo sera o assunto (subject) da mesma; 
     194                        $tempDir = $this->tempDir; 
     195                         
    179196                        include_once("class.imap_functions.inc.php"); 
    180197                        $imapf = new imap_functions(); 
     198 
     199                        // quando houver apenas um arquivo, exporta o .eml sem coloca-lo em zip  
     200                        if (count($array_ids)==1)  
     201                        {  
     202                                $sEMLData=$imapf->treat_base64_from_post($array_mesgs[$i]);  
     203                                $fileName=$this->CreateFileEml($sEMLData, $tempDir,'',$array_subjects[$i],$i);  
     204                                return $tempDir.'/'.$fileName;  
     205                        } 
     206 
     207                        // Para cada mensagem selecionada sera gerado um arquivo .eml cujo titulo sera o assunto (subject) da mesma; 
    181208                foreach($array_ids as $i=>$id) { 
    182209                                $sEMLData=$imapf->treat_base64_from_post($array_mesgs[$i]); 
     
    203230 
    204231            return $file; 
    205  
     232                 
     233                } else 
    206234                // Exportacao de mensagens da caixa de entrada (imap) - processo original do Expresso 
    207                 } else{ 
    208             $this-> folder = $params['folder']; 
    209             $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8"); 
    210             $array_ids = explode(',', $params['msgs_to_export']); 
    211             $error = False; 
    212             $fileNames = ""; 
    213             $tempDir = ini_get("session.save_path"); 
    214             $this->connectImap(); 
    215                         for($i = 0; $i < count($array_ids); $i++) { 
    216                         $header         = $this-> getHeader($array_ids[$i]);                                                                                     
    217                         $body           = $this-> getBody($array_ids[$i]);                       
    218                         $sEMLData       = $this -> parseEml($header, $body);                     
    219                         $fileName       = $this -> CreateFileEml($sEMLData, $tempDir, $array_ids[$i]); 
    220                          
    221                         if(!$fileName)  { 
    222                                 $error = True;                                   
    223                                 break; 
    224                         } 
    225                         else 
    226                                 $fileNames .= "\"".$fileName."\" ";                      
    227                          
    228                 } 
    229                 imap_close($this->mbox_stream); 
    230                  
    231                  
    232                 $nameFileZip = 'False';                  
    233                 if($fileNames && !$error) {                      
    234                         $nameFileZip = $this -> createFileZip($fileNames, $tempDir); 
    235                         if($nameFileZip)                         
    236                                 $file = $tempDir.'/'.$nameFileZip; 
    237                         else { 
     235                { 
     236                        $this-> folder = $params['folder']; 
     237                        $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8"); 
     238                        $array_ids = explode(',', $params['msgs_to_export']); 
     239                        $error = False; 
     240                        $fileNames = ""; 
     241                        $tempDir = $this->tempDir; 
     242                        $this->connectImap(); 
     243 
     244                        // quando houver apenas um arquivo, exporta o .eml sem coloca-lo em zip 
     245                        if (count($array_ids)==1) 
     246                        { 
     247                                $header         = $this->getHeader($array_ids[0]);                                                                                      
     248                                $body           = $this->getBody($array_ids[0]);                        
     249                                $sEMLData       = $this->parseEml($header, $body);                      
     250                                $fileName       = $this->CreateFileEml($sEMLData, $tempDir, $array_ids[0]."_".$_SESSION[ 'phpgw_session' ][ 'session_id' ]); 
     251 
     252                                imap_close($this->mbox_stream); 
     253                                if (!$fileName) { 
     254                                        return false; 
     255                                } else { 
     256                                        return $tempDir.'/'.$fileName; 
     257                                } 
     258                        } 
     259 
     260                        for($i = 0; $i < count($array_ids); $i++)  
     261                        { 
     262                                $header         = $this-> getHeader($array_ids[$i]);                                                                                    
     263                                $body           = $this-> getBody($array_ids[$i]);                      
     264                                $sEMLData       = $this -> parseEml($header, $body);                    
     265                                $fileName       = $this -> CreateFileEml($sEMLData, $tempDir, $array_ids[$i]); 
     266 
     267                                if(!$fileName)  
     268                                { 
     269                                        $error = True;                                  
     270                                        break; 
     271                                } else { 
     272                                        $fileNames .= "\"".$fileName."\" ";                      
     273                                } 
     274                        } 
     275                        imap_close($this->mbox_stream); 
     276 
     277                        $nameFileZip = 'False';                  
     278                        if($fileNames && !$error)  
     279                        { 
     280                                $nameFileZip = $this -> createFileZip($fileNames, $tempDir); 
     281                                if($nameFileZip)  
     282                                {                
     283                                        $file = $tempDir.'/'.$nameFileZip; 
     284                                } else { 
     285                                        $file = false; 
     286                                }                                                                
     287                        } 
     288                        else  
     289                        { 
    238290                                $file = false; 
    239                         }                                                                
    240                 } 
    241                 else  
    242                         $file = false; 
    243                          
    244                 return $file; 
    245         } 
     291                        } 
     292 
     293                        return $file; 
     294                } 
    246295    } 
    247296 
     
    250299                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","ISO_8859-1"); 
    251300                $id_number = $params['msgs_to_export']; 
    252                 $tempDir = ini_get("session.save_path"); 
    253                  
     301                $tempDir = $this->tempDir; 
    254302                $this->connectImap(); 
    255303                $header         = $this-> getHeader($id_number); 
     
    283331                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","ISO_8859-1"); 
    284332                    
    285                 $tempDir = $_SESSION['phpgw_info']['server']['temp_dir']; 
     333                $tempDir = $this->tempDir; 
    286334                                  
    287335                $this->connectImap();  
     
    471519                $attachments =unserialize(rawurldecode($params['s_attachments'])); 
    472520                 
    473                 $tempDir = ini_get("session.save_path"); 
     521                $tempDir = $this->tempDir; 
    474522                $tempSubDir = $_SESSION['phpgw_session']['session_id']; 
    475523                $fileNames = ''; 
Note: See TracChangeset for help on using the changeset viewer.