Ignore:
Timestamp:
07/04/08 17:14:41 (16 years ago)
Author:
niltonneto
Message:
  • Frases truncadas devido ao commit anterior, proveniente de

charset incorreto usado, foram revertidas de forma correta;

  • Correção na inserção de imagens em nova mensagem;
  • Correção de problema com mensagens que contêm caracteres

especiais conflitantes com a função unserialize no Javascript;

  • Otimização das funções IMAP: replace_links,

htmlspecialchars_encode(decode);

  • Inserção de verificações em variáveis nulas;
  • Otimização do código que carrega a cota da pasta compartilhada,

evitando várias requisições ao servidor, ou seja, trazendo as
informações do IMAP em uma requisição.
-Correção ao mover/deletar mensagens do resultado da pesquisa.

  • Função IMAP spam() foi revertida corretamente.
File:
1 edited

Legend:

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

    r325 r345  
    692692 
    693693        function replace_links($body) {                                  
    694                 // Search for links,then open the link in new window. 
    695                 //$body = @ereg_replace('[a-zA-Z]+://(([.]?[a-zA-Z0-9_/-])*)', '<a href="\\0" title="'.$this->functions->getLang("Open in New Window").'">\\0</a>',$body);         
    696                 //Search for emails, then open a new message tab. 
    697                 //$body = @ereg_replace('[a-zA-Z0-9!#$%&\'*+/=?^_`{|}~]+@([.]?[a-zA-Z0-9_/-])*', '<a title=\''.$this->functions->getLang("New Message").' -> \\0\'" onclick="Element(\'msg_number\').value=\'\\0\';new_message(\'new\',\'null\')" href="#">\\0</a>',$body);              
    698                 //$matches = array(); 
     694                $matches = array(); 
    699695                // Verify exception. 
    700                 //@preg_match("/<a href=\"notes:\/\/\//",$body,$matches); 
     696                @preg_match("/<a href=\"notes:\/\/\//",$body,$matches); 
    701697                // It no has exception,then open the link in new window. 
    702                 /*if(!count($matches)){ 
    703                         $body = @eregi_replace("<a (.*) href=", "<a \\1 target='_blank' href=", $body); 
    704                         $body = @str_replace("<a href=", "<a target='_blank' href=", $body); 
    705                         $body = @eregi_replace("target=\"\"", "target='_blank'", $body); 
    706                         $body = @eregi_replace("target=''", "target='_blank'", $body); 
    707                 }*/ 
    708                 $body = preg_replace('/(?<=[\s|(<br>)|\n|\r|;])((http(s?):\/\/((?:[\w]\.?)+(?::[\d]+)?[\/.\-~&=?%;@#,+\w]*))|((?:www?\.)(?:\w\.?)*(?::\d+)?[\/\w.\-~&=?%;@+]*))/i', '<a href="http$3://$4$5" target="_blank">http$3://$4$5</a>', $body); 
    709                 return $body; 
     698                if(count($matches)) 
     699                        return $body; 
     700                return preg_replace('/(?<=[\s|(<br>)|\n|\r|;])((http(s?):\/\/((?:[\w]\.?)+(?::[\d]+)?[\/.\-~&=?%;@#,+\w]*))|((?:www?\.)(?:\w\.?)*(?::\d+)?[\/\w.\-~&=?%;@+]*))/i', '<a href="http$3://$4$5" target="_blank">http$3://$4$5</a>', $body); 
    710701        } 
    711702 
     
    790781                $return = array(); 
    791782                 
    792                 if ($params['get_previous_msg']) 
     783                if ($params['get_previous_msg']){ 
    793784                        $return['previous_msg'] = $this->get_info_previous_msg($params); 
     785                        // Fix problem in unserialize function JS. 
     786                        $return['previous_msg']['body'] = str_replace(array('{','}'), array('&#123;','&#125;'), $return['previous_msg']['body']); 
     787                } 
    794788 
    795789                //$mbox_stream = $this->open_mbox($folder); 
     
    937931        } 
    938932 
    939         function get_folders_list() 
     933        function get_folders_list($params = null) 
    940934        { 
    941935                $mbox_stream = $this->open_mbox();               
     
    967961                                        } 
    968962                                } 
    969                                                                  
     963                                 
    970964                                $tmp_folder_parent = implode($this->imap_delimiter, $tmp_folder_parent); 
    971965                                $result[$i]['folder_parent'] = $tmp_folder_parent == 'INBOX' ? '' : $tmp_folder_parent; 
     
    992986                } 
    993987                 
    994                 if($mbox_stream) 
    995                         imap_close($mbox_stream); 
    996                 return array_merge($result2); 
     988                $current_folder = "INBOX"; 
     989                if($params && $params['folder']) 
     990                        $current_folder = $params['folder']; 
     991                return array_merge($result2, $this->get_quota(array(folder_id => $current_folder))); 
    997992        } 
    998993         
     
    11461141//////////////////////////////////////////////////////////////////////////////////////////////////// 
    11471142                //      Build CID for embedded Images!!! 
    1148                 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&amp;msg_num=(.+)?&amp;msg_part=(.+)?)"/isU'; 
     1143                $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU'; 
    11491144                $cid_imgs = ''; 
    11501145                $name_cid_files = array(); 
    11511146                preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); 
    11521147                $cid_array = array(); 
    1153                 foreach($cid_imgs[4] as $j => $val){ 
    1154                                 if ( !array_key_exists($cid_imgs[3][$j].$val, $cid_array) ) 
     1148                foreach($cid_imgs[6] as $j => $val){ 
     1149                                if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) ) 
    11551150                        { 
    1156                 $cid_array[$cid_imgs[3][$j].$val] = base_convert(microtime(), 10, 36); 
     1151                $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); 
    11571152                        } 
    1158                         $cid = $cid_array[$cid_imgs[3][$j].$val];  
     1153                        $cid = $cid_array[$cid_imgs[4][$j].$val];  
    11591154                        $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 
    11601155                         
    1161                                 if ($msg_uid != $cid_imgs[3][$j]) // The image isn't in the same mail? 
     1156                                if ($msg_uid != $cid_imgs[4][$j]) // The image isn't in the same mail? 
    11621157                                { 
    1163                                         $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[3][$j], $cid_imgs[4][$j], 'base64'); 
     1158                                        $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); 
    11641159                                        $fileName = "image_".($j).".jpg"; 
    11651160                                        $fileCode = "base64"; 
     
    11681163                                else 
    11691164                                { 
    1170                                         $attach_img = $forwarding_attachments[$cid_imgs[4][$j]-2]; 
     1165                                        $attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2]; 
    11711166                                        $file_description = unserialize(rawurldecode($attach_img)); 
    11721167 
     
    11781173                                        $fileCode = $file_description[4]; 
    11791174                                        $fileType = $this->get_file_type($file_description[2]); 
    1180                                         unset($forwarding_attachments[$cid_imgs[4][$j]-2]); 
     1175                                        unset($forwarding_attachments[$cid_imgs[6][$j]-2]); 
    11811176                                } 
    11821177                                $tempDir = ini_get("session.save_path"); 
     
    14421437                // Caso estejamos no box principal, nï¿œo ï¿œ necessï¿œrio pegar a informaᅵᅵo da mensagem anterior.                  
    14431438                if (($params['get_previous_msg']) && ($params['border_ID'] != 'null') && ($params['border_ID'] != '')) 
     1439                { 
    14441440                        $return['previous_msg'] = $this->get_info_previous_msg($params); 
     1441                        // Fix problem in unserialize function JS. 
     1442                        $return['previous_msg']['body'] = str_replace(array('{','}'), array('&#123;','&#125;'), $return['previous_msg']['body']); 
     1443                } 
    14451444                 
    14461445                $mbox_stream = $this->open_mbox($folder);        
     
    17891788        function htmlspecialchars_encode($str) 
    17901789        { 
    1791                 /*// replace  '  and  "  with htmlspecialchars */ 
    1792                 $str = ereg_replace('&', '&amp;', $str); 
    1793                 // any ampersand & that ia already in a "&amp;" should NOT be encoded 
    1794                 //$str = preg_replace("/&(?![:alnum:]*;)/", "&amp;", $str); 
    1795                 $str = ereg_replace('"', '&quot;', $str); 
    1796                 $str = ereg_replace('\'', '&#039;', $str); 
    1797                  
    1798                 $str = ereg_replace('<', '&lt;', $str); 
    1799                 $str = ereg_replace('>', '&gt;', $str); 
    1800                 // these {  and  }  must be html encoded or else they conflict with the template system 
    1801                 $str = str_replace("{", '&#123;', $str); 
    1802                 $str = str_replace("}", '&#125;', $str); 
    1803                 return $str; 
     1790                return  str_replace( array('&', '"','\'','<','>','{','}'), array('&amp;','&quot;','&#039;','&lt;','&gt;','&#123;','&#125;'), $str); 
    18041791        } 
    18051792        function htmlspecialchars_decode($str) 
    18061793        { 
    1807                 /*// replace  '  and  "  with htmlspecialchars */ 
    1808                 $str = ereg_replace('&amp;','&',  $str); 
    1809                 // any ampersand & that ia already in a "&amp;" should NOT be encoded 
    1810                 //$str = preg_replace("/&(?![:alnum:]*;)/", "&amp;", $str); 
    1811                 $str = ereg_replace('&quot;', '"', $str); 
    1812                 $str = ereg_replace('&#039;', '\'', $str); 
    1813                 $str = ereg_replace('&lt;','<', $str); 
    1814                 $str = ereg_replace('&gt;', '>', $str); 
    1815                 // these {  and  }  must be html encoded or else they conflict with the template system 
    1816                 $str = str_replace('&#123;', "{", $str); 
    1817                 $str = str_replace( '&#125;',"}", $str); 
    1818                 return $str; 
     1794                return  str_replace( array('&amp;','&quot;','&#039;','&lt;','&gt;','&#123;','&#125;'), array('&', '"','\'','<','>','{','}'), $str); 
    18191795        } 
    18201796         
     
    19251901         
    19261902        function get_quota($params){ 
    1927                 $folder_id = $params['folder_id']; 
     1903                // folder_id = user/{uid} for shared folders 
     1904                if(substr($params['folder_id'],0,5) != 'INBOX' && preg_match('/user\\'.$this->imap_delimiter.'/i', $params['folder_id'])){ 
     1905                        $array_folder =  explode($this->imap_delimiter,$params['folder_id']); 
     1906                        $folder_id = "user".$this->imap_delimiter.$array_folder[1];              
     1907                } 
     1908                // folder_id = INBOX for inbox folders 
     1909                else 
     1910                        $folder_id = "INBOX"; 
     1911                 
    19281912                if(!$this->mbox) 
    19291913                        $this->mbox = $this->open_mbox(); 
    1930                  
     1914 
    19311915                $quota = imap_get_quotaroot($this->mbox, $folder_id); 
    19321916                if($this->mbox) 
     
    19651949                $toaddress = $params['notificationto']; 
    19661950                 
    1967                 $subject = 'Confirmaᅵᅵo de leitura: ' . $params['subject']; 
     1951                $subject = 'Confirmação de leitura: ' . $params['subject']; 
    19681952                $body = 'Sua mensagem: ' . $params['subject'] . '<br>'; 
    19691953                $body .= 'foi lida por: ' . $_SESSION['phpgw_info']['expressomail']['user']['fullname'] . ' &lt;' . $_SESSION['phpgw_info']['expressomail']['user']['email'] . '&gt; em ' . date("d/m/Y H:i"); 
     
    21122096        function remove_accents($string) { 
    21132097                return strtr($string,  
    2114                 "?ï¿œ??ï¿œ?ï¿œ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵ",  
     2098                "?Ó??ó?Ý?úÁÀÃÂÄÇÉÈÊËÍÌ?ÎÏÑÕÔÓÒÖÚÙ?ÛÜ?áàãâäçéèêëíì?îïñóòõôöúù?ûüýÿ",  
    21152099                "SOZsozYYuAAAAACEEEEIIIIINOOOOOUUUUUsaaaaaceeeeiiiiinooooouuuuuyy"); 
    21162100        } 
     
    23212305                //No caso de se tratar da caixa do proprio usuario logado, utiliza a sintaxe abaixo 
    23222306                if(substr($user,0,4) != 'user') 
    2323                   $mbox_acl = imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); 
     2307                $mbox_acl = imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); 
    23242308                else 
    23252309                  $mbox_acl = imap_getacl($mbox_stream, $user); 
     
    23902374                        $msg = $header . $body; 
    23912375                        $email = $_SESSION['phpgw_info']['expressomail']['user']['email']; 
    2392                         //$tmp_file = $tmp_dir . "msg." . $email . '.'. $msg_number . time(); 
    2393                         // maybe we can get it faster with regex, don't know how :'( 
    2394                         $signature = trim(substr($header, strpos($header, 'X-DSPAM-Signature:') + 18)); 
     2376                        $username = $this->username; 
    23952377                        strtok($email, '@'); 
    23962378                        $domain = strtok('@'); 
    23972379 
     2380                        //Encontrar a assinatura do dspam no cabecalho 
     2381                        $v = explode("\r\n", $header); 
     2382                        foreach ($v as $linha){ 
     2383                                if (eregi("^X-DSPAM-Signature", $linha)) { 
     2384                                         
     2385                                        $args = explode(" ",$linha); 
     2386                                        $signature = $args[1]; 
     2387                                } 
     2388                        } 
     2389 
    23982390                        // feed dspam 
    2399                         if ($is_spam) 
    2400                                 $cmd = str_replace( 
    2401                                                         array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##'),  
    2402                                                         array($email, $this->username, $domain, $signature), $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam'] 
    2403                                                 ); 
    2404                         else 
    2405                                 $cmd = str_replace( 
    2406                                                         array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##'), 
    2407                                                 array($email, $this->username, $domain, $signature), $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham'] 
    2408                                         ); 
    2409                          
     2391                        switch($is_spam){ 
     2392                                case 'true':  $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam']; break; 
     2393                                case 'false': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham']; break; 
     2394                        } 
     2395                        $tags = array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##'); 
     2396                        $cmd = str_replace($tags,array($email,$username,$domain,$signature),$cmd); 
    24102397                        system($cmd); 
    2411                          
    24122398                } 
    24132399                imap_close($mbox_stream); 
Note: See TracChangeset for help on using the changeset viewer.