Ignore:
Timestamp:
09/24/10 16:20:17 (14 years ago)
Author:
rafaelraymundo
Message:

Ticket #1275 - anexos com caracteres especiais convertidos para underline.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/expressoMail1_2/inc/class.exporteml.inc.php

    r3273 r3289  
    9191        function createFileZip($files, $tempDir){                
    9292                $tmp_zip_filename = "email_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".zip"; 
    93                 $command = "cd " . escapeshellarg($tempDir) . " && nice zip -m9 " . escapeshellarg($tmp_zip_filename) . " " .  escapeshellcmd($files); 
     93                 
     94                if (!empty($files)) 
     95                { 
     96                    if (is_array($files)) 
     97                    { 
     98                        for ($i=0; $i < count($files); $i++) 
     99                        { 
     100                            $files[$i] = escapeshellarg($files[$i]); 
     101                        } 
     102                        $files = implode(' ', $files); 
     103                    } 
     104                    else 
     105                    { 
     106                        $files = escapeshellcmd($files); 
     107                    } 
     108                } 
     109                 
     110                $command = "cd " . escapeshellarg($tempDir) . " && nice zip -m9 " . escapeshellarg($tmp_zip_filename) . " " .  $files; 
    94111                if(!exec($command)) { 
    95                         $command = "cd " .  escapeshellarg($tempDir) . " && rm ".escapeshellcmd($files)." ". escapeshellarg($tmp_zip_filename); 
     112                        $command = "cd " .  escapeshellarg($tempDir) . " && rm ".$files." ". escapeshellarg($tmp_zip_filename); 
    96113                        exec($command); 
    97114                        return null; 
     
    464481                $imap_attachment = new imap_attachment(); 
    465482                $attachments = $imap_attachment->download_attachment($this->mbox_stream, $id_number); 
    466                 foreach($attachments as $i => $attachment){ 
    467                         if($i && $i == 'names') 
    468                                 continue; 
    469                                                                                                                                                  
     483                 
     484                $fileNames = Array(); 
    470485                         
    471                         $fileName = $this->remove_accents($attachment['name']); 
     486                for ($i = 0; $i < count($attachments); $i++) 
     487                { 
     488                   $attachments[$i]['name'] = $this->remove_accents($attachments[$i]['name']); 
     489                   $fileNames[$i] = $attachments[$i]['name']; 
     490                } 
     491 
     492                for ($i = 0; $i < count($attachments); $i++) 
     493                { 
     494                        $fileName = $attachments[$i]['name']; 
     495                        $result = array_keys($fileNames, $fileName); 
     496 
     497                        // Detecta duplicatas 
     498                        if (count($result) > 1) 
     499                        { 
     500                            for ($j = 1; $j < count($result); $j++) 
     501                            { 
     502                                $replacement = '('.$j.')$0'; 
     503                                if (preg_match('/\.\w{2,4}$/', $fileName)) 
     504                                { 
     505                                    $fileNames[$result[$j]] = preg_replace('/\.\w{2,4}$/', $replacement, $fileName); 
     506                                } 
     507                                else 
     508                                { 
     509                                    $fileNames[$result[$j]] .= "($j)"; 
     510                                } 
     511                                $attachments[$result[$j]]['name'] = $fileNames[$result[$j]]; 
     512                            } 
     513                        } 
     514                        // Fim detecta duplicatas 
     515 
    472516                        $f = fopen($tempDir . '/'.$tempSubDir.'/'.$fileName,"wb"); 
    473517                        if(!$f) 
    474518                                return False;                    
    475519                                                 
    476                         $fileNames .= "'".$fileName."' "; 
    477                         $fileContent = imap_fetchbody($this->mbox_stream, $id_number,$attachment['pid'], FT_UID); 
    478                         if($attachment['encoding'] == 'base64') 
     520                        $fileContent = imap_fetchbody($this->mbox_stream, $id_number,$attachments[$i]['pid'], FT_UID); 
     521                        if($attachments[$i]['encoding'] == 'base64') 
    479522                                fputs($f,imap_base64($fileContent)); 
    480523                        else             
     
    487530                $nameFileZip = ''; 
    488531                 
    489                 if($fileNames) { 
     532                if(!empty($fileNames)) { 
    490533                        $nameFileZip = $this -> createFileZip($fileNames, $tempDir . '/'.$tempSubDir);                                           
    491534                        if($nameFileZip) 
Note: See TracChangeset for help on using the changeset viewer.