Changeset 4795


Ignore:
Timestamp:
07/19/11 09:32:37 (13 years ago)
Author:
roberto.santosjunior
Message:

Ticket #1820 - Link no email, não trata url de intranet.r4649

File:
1 edited

Legend:

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

    r4784 r4795  
    8888                } 
    8989                // This condition verifies if SESSION is expired. 
    90                 elseif(!count($_SESSION))                        
     90                elseif(!count($_SESSION)) 
    9191                        return "nosession"; 
    9292 
     
    288288        */ 
    289289        function decode_string($string) 
    290     {     
    291         if ((strpos(strtolower($string), '=?iso-8859-1') !== false) || (strpos(strtolower($string), '=?windows-1252') !== false)) 
    292         { 
     290        { 
     291                if ((strpos(strtolower($string), '=?iso-8859-1') !== false) || (strpos(strtolower($string), '=?windows-1252') !== false)) 
     292                { 
    293293            $retun = ''; 
    294             $tmp = imap_mime_header_decode($string); 
    295             foreach ($tmp as $tmp1) 
     294                        $tmp = imap_mime_header_decode($string); 
     295                        foreach ($tmp as $tmp1) 
    296296            { 
    297                 $return .= $this->htmlspecialchars_encode($tmp1->text); 
     297                                $return .= $this->htmlspecialchars_encode($tmp1->text); 
    298298            } 
    299              
     299 
    300300            return str_replace("\t", "", $return); 
    301         } 
    302         else if (strpos(strtolower($string), '=?utf-8') !== false) 
    303         { 
    304             $elements = imap_mime_header_decode($string); 
    305  
    306               for($i = 0;$i < count($elements);$i++) 
    307               { 
    308                                         $charset = strtolower($elements[$i]->charset);  
    309                                         $text = $elements[$i]->text;  
    310                                         if(!strcasecmp($charset, "utf-8") || !strcasecmp($charset, "utf-7")) 
    311                                                 $decoded .= $this->functions->utf8_to_ncr($text); 
    312                   else 
    313                   { 
    314                     if( strcasecmp($charset,"default") ) 
    315                         $decoded .= $this->htmlspecialchars_encode(iconv($charset, "iso-8859-1", $text)); 
    316                     else 
    317                         $decoded .= $this->htmlspecialchars_encode($text); 
    318                   } 
    319               } 
     301                } 
     302                else if (strpos(strtolower($string), '=?utf-8') !== false) 
     303                { 
     304                        $elements = imap_mime_header_decode($string); 
     305 
     306                        for($i = 0;$i < count($elements);$i++) 
     307                        { 
     308                                $charset = strtolower($elements[$i]->charset); 
     309                                $text = $elements[$i]->text; 
     310                                if(!strcasecmp($charset, "utf-8") || !strcasecmp($charset, "utf-7")) 
     311                                $decoded .= $this->functions->utf8_to_ncr($text); 
     312                                else 
     313                                { 
     314                                        if( strcasecmp($charset,"default") ) 
     315                                                $decoded .= $this->htmlspecialchars_encode(iconv($charset, "iso-8859-1", $text)); 
     316                                        else 
     317                                                $decoded .= $this->htmlspecialchars_encode($text); 
     318                                } 
     319                        } 
    320320 
    321321              return str_replace("\t", "", $decoded); 
    322         } 
     322                } 
    323323                else if(strpos(strtolower($string), '=?us-ascii') !== false)  
    324324           {  
     
    335335         
    336336 
    337         return $this->htmlspecialchars_encode($string); 
    338     } 
     337                        return $this->htmlspecialchars_encode($string); 
     338        } 
    339339        /** 
    340340        * Função que importa arquivos .eml exportados pelo expresso para a caixa do usuário. Testado apenas 
     
    581581                return $return; 
    582582        } 
    583          
     583 
    584584        /** 
    585585        * @license   http://www.gnu.org/copyleft/gpl.html GPL 
     
    822822                 
    823823                if(preg_match('(.+)(_[a-zA-Z0-9]+)',$msg_number,$matches)) { //Verifies if it comes from a tab diferent of the main one.  
    824                         $msg_number = $matches[1];  
    825                         $plus_id = $matches[2];  
    826                 }  
    827                 else {  
    828                         $plus_id = '';  
    829                 }  
    830                  
     824                        $msg_number = $matches[1]; 
     825                        $plus_id = $matches[2]; 
     826                } 
     827                else { 
     828                        $plus_id = ''; 
     829                } 
     830 
    831831                if(!$this->mbox || !is_resource($this->mbox)) 
    832                         $this->mbox = $this->open_mbox($msg_folder);             
     832                        $this->mbox = $this->open_mbox($msg_folder); 
    833833                 
    834834                $header = $this->get_header($msg_number); 
    835835                if (!$header) { 
    836                         $return['status_get_msg_info'] = "false";                        
     836                        $return['status_get_msg_info'] = "false"; 
    837837                        return $return; 
    838838                } 
    839                  
    840                 $header_ = imap_fetchheader($this->mbox, $msg_number, FT_UID);           
     839 
     840                $header_ = imap_fetchheader($this->mbox, $msg_number, FT_UID); 
    841841                $return_get_body = $this->get_body_msg($msg_number, $msg_folder); 
    842842                $body = $return_get_body['body']; 
    843                  
     843 
    844844                if($return_get_body['body']=='isCripted'){ 
    845845                        $exporteml = new ExportEml(); 
     
    851851                        //return $return; 
    852852                }else{ 
    853             $return['body']             = $body; 
    854             $return['attachments']      = $return_get_body['attachments']; 
    855             $return['thumbs']           = $return_get_body['thumbs']; 
    856             $return['signature']        = $return_get_body['signature']; 
    857         } 
     853            $return['body']             = $body; 
     854            $return['attachments']      = $return_get_body['attachments']; 
     855            $return['thumbs']           = $return_get_body['thumbs']; 
     856            $return['signature']        = $return_get_body['signature']; 
     857                } 
    858858                $pattern = '/^[ \t]*Disposition-Notification-To:[ ]*<?[[:alnum:]\._-]+@[[:alnum:]_-]+[\.[:alnum:]]+>?/sm'; 
    859859                if (preg_match($pattern, $header_, $fields)) 
    860860                { 
    861                         if(preg_match('/[[:alnum:]\._\-]+@[[:alnum:]_\-\.]+/',$fields[0], $matches)){ 
    862                                 $return['DispositionNotificationTo'] = "<".$matches[0].">"; 
    863                         } 
     861                        if(preg_match('/[[:alnum:]\._\-]+@[[:alnum:]_\-\.]+/',$fields[0], $matches)){  
     862                                $return['DispositionNotificationTo'] = "<".$matches[0].">";  
     863                        }  
    864864                } 
    865865 
    866866                $return['Recent']       = $header->Recent; 
    867867                $return['Unseen']       = $header->Unseen; 
    868                 $return['Deleted']      = $header->Deleted;              
     868                $return['Deleted']      = $header->Deleted; 
    869869                $return['Flagged']      = $header->Flagged; 
    870870 
     
    872872                        $return['Forwarded'] = 'F'; 
    873873                } 
    874   
     874 
    875875                else { 
    876876                        $return['Answered']     = $header->Answered; 
    877                         $return['Draft']        = $header->Draft;        
    878                 } 
    879  
    880                 $return['msg_number'] = $msg_number.$plus_id;  
     877                        $return['Draft']        = $header->Draft; 
     878                } 
     879 
     880                $return['msg_number'] = $msg_number.$plus_id; 
    881881                $return['msg_folder'] = $msg_folder; 
    882          
     882 
    883883                $date_msg = gmdate("d/m/Y",$header->udate); 
    884884                if (date("d/m/Y") == $date_msg) 
     
    886886                else 
    887887                        $return['udate'] = $date_msg; 
    888                  
    889                 $return['msg_day'] = $date_msg;  
     888 
     889                $return['msg_day'] = $date_msg; 
    890890                $return['msg_hour'] = gmdate("H:i",$header->udate); 
    891                  
     891 
    892892                if (date("d/m/Y") == $date_msg) //no dia 
    893893                { 
     
    895895                        $return['smalldate'] = gmdate("H:i",$header->udate); 
    896896 
    897                         $timestamp_now = strtotime("now") + $offset;                     
     897                        $timestamp_now = strtotime("now") + $offset; 
    898898                        $timestamp_msg_time = $header->udate; 
    899899                        // $timestamp_now is GMT and $timestamp_msg_time is MailDate TZ.  
     
    901901                        $pdate = date_parse($header->MailDate); 
    902902                        $timestamp_diff = $timestamp_now - $timestamp_msg_time  + ($pdate['zone']*(-60)); 
    903                          
     903 
    904904                        if (gmdate("H",$timestamp_diff) > 0) 
    905905                        { 
     
    923923                        $return['smalldate'] = gmdate("d/m/Y",$header->udate); 
    924924                } 
    925                  
     925 
    926926                $from = $header->from; 
    927927                $return['from'] = array(); 
     
    937937                else 
    938938                        $return['from']['full'] = $return['from']['email']; 
    939                  
     939 
    940940                // Sender attribute 
    941941                $sender = $header->sender; 
    942                 $return['sender'] = array();             
     942                $return['sender'] = array(); 
    943943                $return['sender']['name'] = $this->decode_string($sender[0]->personal); 
    944944                $return['sender']['email'] = $this->decode_string($sender[0]->mailbox . "@" . $sender[0]->host); 
     
    989989                        $return['toaddress2'] = ""; 
    990990                }        
    991                  
     991 
    992992                $cc = $header->cc; 
    993993                $return['cc'] = ""; 
     
    10171017                { 
    10181018                        $return['cc'] = ""; 
    1019                 }        
     1019                } 
    10201020 
    10211021                ## 
     
    10251025                ## 
    10261026                 
    1027                 $bcc = $header->bcc; 
     1027                $bcc = $header->bcc; 
    10281028                $return['bcc'] = ""; 
    10291029                if (!empty($bcc)) 
     
    10521052                { 
    10531053                        $return['bcc'] = ""; 
    1054                 }        
     1054                } 
    10551055 
    10561056                $reply_to = $header->reply_to; 
     
    10821082                $return['reply_to'] = $this->decode_string($return['reply_to']); 
    10831083                $return['subject'] = $this->decode_string($header->fetchsubject); 
    1084                 $return['Size'] = $header->Size;                 
     1084                $return['Size'] = $header->Size; 
    10851085                $return['reply_toaddress'] = $header->reply_toaddress; 
    1086                  
     1086 
    10871087                //All this is to help in local messages 
    1088                 $return['timestamp'] = $header->udate; 
     1088                $return['timestamp'] = $header->udate; 
    10891089                $return['login'] = $_SESSION['phpgw_info']['expressomail']['user']['account_id'];//$GLOBALS['phpgw_info']['user']['account_id']; 
    10901090                $return['reply_toaddress'] = $header->reply_toaddress; 
    1091          
     1091                 
    10921092                return $return; 
    10931093        } 
     
    10991099         */  
    11001100        function utf8_to_html ($data)  
    1101         {  
     1101        { 
    11021102            return preg_replace("/([\\xC0-\\xF7]{1,1}[\\x80-\\xBF]+)/e", '$this->_utf8_to_html("\\1")', $data);  
    11031103        }  
    1104                   
     1104 
    11051105        function _utf8_to_html ($data)  
    1106         {  
     1106                {  
    11071107            $ret = 0;  
    11081108                foreach((str_split(strrev(chr((ord($data{0}) % 252 % 248 % 240 % 224 % 192) + 128) . substr($data, 1)))) as $k => $v)  
    11091109                        $ret += (ord($v) % 128) * pow(64, $k);  
    11101110                    return "&#$ret;";  
    1111         }  
     1111                }  
    11121112        //------------------------------------------------------------------------------//  
    1113          
    1114          
     1113 
     1114 
    11151115         
    11161116         
     
    11221122         */ 
    11231123        function decodeMailPart($part, $encode, $html = true) 
    1124         { 
     1124                { 
    11251125            switch (strtolower($encode)) 
    1126             { 
     1126                        { 
    11271127                case 'iso-8859-1': 
    11281128                    return $part; 
     
    11321132                    if ($html)  
    11331133                                                return  $this->utf8_to_html($part);  
    1134                         else        
     1134                else 
    11351135                                                return  utf8_decode ($part); 
    11361136                    break; 
     
    11381138                default: 
    11391139                    return mb_convert_encoding($part, 'iso-8859-1'); 
    1140                     break; 
    1141             } 
    1142         } 
    1143          
     1140                                        break; 
     1141                                } 
     1142                        } 
     1143 
    11441144         
    11451145        function get_body_msg($msg_number, $msg_folder) 
     
    11511151            require_once $_SESSION['rootPath'].'/library/mime/mimeDecode.php'; 
    11521152            require_once $_SESSION['rootPath'].'/expressoMail1_2/inc/class.attachment.inc.php'; 
    1153             include_once ("class.message_components.inc.php"); 
     1153                include_once("class.message_components.inc.php"); 
    11541154            //--------------------------------------------------------------------// 
    11551155 
    11561156            $return = array(); 
    11571157 
    1158             $msg = &new message_components($this->mbox); 
    1159             $msg->fetch_structure($msg_number); 
     1158                $msg = &new message_components($this->mbox); 
     1159                $msg->fetch_structure($msg_number); 
    11601160 
    11611161            $content = ''; 
     
    11901190            //----------------------------------------------// 
    11911191 
    1192             if(!$this->has_cid) 
    1193             { 
     1192                if(!$this->has_cid) 
     1193                { 
    11941194                    $return['thumbs']    = $this->get_thumbs($images,$msg_number,$msg_folder); 
    1195                     $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); 
    1196             } 
     1195                        $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); 
     1196                } 
    11971197 
    11981198            switch (strtolower($structure->ctype_primary)) 
    1199             { 
     1199                { 
    12001200                case 'text': 
    12011201                        if(strtolower($structure->ctype_secondary) == 'x-pkcs7-mime') 
    12021202                        { 
    1203                                 $return['body']='isCripted'; 
    1204                                 return $return; 
    1205                         } 
     1203                                $return['body']='isCripted'; 
     1204                                return $return; 
     1205                        } 
    12061206                        $attachment = array(); 
    12071207 
     
    12101210 
    12111211                        if(($msg_subtype == "html" || $msg_subtype == 'plain') && ($disposition != 'attachment')) 
    1212                         { 
    1213                                  
     1212                        { 
     1213 
    12141214 
    12151215                                if(strtolower($msg_subtype) == 'plain') 
    1216                                 { 
     1216                                        {  
    12171217                                        $content = $this->decodeMailPart($structure->body, $structure->ctype_parameters['charset'],false); 
    1218                                                                                 $content = str_replace(array('<', '>'), array(' #$<$# ', ' #$>$# '), $content); 
    1219                                         $content = htmlentities($content); 
     1218                                                $content = str_replace( array( '<', '>' ), array( ' #$<$# ', ' #$>$# ' ), $content );  
     1219                                                $content = htmlentities( $content );  
    12201220                                        $this->replace_links($content); 
    1221                                         $content = str_replace(array(' #$&lt;$# ', ' #$&gt;$# '), array('&lt;', '&gt;'), $content); 
    1222                                         $content = '<pre>' . $content . '</pre>'; 
    1223                                         $return[ 'body' ] = $content; 
    1224                                         return $return; 
    1225                                 } 
     1221                                                $content = str_replace( array( ' #$&lt;$# ', ' #$&gt;$# ' ), array( '&lt;', '&gt;' ), $content );  
     1222                                                $content = '<pre>' . $content . '</pre>';  
     1223                                                $return[ 'body' ] = $content; 
     1224                                                return $return;  
     1225                                        }  
    12261226                                                                $content = $this->decodeMailPart($structure->body, $structure->ctype_parameters['charset']); 
    1227                         } 
     1227                                } 
    12281228 
    12291229                    break; 
     
    12361236               case 'message': 
    12371237                    if(!is_array($structure->parts)) 
    1238                     { 
     1238                                { 
    12391239                        $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 
    12401240                        $content .= '<pre>'.htmlentities($this->decodeMailPart($structure->body, $structure->ctype_parameters['charset'],false)).'</pre>'; 
    12411241                        $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 
    1242                     } 
    1243                     else 
     1242                                                } 
     1243                                            else 
    12441244                        $this->builderMsgBody($structure , $content,true); 
    12451245 
     
    12501250                       $content .= ''; 
    12511251                    else  
    1252                     { 
     1252                                                                {  
    12531253                       $content .= $this->functions->getLang('Message not supported') . '. '; 
    12541254                       $content .= $this->functions->getLang('Type') . ': ' . $structure->ctype_primary . '/' . $structure->ctype_secondary; 
    1255                     } 
     1255                                                                }  
    12561256                    break; 
    1257             } 
     1257                                                                }  
    12581258 
    12591259                $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen"); 
    12601260                $this->set_messages_flag($params); 
    12611261                $content = $this->process_embedded_images($images,$msg_number,$content, $msg_folder); 
    1262                 $content = $this->replace_special_characters($content); 
     1262                $content = $this->replace_special_characters($content); 
    12631263                $this->replace_links($content); 
    12641264                $return['body'] = &$content; 
    12651265                 
    1266                 return $return;     
     1266                return $return; 
    12671267        } 
    12681268 
     
    13911391                { 
    13921392                        $body = quoted_printable_decode($body); 
    1393             
    1394                 } 
    1395                 else if ($encoding == 'base64') 
    1396                 { 
    1397                         $body = base64_decode($body); 
    1398                 } 
    1399                         // All other encodings are returned raw. 
    1400                 if (strtolower($charset) == "utf-8") 
    1401                                 return utf8_decode($body); 
    1402                 else 
    1403                                 return $body; 
    1404                 } 
     1393 
     1394                        } 
     1395        else if ($encoding == 'base64') 
     1396        { 
     1397                $body = base64_decode($body); 
     1398        } 
     1399                // All other encodings are returned raw. 
     1400                if (strtolower($charset) == "utf-8") 
     1401                        return utf8_decode($body); 
     1402        else 
     1403                        return $body; 
     1404        } 
    14051405 
    14061406                                 
     
    14171417 
    14181418            foreach ($images as $image) 
    1419             {     
     1419                { 
    14201420                $image['cid'] = eregi_replace("<", "", $image['cid']); 
    14211421                $image['cid'] = eregi_replace(">", "", $image['cid']); 
    1422                 $body = eregi_replace("<br/>", "", $body); 
     1422                                $body = eregi_replace("<br/>", "", $body); 
    14231423                $body = str_replace("src=\"cid:".$image['cid']."\"", " src=\"./inc/show_embedded_attach.php?msg_folder=$msg_folder&msg_num=$msgno&msg_part=".$image['pid']."\" ", $body); 
    14241424                $body = str_replace("src='cid:".$image['cid']."'", " src=\"./inc/show_embedded_attach.php?msg_folder=$msg_folder&msg_num=$msgno&msg_part=".$image['pid']."\" ", $body); 
    14251425                $body = str_replace("src=cid:".$image['cid'], " src=\"./inc/show_embedded_attach.php?msg_folder=$msg_folder&msg_num=$msgno&msg_part=".$image['pid']."\" ", $body);    
    1426             } 
    1427             return $body; 
     1426                        } 
     1427                return $body; 
    14281428        } 
    14291429 
     
    14321432                // Suspected TAGS! 
    14331433                // $tag_list = Array('blink','object','meta','html','link','frame','iframe','layer','ilayer','plaintext','script','style','img','applet','embed','head','frameset','xml','xmp'); 
    1434                  
     1434 
    14351435                // remove MS Office's proprietary tag 
    14361436                //$body = mb_ereg_replace('<!\-\-\[if [^!]* mso .*\]>.*<!\[endif\]\-\->', '', $body); 
    14371437                 
    1438                 // Layout problem: Change html elements  
    1439                 // with absolute position to relate position, CASE INSENSITIVE.  
    1440                 $body = @mb_eregi_replace("POSITION: ABSOLUTE;","",$body); 
     1438                // Layout problem: Change html elements 
     1439                // with absolute position to relate position, CASE INSENSITIVE. 
     1440                $body = @mb_eregi_replace("POSITION: ABSOLUTE;","",$body); 
    14411441 
    14421442                // tags to be removed doe to security reasons 
     
    14461446                        'applet','embed','frameset','xml','xmp' 
    14471447                ); 
    1448                  
     1448 
    14491449                foreach($tag_list as $index => $tag) { 
    14501450                        $body = @mb_eregi_replace("<$tag\\b[^>]*>(.*?)</$tag>", "<!-- TAG <$tag> Removed by ExpressoMail -->", $body);  
    1451                 } 
     1451                        } 
    14521452                 
    14531453                //try to wrap CSS code instead of remove STYLE tags 
     
    14781478                                                                //skip selecto '*'  
    14791479                                            continue;  
    1480                                         }  
     1480                } 
    14811481                                                                  
    14821482                                                        $selector = eregi_replace('[^#\.]*body.*', '', $selector);  
     
    14971497                                $body = str_replace($rest[1][$i],"<".$rest[2][$i].$rest[3][$i].$rest[7][$i].">",$body); 
    14981498                } 
    1499                  
     1499 
    15001500                /* 
    15011501                * Remove deslocamento a esquerda colocado pelo Outlook. 
     
    15061506            $body = mb_ereg_replace("(<p[^>]*)(margin-left:[^>;]*-[^>;]*;)([^>]*>)","\\1\\3",$body);  
    15071507            //--------------------------------------------------------------------------------------------//     
     1508 
     1509                //$body = $this->replace_links($body); 
     1510 
     1511                //Remoção de tags <span></span> para correção de erro no firefox  
     1512                $body = mb_eregi_replace("<span><span>","",$body); 
     1513                $body = mb_eregi_replace("</span></span>","",$body); 
     1514                $body =  preg_replace("/text-indent:.*;/i","", $body); 
    15081515                 
    1509                 //$body = $this->replace_links($body); 
    1510  
    1511                 //Remoção de tags <span></span> para correção de erro no firefox 
    1512                 $body = mb_eregi_replace("<span><span>","",$body);  
    1513                 $body = mb_eregi_replace("</span></span>","",$body);  
    1514                 $body = preg_replace("/text-indent:.*;/i","", $body); 
     1516                //Correção para compatibilização com Outlook, ao visualizar a mensagem  
     1517                $body = mb_ereg_replace('<!--\[','<!-- [',$body);  
     1518                $body = mb_ereg_replace('&lt;!\[endif\]--&gt;', '<![endif]-->', $body); 
    15151519                 
    1516                 //Correção para compatibilização com Outlook, ao visualizar a mensagem 
    1517                 $body = mb_ereg_replace('<!--\[','<!-- [',$body); 
    1518                 $body = mb_ereg_replace('&lt;!\[endif\]--&gt;', '<![endif]-->', $body); 
    1519                          
    15201520                return  "<div class=\"$wrapper_class\"><span>".$body.'</span></div>'; 
    1521         }        
    1522  
    1523          
    1524          
     1521        } 
     1522 
     1523 
     1524 
    15251525        function replace_links_callback($matches)   
    15261526        {  
     
    15291529            else  
    15301530                        $pref = $matches[3] = 'http';  
    1531                  
     1531 
    15321532            return '<a href="'.$pref.'://'.$matches[4].$matches[5].'" target="_blank">'.$matches[4].$matches[5].'</a>';  
    15331533        }  
    1534          
    1535          
     1534 
     1535 
    15361536        /** 
    15371537        * @license   http://www.gnu.org/copyleft/gpl.html GPL 
     
    15401540        */ 
    15411541        function replace_links(&$body) 
    1542         { 
     1542                {  
    15431543                // Trata urls do tipo aaaa.bbb.empresa   
    15441544                // Usadas na intranet.   
     
    15461546                $replacement = '<a href="://$4$5" target="_blank">$4$5</a>';  
    15471547            $body = preg_replace_callback($pattern,array( &$this, 'replace_links_callback'), $body); 
    1548                 // E-mail address in the text should create a new e-mail on ExpressoMail   
     1548                // E-mail address in the text should create a new e-mail on ExpressoMail 
    15491549                $pattern = '/( |<|&lt;|>)([A-Za-z0-9\.~?\/_=#\-]*@[A-Za-z0-9\.~?\/_=#\-]*)( |>|&gt;|<)/im';  
    1550                 $replacement = '$1<a href="mailto:$2">$2</a>$3';  
    1551                 $body = preg_replace($pattern, $replacement, $body);  
    1552                               
    1553         }  
     1550                $replacement = '$1<a href="mailto:$2">$2</a>$3'; 
     1551                $body = preg_replace( $pattern, $replacement, $body ); 
     1552 
     1553        } 
    15541554 
    15551555        function get_signature($msg, $msg_number, $msg_folder) 
     
    16671667        { 
    16681668 
    1669             $thumbs_array = array(); 
    1670             $i = 0; 
     1669                $thumbs_array = array(); 
     1670                $i = 0; 
    16711671 
    16721672            foreach ($images as $x => $image) 
    1673             { 
     1673        { 
    16741674                 if($x && $x == 'names') 
    16751675                    continue; 
     
    16791679                                 $anchor = "<a class=\"expressomail-thumbs-link\" onMouseDown='save_image(event,this,\"".$image['type']."\")' href=\"".$href."\" onclick=\"window.open('".$href."','mywindow','width=700,height=600,scrollbars=yes');return false;\">". $img ."</a>"; 
    16801680                 $thumbs_array[] = $anchor;  
    1681                  $i++; 
     1681                        $i++; 
    16821682                
    1683             } 
    1684             return $thumbs_array; 
     1683                } 
     1684        return $thumbs_array; 
    16851685        } 
    16861686 
     
    17021702        function delete_msgs($params) 
    17031703        { 
    1704                  
     1704 
    17051705                $folder = $params['folder']; 
    17061706                $folder =  mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); 
    17071707                $msgs_number = explode(",",$params['msgs_number']); 
    17081708                $border_ID = $params['border_ID']; 
    1709                  
     1709 
    17101710                $return = array(); 
    1711                  
     1711 
    17121712                if ($params['get_previous_msg']){ 
    17131713                        $return['previous_msg'] = $this->get_info_previous_msg($params); 
     
    17161716                } 
    17171717 
    1718                 //$mbox_stream = $this->open_mbox($folder);              
     1718                //$mbox_stream = $this->open_mbox($folder); 
    17191719                $mbox_stream = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error())))); 
    1720                  
     1720 
    17211721                foreach ($msgs_number as $msg_number) 
    17221722                { 
     
    17241724                                $return['msgs_number'][] = $msg_number; 
    17251725                } 
    1726                  
     1726 
    17271727                $return['folder'] = $folder; 
    17281728                $return['border_ID'] = $border_ID; 
    1729                  
     1729 
    17301730                if($mbox_stream) 
    17311731                        imap_close($mbox_stream, CL_EXPUNGE); 
     
    24842484        * @param     $forwarding_attachments anexos 
    24852485        */ 
    2486         function buildEmbeddedImages(&$mail,$msg_uid,&$forwarding_attachments) 
    2487         { 
    2488                 //Build CID for embedded Images!!! 
    2489                 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU'; 
    2490                 $cid_imgs = ''; 
    2491                 preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); 
    2492                 $cid_array = array(); 
    2493  
    2494                 foreach($cid_imgs[6] as $j => $val){ 
    2495                         if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) ) 
    2496                         { 
    2497                                 $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); 
    2498                         } 
    2499                         $cid = $cid_array[$cid_imgs[4][$j].$val]; 
    2500  
    2501                         $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 
     2486        function buildEmbeddedImages(&$mail,$msg_uid,&$forwarding_attachments)  
     2487        {  
     2488                //      Build CID for embedded Images!!!  
     2489                $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU';  
     2490                $cid_imgs = '';  
     2491                preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER);  
     2492                $cid_array = array();  
     2493 
     2494                foreach($cid_imgs[6] as $j => $val){  
     2495                        if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) )  
     2496                        {  
     2497                                $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36);  
     2498                        }  
     2499                        $cid = $cid_array[$cid_imgs[4][$j].$val];   
     2500 
     2501                        $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body);  
    25022502 
    25032503                        $count    = strlen($cid_imgs[6][$j]); 
     
    25142514                        // The image is not in the same mail? 
    25152515                        if ($msg_uid != $cid_imgs[4][$j])  
    2516                         { 
    2517                                 $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); 
     2516                        {  
     2517                                $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64');  
    25182518                                $fileName = ($msg_uid != 'undefined') ? "image_".($j).".jpg" : $file_description[2]; 
    2519                                 $fileCode = "base64"; 
    2520                                 $fileType = "image/jpg"; 
    2521                                 $file_attached[0] = $cid_imgs[2][$j]; 
    2522                                 $file_attached[1] = $cid_imgs[4][$j]; 
    2523                                 $file_attached[2] = $fileName; 
     2519                                $fileCode = "base64";  
     2520                                $fileType = "image/jpg";  
     2521                                $file_attached[0] = $cid_imgs[2][$j];  
     2522                                $file_attached[1] = $cid_imgs[4][$j];  
     2523                                $file_attached[2] = $fileName;  
    25242524                                $file_attached[3] = '0.'.($j+1); 
    2525                                 $file_attached[4] = 'base64'; 
    2526                                 $file_attached[5] = strlen($fileContent); //Size of file 
     2525                                $file_attached[4] = 'base64';  
     2526                                $file_attached[5] = strlen($fileContent); //Size of file  
    25272527                                $file_attached[6] = $cid_imgs[6][$j]; 
    2528                                 $return_forward[] = $file_attached; 
     2528                                $return_forward[] = $file_attached;  
    25292529 
    25302530                                if ($file_attached[3] == $file_description[3] || $msg_uid == 'undefined') 
    25312531                                        unset($forwarding_attachments[$position]); 
    25322532                                 
    2533                         } 
    2534                         else 
    2535                         { 
    2536                                 $fileContent = $this->get_forwarding_attachment($file_description[0], $msg_uid, $file_description[3], 'base64'); 
    2537                                 $fileName = $file_description[2]; 
    2538                                 $fileCode = $file_description[4]; 
     2533                        }  
     2534                        else  
     2535                        {  
     2536                                $fileContent = $this->get_forwarding_attachment($file_description[0], $msg_uid, $file_description[3], 'base64');  
     2537                                $fileName = $file_description[2];  
     2538                                $fileCode = $file_description[4];  
    25392539                                $file_description[3] = '0.'.($j+1); 
    25402540                                $file_description[6] = $cid_imgs[6][$j]; 
    2541                                 $fileType = $this->get_file_type($file_description[2]); 
     2541                                $fileType = $this->get_file_type($file_description[2]);  
    25422542                                unset($forwarding_attachments[$position]); 
    2543                                 if (!empty($file_description)) 
    2544                                 { 
    2545                                         $file_description[5] = strlen($fileContent); //Size of file 
    2546                                         $return_forward[] = $file_description; 
    2547                                 } 
    2548                         } 
     2543                                if (!empty($file_description))  
     2544                                {  
     2545                                        $file_description[5] = strlen($fileContent); //Size of file  
     2546                                        $return_forward[] = $file_description;  
     2547                                }  
     2548                        }  
    25492549                        $tempDir = '/tmp'; 
    2550                         $file = "cidimage_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].$cid_imgs[6][$j].".dat";                                        
    2551                         $f = fopen($tempDir.'/'.$file,"w"); 
    2552                         fputs($f,$fileContent); 
    2553                         fclose($f); 
    2554  
    2555                         if ($fileContent) 
    2556                                 $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType);                                      
    2557                 } 
    2558                          
    2559                 return $return_forward; 
    2560         } 
     2550                        $file = "cidimage_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].$cid_imgs[6][$j].".dat";                                         
     2551                        $f = fopen($tempDir.'/'.$file,"w");  
     2552                        fputs($f,$fileContent);  
     2553                        fclose($f);  
     2554 
     2555                        if ($fileContent)  
     2556                                $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType);  
     2557                } 
     2558 
     2559                return $return_forward;  
     2560        }  
    25612561        function add_recipients_cert($full_address) 
    25622562        { 
     
    28742874        { 
    28752875 
    2876         include_once("class.phpmailer.php"); 
     2876                include_once("class.phpmailer.php"); 
    28772877                $mail = new PHPMailer(); 
    28782878                include_once("class.db_functions.inc.php"); 
    2879                 $toaddress    = $params['input_to']; 
    2880                 $ccaddress    = $params['input_cc']; 
     2879                $toaddress = $params['input_to']; 
     2880                $ccaddress = $params['input_cc']; 
    28812881                $ccoaddress = $params['input_cco']; 
    2882         $return_receipt = $params['input_return_receipt']; 
    2883         $is_important = $params['input_important_message']; 
    2884                 $subject      = $params['input_subject']; 
    2885                 $msg_uid      = $params['msg_id']; 
    2886                 $body         = $params['body']; 
     2882                $return_receipt = $params['input_return_receipt']; 
     2883                $is_important = $params['input_important_message']; 
     2884                $subject = $params['input_subject']; 
     2885                $msg_uid = $params['msg_id']; 
     2886                $body = $params['body']; 
    28872887                $body = str_replace("%nbsp;","&nbsp;",$body); 
    28882888                $body = preg_replace("/\n/"," ",$body); 
    28892889                $body = preg_replace("/\r/","",$body); 
    28902890                $forwarding_attachments = $params['forwarding_attachments']; 
    2891                 $attachments  = $params['FILES']; 
     2891                $attachments = $params['FILES']; 
    28922892                $return_files = $params['FILES']; 
    28932893 
    28942894                  
    28952895                $folder = $params['folder']; 
    2896                 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1");                
     2896                $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 
    28972897                // Fix problem with cyrus delimiter changes. 
    2898                 // Dots in names: enabled/disabled.                              
     2898                // Dots in names: enabled/disabled. 
    28992899                $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); 
    29002900                $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); 
    29012901                // End Fix. 
    2902                                          
     2902 
    29032903                $mail->SaveMessageInFolder = $folder; 
    29042904                $mail->SMTPDebug = false; 
    2905                                                  
     2905 
    29062906                $mail->IsSMTP(); 
    29072907                $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; 
     
    29092909                $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; 
    29102910                $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 
    2911                  
     2911 
    29122912                $mail->Sender = $mail->From; 
    29132913                $mail->SenderName = $mail->FromName; 
    29142914                $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 
    29152915                $mail->From =  $_SESSION['phpgw_info']['expressomail']['user']['email']; 
    2916                                  
     2916 
    29172917                $this->add_recipients("to", $toaddress, &$mail); 
    29182918                $this->add_recipients("cc", $ccaddress, &$mail); 
     
    29202920                $mail->IsHTML(true); 
    29212921                $mail->Body = $body; 
    2922  
     2922                 
    29232923                $return_forward = $this->buildEmbeddedImages($mail,$msg_uid,$forwarding_attachments); 
    29242924                $imagesParts = array();  
    2925                  
     2925 
    29262926                foreach ($return_forward as $value) 
    29272927                        $imagesParts[$value[6]] = $value[3];     
    29282928 
    2929                 //Build Forwarding Attachments!!!                     
    2930                 foreach($forwarding_attachments as $forwarding_attachment)  
    2931                 { 
    2932                         $file_description = unserialize(rawurldecode($forwarding_attachment)); 
     2929        //      Build Forwarding Attachments!!! 
     2930                        foreach($forwarding_attachments as $forwarding_attachment) 
     2931                        { 
     2932                                $file_description = unserialize(rawurldecode($forwarding_attachment)); 
    29332933                        $file_description = array_values($file_description);  
    29342934                                         
    2935                                 foreach($file_description as $i => $descriptor){                                  
     2935                                foreach($file_description as $i => $descriptor){ 
    29362936                                                        $file_description[$i] = eregi_replace('\'*\'','',$descriptor);  
    2937                                                 }  
    2938                                                 $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]);  
    2939                                                 $fileName = $file_description[2];  
    2940                                                   
    2941                                                 $file_description[5] = strlen($fileContent); //Size of file  
    2942                                                 $return_forward[] = $file_description;  
    2943                                           
    2944                                                 $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2]));  
    2945                 } 
    2946                  
     2937                                } 
     2938                                $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 
     2939                                $fileName = $file_description[2]; 
     2940 
     2941                                $file_description[5] = strlen($fileContent); //Size of file 
     2942                                $return_forward[] = $file_description; 
     2943 
     2944                                        $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); 
     2945                        } 
     2946 
    29472947                if ((count($return_forward) > 0) && (count($return_files) > 0)) 
    29482948                { 
     
    29512951                else if (count($return_files) < 1) 
    29522952                { 
    2953                         $return_files = $return_forward; 
    2954                 } 
    2955  
    2956                 //Build Uploading Attachments!!! 
     2953                                $return_files = $return_forward; 
     2954                } 
     2955 
     2956                //      Build Uploading Attachments!!! 
    29572957                $sizeof_attachments = count($attachments); 
    29582958                if ($sizeof_attachments) 
     
    29652965                                        switch ($image_type) 
    29662966                                        { 
    2967                                                 // Do not corrupt animated gif 
    2968                                                 //case 1: $image_big = imagecreatefromgif($attach['tmp_name']);break; 
     2967                                        // Do not corrupt animated gif 
     2968                                        //case 1: $image_big = imagecreatefromgif($attach['tmp_name']);break; 
    29692969                                                case 2:  
    29702970                                                        $image_big = imagecreatefromjpeg($attach['tmp_name']);  break; 
    29712971                                                case 3:  
    29722972                                                        $image_big = imagecreatefrompng($attach['tmp_name']); break; 
    2973                                                 case 6: 
    2974                                                         require_once("gd_functions.php"); 
    2975                                                         $image_big = imagecreatefrombmp($attach['tmp_name']); break; 
    2976                                                 default: 
    2977                                                         $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); 
    2978                                                         break; 
     2973                                        case 6: 
     2974                                                require_once("gd_functions.php"); 
     2975                                                $image_big = imagecreatefrombmp($attach['tmp_name']); break; 
     2976                                        default: 
     2977                                                $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); 
     2978                                                break; 
    29792979                                        } 
    29802980                                        header('Content-type: image/jpeg'); 
     
    30083008                                        $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); 
    30093009                                 
    3010                         } 
    3011                 } 
    3012                  
     3010                                } 
     3011                } 
     3012 
    30133013                if(!empty($mail->AltBody)) 
    3014                     $mail->ContentType = "multipart/alternative"; 
     3014            $mail->ContentType = "multipart/alternative"; 
    30153015 
    30163016                $mail->error_count = 0; // reset errors 
    30173017                $mail->SetMessageType(); 
    30183018                $header = $mail->CreateHeader(); 
    3019                 $body   = $mail->CreateBody();  
    3020  
    3021                 $mbox_stream = $this->open_mbox($folder);        
    3022                 $new_header  = str_replace("\n", "\r\n", $header); 
    3023                 $new_body    = str_replace("\n", "\r\n", $body); 
     3019                $body = $mail->CreateBody(); 
     3020 
     3021                $mbox_stream = $this->open_mbox($folder); 
     3022                $new_header = str_replace("\n", "\r\n", $header); 
     3023                $new_body = str_replace("\n", "\r\n", $body); 
    30243024                $return['append'] = imap_append($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, $new_header . $new_body, "\\Seen \\Draft"); 
    3025                 $status      = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); 
     3025                $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); 
    30263026                $return['msg_no'] = $status->uidnext - 1; 
    30273027                $return['folder_id'] = $folder; 
     
    30373037                                if (array_key_exists("name", $_attachment)) 
    30383038                                { 
    3039                                         unset($return_files[$index]); 
    3040                                         $return_files[$index] = $_attachment['name']."_SIZE_".$return_files[$index][1] = $_attachment['size']; 
    3041                                 } 
    3042                                 else 
    3043                                 { 
    3044                                         unset($return_files[$index]); 
    3045                                         $return_files[$index] = $_attachment[2]."_SIZE_". $return_files[$index][1] = $_attachment[5]; 
    3046                                 } 
    3047                         } 
    3048                 } 
    3049                  
     3039                                unset($return_files[$index]); 
     3040                                $return_files[$index] = $_attachment['name']."_SIZE_".$return_files[$index][1] = $_attachment['size']; 
     3041                        } 
     3042                        else 
     3043                        { 
     3044                                unset($return_files[$index]); 
     3045                                $return_files[$index] = $_attachment[2]."_SIZE_". $return_files[$index][1] = $_attachment[5]; 
     3046                        } 
     3047                } 
     3048                } 
     3049 
    30503050                $return['files'] = serialize($return_files); 
    30513051                $return["subject"] = $subject; 
    3052                                  
     3052 
    30533053                if (!$return['append']) 
    30543054                        $return['append'] = imap_last_error(); 
     
    35693569                "SOZsozYYuAAAAACEEEEIIIIINOOOOOUUUUUsaaaaaceeeeiiiiinooooouuuuuyy"); 
    35703570        } 
    3571          
    3572         function make_search_date($date,$before = false){  
     3571 
     3572        function make_search_date($date,$before = false){ 
    35733573 
    35743574            //TODO: Adaptar a data de acordo com o locale do sistema. 
    35753575            list($day,$month,$year) = explode("/", $date); 
    3576                         $before?$day=(int)$day+1:$day=(int)$day;  
    3577                 $timestamp = mktime(0,0,0,(int)$month,$day,(int)$year);  
    3578                 $search_date = date('d-M-Y',$timestamp); 
     3576            $before?$day=(int)$day+1:$day=(int)$day; 
     3577            $timestamp = mktime(0,0,0,(int)$month,$day,(int)$year); 
     3578            $search_date = date('d-M-Y',$timestamp); 
    35793579            return $search_date; 
    35803580 
    3581     } 
     3581        } 
    35823582 
    35833583        function search_msg( $params = false ) 
     
    36233623                                                        if(trim($filter_array[0]) == 'BEFORE' ) 
    36243624                                                        { 
    3625                                                                 $filter .= '"'.$this->make_search_date($filter_array[1],true).'"';  
    3626                                     }else{  
    3627                                                                 $filter .= '"'.$this->make_search_date($filter_array[1]).'"';  
    3628                                 }  
     3625                                                            $filter .= '"'.$this->make_search_date($filter_array[1],true).'"'; 
     3626                                                        }else{ 
     3627                                                            $filter .= '"'.$this->make_search_date($filter_array[1]).'"'; 
     3628                                                        } 
    36293629                                                } 
    36303630                                        } 
     
    36713671                                                                $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream);  
    36723672                                                                $elem['boxname'] = mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" );  
    3673                                                                 $elem['uid'] = $new_search;  
    3674                                                                 /* compare dates in ordering */  
    3675                                                                 $elem['udatecomp'] = substr ($elem['udate'], -4) ."-". substr ($elem['udate'], 3, 2) ."-". substr ($elem['udate'], 0, 2);   
     3673                                                                $elem['uid'] = $new_search; 
     3674                                                                /* compare dates in ordering */ 
     3675                                                                $elem['udatecomp'] = substr ($elem['udate'], -4) ."-". substr ($elem['udate'], 3, 2) ."-". substr ($elem['udate'], 0, 2); 
    36763676                                                                $retorno[] = $elem;  
    36773677                                                        } 
     
    37173717                                                        $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream);  
    37183718                                                        $elem['boxname'] = mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" );  
    3719                                                         $elem['uid'] = $new_search;  
    3720                                                         /* compare dates in ordering */  
     3719                                                        $elem['uid'] = $new_search; 
     3720                                                        /* compare dates in ordering */ 
    37213721                                                        $elem['udatecomp'] = substr ($elem['udate'], -4) ."-". substr ($elem['udate'], 3, 2) ."-". substr ($elem['udate'], 0, 2); 
    37223722                                                        $retorno[] = $elem; 
     
    40704070        function get_header($msg_number) 
    40714071        { 
    4072         $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); 
     4072                $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); 
    40734073                if (!is_object($header)) 
    40744074                        return false; 
     
    41064106                $f = fopen($file,"w"); 
    41074107                fputs($f,base64_encode($source)); 
    4108             fclose($f);            
     4108            fclose($f); 
    41094109                   $command = "python ".$_SESSION['rootPatch']."/expressoMail1_2/imap.py ".escapeshellarg($imap_server)." ".escapeshellarg($imap_port)." ".escapeshellarg($username)." ".escapeshellarg($password)." ".escapeshellarg($timestamp)." ".escapeshellarg($folder)." ".escapeshellarg($file); 
    41104110            $return['command']=exec(escapeshellcmd($command)); 
Note: See TracChangeset for help on using the changeset viewer.