Changeset 4348 for sandbox


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

Location:
sandbox/2.2.0.2/expressoMail1_2
Files:
3 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 = ''; 
  • sandbox/2.2.0.2/expressoMail1_2/inc/gotodownload.php

    r3369 r4348  
    88} 
    99require_once '../../header.inc.php'; 
    10  
     10        //TODO: alterar a string /tmp logo abaixo, pelo caminho temporario configurado no expresso        
     11        $GLOBALS['phpgw_info']['server']['download_temp_dir'] = "/tmp";  
    1112 
    1213        $msg_number = $_GET['msg_number']; 
    1314        $idx_file = $_GET['idx_file']; 
    14         $newfilename = html_entity_decode(rawurldecode($_GET['newfilename'])); 
     15        $newfilename = html_entity_decode(rawurldecode($_GET['newfilename'])); 
    1516        $msg_part = $_GET['msg_part']; 
    1617        $msg_folder = $_GET['msg_folder']; 
     
    162163                header("Expires: 0"); // set expiration time 
    163164                header ("Content-Disposition: attachment; filename=\"". addslashes($newFileName)."\""); 
     165                 
    164166                if($fileContent) { 
    165167                        if($encoding == 'base64') 
     
    171173                } 
    172174                else 
    173  
    174                         if (strstr($strFileName,$GLOBALS['phpgw']->session->sessionid)&&file_exists($strFileName)) 
     175                { 
     176                        $tempDir = $GLOBALS['phpgw_info']['server']['download_temp_dir']; 
     177                        if (preg_match("#^".$tempDir."/(".$GLOBALS['phpgw']->session->sessionid."/)*[A-z0-9_]+_".$GLOBALS['phpgw']->session->sessionid."[A-z0-9]*(\.[A-z]{3,4})?$#",$strFileName)) 
    175178                        { 
    176                             header("Content-Type: $ContentType"); 
    177                             header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
    178                             header("Pragma: public"); 
    179                             header("Expires: 0"); // set expiration time 
    180                             header ("Content-Disposition: attachment; filename=\"". addslashes($newFileName)."\""); 
    181                             readfile($strFileName); 
    182                         }else{ 
    183                             header("HTTP/1.1 404 Not Found"); 
     179                                //avoid stuck request 
     180                                session_write_close(); 
     181 
     182                                //reset time limit for big files 
     183                                set_time_limit(0); 
     184                                ob_end_flush(); 
     185 
     186                                if ($fp = fopen ($strFileName, 'rb')) 
     187                                { 
     188                                        $bufferSize=1024; 
     189                                        for ($i=$bufferSize; $i<=(filesize($strFileName)+$bufferSize); $i+=$bufferSize) { 
     190                                                echo fread($fp, $i); 
     191                                                flush(); 
     192                                        } 
     193                                        fclose ($fp); 
     194                                } 
     195 
     196                                //removendo pelo php, garante a suportabilidade cross-platform 
     197                                cleanup( dirname( $strFileName ) ); 
    184198                        } 
    185  
    186  
    187                         if (preg_match("#^".ini_get('session.save_path')."/(".$GLOBALS['phpgw']->session->sessionid."/)*[A-z]+_".$GLOBALS['phpgw']->session->sessionid."[A-z0-9]*(\.[A-z]{3,4})?$#",$strFileName)) 
     199                        else  
    188200                        { 
    189                                 if ( ! preg_match("#^".dirname( __FILE__ ) . '/../tmpLclAtt'."/source_#",$strFileName)) { 
    190                                         //reset time limit for big files 
    191                                         set_time_limit(0); 
    192                                         ob_end_flush(); 
    193  
    194                                         if ($fp = fopen ($strFileName, 'rb')) 
    195                                         { 
    196                                                 $bufferSize=1024; 
    197                                                 for ($i=$bufferSize; $i<=(filesize($strFileName)+$bufferSize); $i+=$bufferSize) 
    198                                                 { 
    199                                                         echo fread($fp, $i); 
    200                                                         flush(); 
    201                                                 } 
    202                                                 fclose ($fp); 
    203                                         } 
    204                                         //readfile($strFileName); 
    205  
    206                                         exec("rm -f ".escapeshellcmd(escapeshellarg($strFileName))); 
     201                                if (preg_match("#^".dirname( __FILE__ ) . '/../tmpLclAtt'."/source_#",$strFileName)) { 
     202                                        readfile($strFileName); 
    207203                                } 
    208                                 else 
    209                                         readfile($strFileName); 
    210204                        } 
     205                } 
    211206        } 
    212207?> 
  • sandbox/2.2.0.2/expressoMail1_2/js/main.js

    r4312 r4348  
    23662366 
    23672367function export_all_selected_msgs(){ 
     2368        var msgs_to_export = this.get_selected_messages();  
     2369 
    23682370        if (openTab.type[currentTab] > 1){ 
    2369                 source_msg(currentTab,current_folder); 
    2370                 return; 
    2371         } 
    2372         var msgs_to_export = this.get_selected_messages(); 
     2371                msgs_to_export = currentTab.substr(0,(currentTab.length - 2)); 
     2372        } 
    23732373 
    23742374        var handler_export_all_selected_msgs = function(data){ 
     
    23772377                        write_msg(get_lang('Error compressing messages (ZIP). Contact the administrator.')); 
    23782378                } 
    2379                 else 
    2380                         download_attachments(null, null, data, null,null,'mensagens.zip'); 
     2379                else  
     2380                {  
     2381                        if (data.substr(data.length-3, 3) == "zip") {  
     2382                                download_attachments(null, null, data, null, null,'mensagens.zip');  
     2383                        } else if (data.substr(data.length-3, 3) == "eml") {  
     2384                                //extracts the file name from file path  
     2385                                var string_start  = data.lastIndexOf("/") + 1;  
     2386                                var string_length = data.length - string_start;  
     2387                                var fname = data.substr(string_start, string_length);  
     2388                                //extracts the session_id from file name  
     2389                                var string_end  = data.lastIndexOf("_") - 5;  
     2390                                fname = fname.substr(0, string_end).concat(".eml");  
     2391                                download_attachments(null, null, data, null, null, fname);  
     2392                        } else {  
     2393                                download_attachments(null, null, data, null, null, 'mensagens');  
     2394                        }  
     2395                }  
    23812396        } 
    23822397 
Note: See TracChangeset for help on using the changeset viewer.