Changeset 1472


Ignore:
Timestamp:
09/30/09 15:18:10 (15 years ago)
Author:
rodsouza
Message:

Ticket #2 - Visualização de e-mails problemáticas.

File:
1 edited

Legend:

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

    r1467 r1472  
    88{ 
    99        var $public_functions = array 
    10         (        
     10        ( 
    1111                'get_range_msgs'                                => True, 
    1212                'get_info_msg'                                  => True, 
     
    3131                $this->imap_port          = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; 
    3232                $this->imap_delimiter = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter']; 
    33                 $this->functions          = new functions();             
     33                $this->functions          = new functions(); 
    3434                $this->has_cid = false; 
    35                  
     35 
    3636                if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') 
    3737                { 
     
    6666                } 
    6767                // This condition verifies if SESSION is expired. 
    68                 elseif(!count($_SESSION))                        
     68                elseif(!count($_SESSION)) 
    6969                        return "nosession"; 
    7070 
    7171                return $error; 
    7272        } 
    73          
     73 
    7474        function get_range_msgs2($params) 
    7575        { 
     
    7777                $msg_range_begin = $params['msg_range_begin']; 
    7878                $msg_range_end = $params['msg_range_end']; 
    79                 $sort_box_type = $params['sort_box_type'];               
     79                $sort_box_type = $params['sort_box_type']; 
    8080                $sort_box_reverse = $params['sort_box_reverse']; 
    8181                $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 
    8282                $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); 
    83                  
     83 
    8484                $return = array(); 
    8585                $i = 0; 
    8686                $num_msgs = imap_num_msg($this->mbox); 
    8787                if(is_array($sort_array_msg)){ 
    88                         foreach($sort_array_msg as $msg_number => $value)  
     88                        foreach($sort_array_msg as $msg_number => $value) 
    8989                        { 
    9090                                $temp = $this->get_info_head_msg($msg_number); 
     
    108108 
    109109 
    110                 /*Como eu preciso do atributo Importance para saber se o email é  
     110                /*Como eu preciso do atributo Importance para saber se o email é 
    111111                 * importante ou não, uso abaixo a função imap_fetchheader e busco 
    112112                 * o atributo importance nela. Isso faz com que eu acesse o cabeçalho 
     
    184184 
    185185        function decode_string($string) 
    186         {        
    187                  
     186        { 
     187 
    188188                if ((strpos(strtolower($string), '=?iso-8859-1') !== false) || (strpos(strtolower($string), '=?windows-1252') !== false)) 
    189189                { 
     
    191191                        foreach ($tmp as $tmp1) 
    192192                                $return .= $this->htmlspecialchars_encode($tmp1->text); 
    193                                  
     193 
    194194                        return $return; 
    195195                } 
     
    227227                if(!$this->mbox) 
    228228                        $this->mbox = $this->open_mbox(); 
    229                  
     229 
    230230                if( preg_match('/local_/',$params["folder"]) ) 
    231231                { 
     
    239239                $errors = array(); 
    240240                $invalid_format = false; 
    241                 $filename = $params['FILES'][0]['name'];  
     241                $filename = $params['FILES'][0]['name']; 
    242242                $params["folder"] = mb_convert_encoding($params["folder"], "UTF7-IMAP","ISO_8859-1"); 
    243243                $quota = imap_get_quotaroot($this->mbox, $params["folder"]); 
     
    323323                $return["status"] = true; 
    324324                $header = ""; 
    325                  
     325 
    326326                $headertemp = explode("\n",imap_fetchheader($this->mbox, imap_msgno($this->mbox, $params["msg_num"]))); 
    327327                foreach($headertemp as $head) {//Se eu colocar todo o header do email dá pau no append, então procuro apenas o que interessa. 
    328328                        $head1 = explode(":",$head); 
    329                         if ( (strtoupper($head1[0]) == "TO") ||  
    330                                         (strtoupper($head1[0]) == "FROM") ||  
     329                        if ( (strtoupper($head1[0]) == "TO") || 
     330                                        (strtoupper($head1[0]) == "FROM") || 
    331331                                        (strtoupper($head1[0]) == "SUBJECT") || 
    332332                                        (strtoupper($head1[0]) == "DATE") ) 
    333333                                $header .= $head."\r\n"; 
    334334                } 
    335                                  
     335 
    336336                $msg = &new message_components($this->mbox); 
    337                 $msg->fetch_structure($params["msg_num"]);/* O fetchbody tava trazendo o email com problemas na acentuação.  
    338                                                              Então uso essa classe para verificar a codificação e o charset,  
     337                $msg->fetch_structure($params["msg_num"]);/* O fetchbody tava trazendo o email com problemas na acentuação. 
     338                                                             Então uso essa classe para verificar a codificação e o charset, 
    339339                                                             para que o método decodeBody do expresso possa trazer tudo certinho*/ 
    340                  
     340 
    341341                $status = imap_append($this->mbox, 
    342342                                "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"], 
     
    346346                                                        imap_fetchbody($this->mbox,imap_msgno($this->mbox, $params["msg_num"]),"1"), 
    347347                                                        $msg->encoding[$params["msg_num"]][0], $msg->charset[$params["msg_num"]][0] 
    348                                                         )                                        
     348                                                        ) 
    349349                                        ), "\\Seen"); //Append do novo email, só com header e conteúdo sem anexos. 
    350                  
     350 
    351351                if(!$status) 
    352352                { 
     
    357357                { 
    358358                        $status = imap_status($this->mbox, "{".$this->imap_server.":".$this->imap_port."}".$params['folder'], SA_UIDNEXT); 
    359                         $return['msg_no'] = $status->uidnext - 1;  
     359                        $return['msg_no'] = $status->uidnext - 1; 
    360360                        imap_delete($this->mbox, imap_msgno($this->mbox, $params["msg_num"])); 
    361361                        imap_expunge($this->mbox); 
    362362                } 
    363                  
     363 
    364364                return $return; 
    365                  
     365 
    366366        } 
    367367 
    368368/** 
    369          *  
    370          * @return  
     369         * 
     370         * @return 
    371371         * @param $params Object 
    372372         */ 
     
    395395                        $this->mbox=false; 
    396396                        array_push($return,serialize($msg_info)); 
    397                  
     397 
    398398                        if($msg_info['Unseen'] == "U" || $msg_info['Recent'] == "N"){ 
    399                                         array_push($unseen_msgs,$msg_number);            
    400                         }                                
    401                 }                
     399                                        array_push($unseen_msgs,$msg_number); 
     400                        } 
     401                } 
    402402                if($unseen_msgs){ 
    403403                        $msgs_list = implode(",",$unseen_msgs); 
    404404                        $array_msgs = array('folder' => $new_params["msg_folder"], "msgs_to_set" => $msgs_list, "flag" => "unseen"); 
    405                         $this->set_messages_flag($array_msgs);   
    406                 } 
    407                  
     405                        $this->set_messages_flag($array_msgs); 
     406                } 
     407 
    408408                return $return; 
    409409        } 
     
    414414                $msg_number = $params['msg_number']; 
    415415                $msg_folder = $params['msg_folder']; 
    416                  
     416 
    417417                if(!$this->mbox || !is_resource($this->mbox)) 
    418                         $this->mbox = $this->open_mbox($msg_folder);             
    419                  
     418                        $this->mbox = $this->open_mbox($msg_folder); 
     419 
    420420                $header = $this->get_header($msg_number); 
    421421                if (!$header) { 
    422                         $return['status_get_msg_info'] = "false";                        
     422                        $return['status_get_msg_info'] = "false"; 
    423423                        return $return; 
    424424                } 
    425                  
     425 
    426426                $header_ = imap_fetchheader($this->mbox, $msg_number, FT_UID); 
    427427 
    428428                $return_get_body = $this->get_body_msg($msg_number, $msg_folder); 
    429                  
     429 
    430430                //Substituição de links em email para abrir no próprio expresso 
    431431                $body = mb_ereg_replace("<a[^>]*href=[\'\"]mailto:([^\"\']+)[\'\"]>([^<]+)</a>","<a href=\"javascript:new_message_to('\\1')\">\\2</a>",$return_get_body['body']); 
     
    454454                $return['Recent']       = $header->Recent; 
    455455                $return['Unseen']       = $header->Unseen; 
    456                 $return['Deleted']      = $header->Deleted;              
     456                $return['Deleted']      = $header->Deleted; 
    457457                $return['Flagged']      = $header->Flagged; 
    458458 
     
    460460                        $return['Forwarded'] = 'F'; 
    461461                } 
    462   
     462 
    463463                else { 
    464464                        $return['Answered']     = $header->Answered; 
    465                         $return['Draft']        = $header->Draft;        
     465                        $return['Draft']        = $header->Draft; 
    466466                } 
    467467 
    468468                $return['msg_number'] = $msg_number; 
    469469                $return['msg_folder'] = $msg_folder; 
    470          
     470 
    471471                $date_msg = gmdate("d/m/Y",$header->udate); 
    472472                if (date("d/m/Y") == $date_msg) 
     
    474474                else 
    475475                        $return['udate'] = $date_msg; 
    476                  
    477                 $return['msg_day'] = $date_msg;  
     476 
     477                $return['msg_day'] = $date_msg; 
    478478                $return['msg_hour'] = gmdate("H:i",$header->udate); 
    479                  
     479 
    480480                if (date("d/m/Y") == $date_msg) //no dia 
    481481                { 
     
    483483                        $return['smalldate'] = gmdate("H:i",$header->udate); 
    484484 
    485                         $timestamp_now = strtotime("now");                       
     485                        $timestamp_now = strtotime("now"); 
    486486                        $timestamp_msg_time = $header->udate; 
    487                         // $timestamp_now is GMT and $timestamp_msg_time is MailDate TZ.  
     487                        // $timestamp_now is GMT and $timestamp_msg_time is MailDate TZ. 
    488488                        // The variable $timestamp_diff is calculated without MailDate TZ. 
    489489                        $pdate = date_parse($header->MailDate); 
    490490                        $timestamp_diff = $timestamp_now - $timestamp_msg_time  + ($pdate['zone']*(-60)); 
    491                          
     491 
    492492                        if (gmdate("H",$timestamp_diff) > 0) 
    493493                        { 
     
    511511                        $return['smalldate'] = gmdate("d/m/Y",$header->udate); 
    512512                } 
    513                  
     513 
    514514                $from = $header->from; 
    515515                $return['from'] = array(); 
     
    525525                else 
    526526                        $return['from']['full'] = $return['from']['email']; 
    527                  
     527 
    528528                // Sender attribute 
    529529                $sender = $header->sender; 
    530                 $return['sender'] = array();             
     530                $return['sender'] = array(); 
    531531                $return['sender']['name'] = $this->decode_string($sender[0]->personal); 
    532532                $return['sender']['email'] = $this->decode_string($sender[0]->mailbox . "@" . $sender[0]->host); 
     
    576576                { 
    577577                        $return['toaddress2'] = "&lt;Empty&gt;"; 
    578                 }        
    579                  
     578                } 
     579 
    580580                $cc = $header->cc; 
    581581                $return['cc'] = ""; 
     
    605605                { 
    606606                        $return['cc'] = ""; 
    607                 }        
     607                } 
    608608 
    609609                ## 
     
    639639                { 
    640640                        $return['bcc'] = ""; 
    641                 }        
     641                } 
    642642 
    643643                $reply_to = $header->reply_to; 
     
    679679                return $return; 
    680680        } 
    681          
     681 
    682682        function get_body_msg($msg_number, $msg_folder) 
    683683        { 
     
    686686                $msg->fetch_structure($msg_number); 
    687687                $return = array(); 
    688                 $return['attachments'] = $this-> download_attachment($msg,$msg_number);          
     688                $return['attachments'] = $this-> download_attachment($msg,$msg_number); 
    689689                if(!$this->has_cid) 
    690690                { 
    691691                        $return['thumbs']  = $this->get_thumbs($msg,$msg_number,urlencode($msg_folder)); 
    692692                        $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); 
    693                 }                        
    694                  
     693                } 
     694 
    695695                if(!$msg->structure[$msg_number]->parts) //Simple message, only 1 piece 
    696696                { 
     
    717717                        } 
    718718                } 
    719                 else  
     719                else 
    720720                { //Complicated message, multiple parts 
    721721                        $html_body = ''; 
     
    723723                        $has_multipart = true; 
    724724                        $this->has_cid = false; 
    725                          
     725 
    726726                        if (strtolower($msg->structure[$msg_number]->subtype) == "related") 
    727727                                $this->has_cid = true; 
    728                          
     728 
    729729                        if (strtolower($msg->structure[$msg_number]->subtype) == "alternative") { 
    730730                                $show_only_html = false; 
     
    732732                                        $file_type = strtolower($msg->file_type[$msg_number][$values]); 
    733733                                        if($file_type == "text/html") 
    734                                                 $show_only_html = true;                  
     734                                                $show_only_html = true; 
    735735                                } 
    736736                        } 
     
    740740                        foreach($msg->pid[$msg_number] as $values => $msg_part) 
    741741                        { 
    742                                  
     742 
    743743                                $file_type = strtolower($msg->file_type[$msg_number][$values]); 
    744744                                if($file_type == "message/rfc822") 
    745745                                        $has_multipart = false; 
    746          
     746 
    747747                                if($file_type == "multipart/alternative") 
    748748                                        $has_multipart = false; 
    749          
    750                                 if(($file_type == "text/plain"  
     749 
     750                                if(($file_type == "text/plain" 
    751751                                        || $file_type == "text/html") 
    752752                                        && $file_type != 'attachment') 
     
    756756                                                // if TXT file size > 100kb, then it will not expand. 
    757757                                                if(!($file_type == "text/plain" && $msg->fsize[$msg_number][$values] > 102400)) { 
    758                                                         $content .= nl2br(htmlentities($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values])));                                                      
     758                                                        $content .= nl2br(htmlentities($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]))); 
    759759                                                } 
    760760                                        } 
     
    768768                                else if($file_type == "message/delivery-status"){ 
    769769                                        $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 
    770                                         $content .= nl2br($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]));                                            
     770                                        $content .= nl2br($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values])); 
    771771 
    772772                                } 
    773773                                else if($file_type == "message/rfc822" || $file_type == "text/rfc822-headers"){ 
    774                                          
     774 
    775775                                        include_once("class.imap_attachment.inc.php"); 
    776776                                        $att = new imap_attachment(); 
    777777                                        $attachments =  $att -> get_attachment_info($this->mbox,$msg_number); 
    778                                         if($attachments['number_attachments'] > 0) {                                                                                             
     778                                        if($attachments['number_attachments'] > 0) { 
    779779                                                foreach($attachments ['attachment'] as $index => $attachment){ 
    780780                                                        if(strtolower($attachment['type']) == "delivery-status" || 
    781                                                                 strtolower($attachment['type']) == "rfc822" ||                                                           
     781                                                                strtolower($attachment['type']) == "rfc822" || 
    782782                                                                strtolower($attachment['type']) == "rfc822-headers" || 
    783783                                                                strtolower($attachment['type']) == "plain" 
    784784                                                        ){ 
    785                                                                 $obj = imap_rfc822_parse_headers(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values]);                                     
    786                                                                 $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>";                                    
     785                                                                $obj = imap_rfc822_parse_headers(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values]); 
     786                                                                $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 
    787787                                                                $content .= "<br><table  style='margin:2px;border:1px solid black;background:#EAEAEA'>"; 
    788788                                                                $content .= "<tr><td><b>".$this->functions->getLang("Subject").":</b></td><td>".$this->decode_string($obj->subject)."</td></tr>"; 
     
    790790                                                                $content .= "<tr><td><b>".$this->functions->getLang("Date").":</b></td><td>".$obj->date."</td></tr>"; 
    791791                                                                $content .= "<tr><td><b>".$this->functions->getLang("TO").":</b></td><td>".$this->decode_string($obj->to[0]->mailbox."@".$obj->to[0]->host)."</td></tr>"; 
    792                                                                 $content .= !$obj->cc ? "</table><br>" :"<tr><td><b>".$this->functions->getLang("CC").":</b></td><td>".$this->decode_string($obj->cc[0]->mailbox."@".$obj->cc[0]->host)."</td></tr></table><br>";                                                                
     792                                                                $content .= !$obj->cc ? "</table><br>" :"<tr><td><b>".$this->functions->getLang("CC").":</b></td><td>".$this->decode_string($obj->cc[0]->mailbox."@".$obj->cc[0]->host)."</td></tr></table><br>"; 
    793793                                                                $ix_part =      strtolower($attachment['type']) == "delivery-status" ? 1 : 0; 
    794                                                                 $content .= nl2br($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, ($attachment['part_in_msg']+$ix_part).".1", FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]));                                                           
    795                                                                 break;                   
     794                                                                $content .= ($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, ($attachment['part_in_msg']+$ix_part).".1", FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values])); 
     795                                                                break; 
    796796                                                        } 
    797797                                                } 
     
    803803                                        $content .= nl2br(imap_base64(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID))); 
    804804                                else if(!strtolower($msg->structure[$msg_number]->subtype) == "mixed") 
    805                                         $content .= nl2br(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID));                          
    806                         } 
    807                 }  
     805                                        $content .= nl2br(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID)); 
     806                        } 
     807                } 
    808808                // Force message with flag Seen (imap_fetchbody not works correctly) 
    809                 $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen");                                
     809                $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen"); 
    810810                $this->set_messages_flag($params); 
    811811                $content = $this->process_embedded_images($msg,$msg_number,$content, $msg_folder); 
     
    814814                return $return; 
    815815        } 
    816          
     816 
    817817        function htmlfilter($body) 
    818818        { 
    819819                require_once('htmlfilter.inc'); 
    820                  
     820 
    821821                $tag_list = Array( 
    822822                                false, 
     
    891891                                          '\\1round:\\2\\1' 
    892892                                        ) 
    893                                     ),      
    894            
     893                                    ), 
     894 
    895895                          '/^style/i' => 
    896896                              Array( 
     
    918918                                '/^a$/i' => Array('target' => '"_new"') 
    919919                ); 
    920          
    921          
     920 
     921 
    922922                $trusted_body = sanitize($body, 
    923923                                $tag_list, 
     
    929929                                $add_attr_to_tag 
    930930                ); 
    931          
     931 
    932932            return $trusted_body; 
    933933        } 
    934          
     934 
    935935        function decodeBody($body, $encoding, $charset=null) 
    936936        { 
     
    944944                { 
    945945                        /* 
    946                          
     946 
    947947                        for($i=0;$i<256;$i++) { 
    948948                                $c1=dechex($i); 
     
    951951                                $myqprinta[]=$c1; 
    952952                                $myqprintb[]=chr($i); 
    953                         }                
     953                        } 
    954954                         */ 
    955955                        $body = str_replace($myqprinta,$myqprintb,($body)); 
    956956                        $body = quoted_printable_decode($body); 
    957                 while (ereg("=\n", $body))  
     957                while (ereg("=\n", $body)) 
    958958                { 
    959959                        $body = ereg_replace ("=\n", '', $body); 
    960960                } 
    961961        } 
    962         else if ($encoding == 'base64')  
     962        else if ($encoding == 'base64') 
    963963        { 
    964964                $body = base64_decode($body); 
    965965        } 
    966         else if ($encoding == '7bit')  
     966        else if ($encoding == '7bit') 
    967967        { 
    968                 $body = quoted_printable_decode($body);                                          
     968                $body = quoted_printable_decode($body); 
    969969        } 
    970970                // All other encodings are returned raw. 
     
    974974                        return $body; 
    975975        } 
    976          
     976 
    977977        function process_embedded_images($msg, $msgno, $body, $msg_folder) 
    978978        { 
     
    991991                        } 
    992992                } 
    993                  
     993 
    994994                return $body; 
    995995        } 
    996          
     996 
    997997        function replace_special_characters($body) 
    998998        { 
    999999                // Suspected TAGS! 
    1000                 /*$tag_list = Array(    
     1000                /*$tag_list = Array( 
    10011001                        'blink','object','meta', 
    10021002                        'html','link','frame', 
     
    10071007                */ 
    10081008 
    1009                 // Layout problem: Change html elements  
    1010                 // with absolute position to relate position, CASE INSENSITIVE.  
     1009                // Layout problem: Change html elements 
     1010                // with absolute position to relate position, CASE INSENSITIVE. 
    10111011                $body = @mb_eregi_replace("POSITION: ABSOLUTE;","",$body); 
    10121012 
     
    10161016 
    10171017                $body = $this-> replace_links($body); 
    1018                 $blocked_tags = array();                 
     1018                $blocked_tags = array(); 
    10191019                foreach($tag_list as $index => $tag) { 
    10201020                        $new_body = @mb_eregi_replace("<$tag", "<!--$tag", $body); 
     
    10341034        } 
    10351035 
    1036         function replace_links($body) {                                  
     1036        function replace_links($body) { 
    10371037                $matches = array(); 
    10381038                // Verify exception. 
     
    10411041                if(count($matches)) 
    10421042                        return $body; 
    1043                          
     1043 
    10441044                $pattern = '/[\s\r\n>;]+((http(s?):\/\/((?:[\w]\.?)+(?::[\d]+)?[:\/.\-~&=?%;@#,+\w]*))|((?:www?\.)(?:\w\.?)*(?::\d+)?[\:\/\w.\-~&=?%;@+]*))/i'; 
    10451045                $replacement = '<a href="http$3://$4$5" target="_blank">$1</a>'; 
    1046                 return preg_replace($pattern, $replacement, $body);  
    1047                  
     1046                return preg_replace($pattern, $replacement, $body); 
     1047 
    10481048                // Original 
    10491049                //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); 
     
    10601060                        if($temp['ContentType'] =='normal') return $sign; 
    10611061                        $file_type = strtolower($file_type); 
    1062                         if(strtolower($msg->encoding[$msg_number][$index]) == 'base64')  
     1062                        if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') 
    10631063                        { 
    1064                                 if ($file_type == 'application/x-pkcs7-signature' || $file_type == 'application/pkcs7-signature')  
     1064                                if ($file_type == 'application/x-pkcs7-signature' || $file_type == 'application/pkcs7-signature') 
    10651065                                { 
    10661066                                        if(!$this->mbox || !is_resource($this->mbox)) 
     
    11861186                        } 
    11871187                } 
    1188                 return $sign;    
     1188                return $sign; 
    11891189        } 
    11901190 
     
    12071207        return $thumbs_array; 
    12081208        } 
    1209                  
     1209 
    12101210        /*function delete_msg($params) 
    12111211        { 
    12121212                $folder = $params['folder']; 
    12131213                $msgs_to_delete = explode(",",$params['msgs_to_delete']); 
    1214                  
     1214 
    12151215                $mbox_stream = $this->open_mbox($folder); 
    1216                  
     1216 
    12171217                foreach ($msgs_to_delete as $msg_number){ 
    12181218                        imap_delete($mbox_stream, $msg_number, FT_UID); 
     
    12251225        function delete_msgs($params) 
    12261226        { 
    1227                  
     1227 
    12281228                $folder = $params['folder']; 
    12291229                $folder =  mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); 
    12301230                $msgs_number = explode(",",$params['msgs_number']); 
    12311231                $border_ID = $params['border_ID']; 
    1232                  
     1232 
    12331233                $return = array(); 
    1234                  
     1234 
    12351235                if ($params['get_previous_msg']){ 
    12361236                        $return['previous_msg'] = $this->get_info_previous_msg($params); 
     
    12391239                } 
    12401240 
    1241                 //$mbox_stream = $this->open_mbox($folder);              
     1241                //$mbox_stream = $this->open_mbox($folder); 
    12421242                $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())))); 
    1243                  
     1243 
    12441244                foreach ($msgs_number as $msg_number) 
    12451245                { 
     
    12471247                                $return['msgs_number'][] = $msg_number; 
    12481248                } 
    1249                  
     1249 
    12501250                $return['folder'] = $folder; 
    12511251                $return['border_ID'] = $border_ID; 
    1252                  
     1252 
    12531253                if($mbox_stream) 
    12541254                        imap_close($mbox_stream, CL_EXPUNGE); 
     
    12561256        } 
    12571257 
    1258                  
     1258 
    12591259        function refresh($params) 
    12601260        { 
    12611261                include_once("class.imap_attachment.inc.php"); 
    1262                 $imap_attachment = new imap_attachment();                
     1262                $imap_attachment = new imap_attachment(); 
    12631263                $folder = $params['folder']; 
    12641264                $msg_range_begin = $params['msg_range_begin']; 
    12651265                $msg_range_end = $params['msg_range_end']; 
    12661266                $msgs_existent = $params['msgs_existent']; 
    1267                 $sort_box_type = $params['sort_box_type'];               
     1267                $sort_box_type = $params['sort_box_type']; 
    12681268                $sort_box_reverse = $params['sort_box_reverse']; 
    12691269                $msgs_in_the_server = array(); 
     
    12731273                if(!count($msgs_in_the_server)) 
    12741274                        return array(); 
    1275                          
     1275 
    12761276                $num_msgs = (count($msgs_in_the_server) - imap_num_recent($this->mbox)); 
    1277                 $msgs_in_the_client = explode(",", $msgs_existent);      
     1277                $msgs_in_the_client = explode(",", $msgs_existent); 
    12781278 
    12791279                $msg_to_insert  = array_diff($msgs_in_the_server, $msgs_in_the_client); 
    12801280                $msg_to_delete = array_diff($msgs_in_the_client, $msgs_in_the_server); 
    1281                  
     1281 
    12821282                $msgs_to_exec = array(); 
    12831283                if ((count($msg_to_insert)) && ($msgs_existent)) 
     
    13051305                        } 
    13061306                } 
    1307                  
     1307 
    13081308                $return = array(); 
    13091309                $i = 0; 
     
    13111311                { 
    13121312                        /*A função imap_headerinfo não traz o cabeçalho completo, e sim alguns 
    1313                         * atributos do cabeçalho. Como eu preciso do atributo Importance  
     1313                        * atributos do cabeçalho. Como eu preciso do atributo Importance 
    13141314                        * para saber se o email é importante ou não, uso abaixo a função 
    13151315                        * imap_fetchheader e busco o atributo importance nela para passar 
     
    13231323                        $flag = preg_match('/importance *: *(.*)\r/i', $tempHeader, $importance); 
    13241324                        $return[$i]['Importance'] = $flag==0?"Normal":$importance[1]; 
    1325                          
     1325 
    13261326                        $header = $this->get_header($msg_number); 
    13271327                        if (!is_object($header)) 
     
    13301330                        $return[$i]['msg_number']       = $msg_number; 
    13311331                        $return[$i]['command']          = $command; 
    1332                          
     1332 
    13331333                        $return[$i]['msg_folder']       = $folder; 
    13341334            // Atribui o tipo (normal, signature ou cipher) ao campo Content-Type 
     
    13461346                        else 
    13471347                                $return[$i]['udate'] = $date_msg; 
    1348                          
     1348 
    13491349                        $from = $header->from; 
    13501350                        $return[$i]['from'] = array(); 
     
    13521352                        $return[$i]['from']['name'] = $tmp[0]->text; 
    13531353                        $return[$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; 
    1354                         //$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>';  
     1354                        //$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>'; 
    13551355                        if(!$return[$i]['from']['name']) 
    13561356                                $return[$i]['from']['name'] = $return[$i]['from']['email']; 
    1357                          
     1357 
    13581358                        /*$toaddress = imap_mime_header_decode($header->toaddress); 
    13591359                        $return[$i]['toaddress'] = ''; 
     
    13661366                        $return[$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; 
    13671367                        $return[$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; 
    1368                          
     1368 
    13691369                        $return[$i]['subject'] = $this->decode_string($header->fetchsubject); 
    13701370 
    13711371                        $return[$i]['Size'] = $header->Size; 
    13721372                        $return[$i]['reply_toaddress'] = $header->reply_toaddress; 
    1373                          
     1373 
    13741374                        $return[$i]['attachment'] = array(); 
    13751375                        $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); 
     
    14131413     * Se usar $params['noSharedFolders'] = true, ira retornar todas as pastas do usuário logado, 
    14141414     * excluindo as compartilhadas para ele. 
    1415      * @return Retorna um array contendo as seguintes informacoes de cada pasta: folder_unseen,  
     1415     * @return Retorna um array contendo as seguintes informacoes de cada pasta: folder_unseen, 
    14161416     * folder_id, folder_name, folder_parent e folder_hasChildren. 
    1417      */  
     1417     */ 
    14181418        function get_folders_list($params = null) 
    14191419        { 
    1420                 $mbox_stream = $this->open_mbox();               
     1420                $mbox_stream = $this->open_mbox(); 
    14211421                $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; 
    14221422                $folders_list = imap_getmailboxes($mbox_stream, $serverString, ($params && $params['noSharedFolders']) ? "INBOX/*" : "*"); 
     
    14251425                $tmp = array(); 
    14261426                $result = array(); 
    1427                  
     1427 
    14281428                if (is_array($folders_list)) { 
    14291429                        reset($folders_list); 
    14301430            $this->ldap = new ldap_functions(); 
    1431                          
     1431 
    14321432                        $i = 0; 
    14331433                        while (list($key, $val) = each($folders_list)) { 
     
    14441444                                $folder_id = $tmp_folder_id[1]; 
    14451445                                $result[$i]['folder_id'] = $folder_id; 
    1446                                  
     1446 
    14471447                                $tmp_folder_parent = explode($this->imap_delimiter, $folder_id); 
    14481448                                $result[$i]['folder_name'] = array_pop($tmp_folder_parent); 
     
    14541454                                        } 
    14551455                                } 
    1456                                  
     1456 
    14571457                                $tmp_folder_parent = implode($this->imap_delimiter, $tmp_folder_parent); 
    14581458                                $result[$i]['folder_parent'] = $tmp_folder_parent == 'INBOX' ? '' : $tmp_folder_parent; 
    1459                                          
     1459 
    14601460                                if (($val->attributes == 32) && ($result[$i]['folder_name'] != 'Inbox')) 
    14611461                                        $result[$i]['folder_hasChildren'] = 1; 
     
    14631463                                        $result[$i]['folder_hasChildren'] = 0; 
    14641464 
    1465                                 $i++;                            
     1465                                $i++; 
    14661466                        } 
    14671467                } 
    1468                  
     1468 
    14691469                foreach ($result as $folder_info) 
    14701470                { 
    14711471                        $array_tmp[] = $folder_info['folder_id']; 
    14721472                } 
    1473                  
     1473 
    14741474                natcasesort($array_tmp); 
    1475                  
     1475 
    14761476                foreach ($array_tmp as $key => $folder_id) 
    14771477                { 
    14781478                        $result2[] = $result[$key]; 
    14791479                } 
    1480                  
     1480 
    14811481                $current_folder = "INBOX"; 
    14821482                if($params && $params['folder']) 
     
    14841484                return array_merge($result2, $this->get_quota(array(folder_id => $current_folder))); 
    14851485        } 
    1486          
     1486 
    14871487        function create_mailbox($arr) 
    14881488        { 
     
    14911491                $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 
    14921492                $namebox =  mb_convert_encoding($namebox, "UTF7-IMAP", "UTF-8"); 
    1493                  
     1493 
    14941494                $result = "Ok"; 
    14951495                if(!imap_createmailbox($mbox_stream,"{".$imap_server."}$namebox")) 
    14961496                { 
    14971497                        $result = implode("<br />\n", imap_errors()); 
    1498                 }        
    1499                  
     1498                } 
     1499 
    15001500                if($mbox_stream) 
    15011501                        imap_close($mbox_stream); 
    1502                                          
     1502 
    15031503                return $result; 
    1504                  
    1505         } 
    1506          
     1504 
     1505        } 
     1506 
    15071507        function create_extra_mailbox($arr) 
    15081508        { 
     
    15111511                $mbox_stream = $this->open_mbox(); 
    15121512                $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 
    1513                 foreach($nameboxs as $key=>$tmp){                        
     1513                foreach($nameboxs as $key=>$tmp){ 
    15141514                        if($tmp != ""){ 
    15151515                                if(!imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}$tmp"))){ 
    15161516                                        $result = implode("<br />\n", imap_errors()); 
    15171517                                        if($mbox_stream) 
    1518                                                 imap_close($mbox_stream);                                        
     1518                                                imap_close($mbox_stream); 
    15191519                                        return $result; 
    15201520                                } 
     
    15251525                return true; 
    15261526        } 
    1527          
     1527 
    15281528        function delete_mailbox($arr) 
    15291529        { 
     
    15321532                $mbox_stream = $this->open_mbox(); 
    15331533                //$del_folder = imap_deletemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox"); 
    1534                  
     1534 
    15351535                $result = "Ok"; 
    15361536                $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); 
     
    15431543                return $result; 
    15441544        } 
    1545          
     1545 
    15461546        function ren_mailbox($arr) 
    15471547        { 
     
    15511551                $mbox_stream = $this->open_mbox(); 
    15521552                //$ren_folder = imap_renamemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox","{".$imap_server."}INBOX.$new_box"); 
    1553                  
     1553 
    15541554                $result = "Ok"; 
    15551555                $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); 
    15561556                $new_box = mb_convert_encoding($new_box, "UTF7-IMAP","UTF-8"); 
    1557                  
     1557 
    15581558                if(!imap_renamemailbox($mbox_stream,"{".$imap_server."}$namebox","{".$imap_server."}$new_box")) 
    15591559                { 
    1560                         $result = imap_errors();                         
     1560                        $result = imap_errors(); 
    15611561                } 
    15621562                if($mbox_stream) 
    15631563                        imap_close($mbox_stream); 
    15641564                return $result; 
    1565                  
    1566         } 
    1567          
     1565 
     1566        } 
     1567 
    15681568        function get_num_msgs($params) 
    15691569        { 
     
    15731573                        if(!$this->mbox || !is_resource($this->mbox)) 
    15741574                        return imap_last_error(); 
    1575                 }                
     1575                } 
    15761576                $num_msgs = imap_num_msg($this->mbox); 
    15771577                if($this->mbox && is_resource($this->mbox)) 
    15781578                        imap_close($this->mbox); 
    1579                  
     1579 
    15801580                return $num_msgs; 
    15811581        } 
    1582          
     1582 
    15831583        function send_mail($params) 
    15841584        { 
     
    16611661                $forwarding_attachments = $params['forwarding_attachments']; 
    16621662                $local_attachments = $params['local_attachments']; 
    1663                   
     1663 
    16641664                $folder =$params['folder']; 
    1665                 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1");                
    1666                 $folder_name = $params['folder_name'];           
     1665                $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 
     1666                $folder_name = $params['folder_name']; 
    16671667                // Fix problem with cyrus delimiter changes. 
    1668                 // Dots in names: enabled/disabled.                              
     1668                // Dots in names: enabled/disabled. 
    16691669                $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); 
    16701670                $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); 
    16711671                // End Fix. 
    1672                 if ($folder != 'null'){                  
     1672                if ($folder != 'null'){ 
    16731673                        $mail->SaveMessageInFolder = $folder; 
    16741674                } 
     
    16831683                else 
    16841684            $mail->IsSMTP(); 
    1685              
     1685 
    16861686                $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; 
    16871687                $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort']; 
     
    16941694                        $mail->From = $fromaddress[1]; 
    16951695                } 
    1696                                  
     1696 
    16971697                $this->add_recipients("to", $toaddress, &$mail); 
    16981698                $this->add_recipients("cc", $ccaddress, &$mail); 
     
    18061806                $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); 
    18071807                        } 
    1808                         $cid = $cid_array[$cid_imgs[4][$j].$val];  
     1808                        $cid = $cid_array[$cid_imgs[4][$j].$val]; 
    18091809                        $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 
    1810                          
     1810 
    18111811                                if ($msg_uid != $cid_imgs[4][$j]) // The image isn't in the same mail? 
    18121812                                { 
     
    18211821                                        $file_description = unserialize(rawurldecode($attach_img)); 
    18221822 
    1823                                         foreach($file_description as $i => $descriptor){                                 
     1823                                        foreach($file_description as $i => $descriptor){ 
    18241824                                                $file_description[$i]  = eregi_replace('\'*\'','',$descriptor); 
    18251825                                        } 
     
    18311831                                } 
    18321832                                $tempDir = ini_get("session.save_path"); 
    1833                                 $file = "cidimage_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].$cid_imgs[6][$j].".dat";        
     1833                                $file = "cidimage_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].$cid_imgs[6][$j].".dat"; 
    18341834                                $f = fopen($tempDir.'/'.$file,"w"); 
    18351835                                fputs($f,$fileContent); 
     
    18381838                                        $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); 
    18391839                                //else 
    1840                                 //      return "Error loading image attachment content";                                                 
     1840                                //      return "Error loading image attachment content"; 
    18411841 
    18421842                } 
     
    18531853                        } 
    18541854                        if( $total_uploaded_size > $upload_max_filesize) 
    1855                                 return $this->parse_error("message file too big");                       
     1855                                return $this->parse_error("message file too big"); 
    18561856                } 
    18571857                else if(($params['is_local_forward']=="1") && (count($local_attachments))) { //Caso seja forward de mensagens locais 
    18581858 
    18591859                        $total_uploaded_size = 0; 
    1860                         $upload_max_filesize = str_replace("M","",ini_get('upload_max_filesize')) * 1024 * 1024;                         
     1860                        $upload_max_filesize = str_replace("M","",ini_get('upload_max_filesize')) * 1024 * 1024; 
    18611861                        foreach($local_attachments as $local_attachment) { 
    18621862                                $file_description = unserialize(rawurldecode($local_attachment)); 
    18631863                                $tmp = array_values($file_description); 
    1864                                 foreach($file_description as $i => $descriptor){                                 
     1864                                foreach($file_description as $i => $descriptor){ 
    18651865                                        $tmp[$i]  = eregi_replace('\'*\'','',$descriptor); 
    18661866                                } 
     
    18791879                                $name_cid_files[count($name_cid_files)] = $name_cid_files[0]; 
    18801880                                $name_cid_files[0] = null; 
    1881                         }                        
    1882                          
     1881                        } 
     1882 
    18831883                        foreach($forwarding_attachments as $forwarding_attachment) 
    18841884                        { 
    18851885                                        $file_description = unserialize(rawurldecode($forwarding_attachment)); 
    18861886                                        $tmp = array_values($file_description); 
    1887                                         foreach($file_description as $i => $descriptor){                                 
     1887                                        foreach($file_description as $i => $descriptor){ 
    18881888                                                $tmp[$i]  = eregi_replace('\'*\'','',$descriptor); 
    18891889                                        } 
    1890                                         $file_description = $tmp;                                        
     1890                                        $file_description = $tmp; 
    18911891                                        $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 
    18921892                                        $fileName = $file_description[2]; 
     
    19091909 
    19101910                $sent = $mail->Send(); 
    1911                  
     1911 
    19121912                if(!$sent) 
    19131913                { 
     
    19201920                                return $sent; 
    19211921                        } 
    1922                         if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True")  
     1922                        if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True") 
    19231923                        { 
    19241924                                $userid = $_SESSION['phpgw_info']['expressomail']['user']['userid']; 
     
    19261926                                $now = date("d/m/y H:i:s"); 
    19271927                                $addrs = $toaddress.$ccaddress.$ccoaddress; 
    1928                                 $sent = trim($sent);                                                                                             
     1928                                $sent = trim($sent); 
    19291929                                error_log("$now - $userip - $sent [$subject] - $userid => $addrs\r\n", 3, "/home/expressolivre/mail_senders.log"); 
    19301930                        } 
    1931                         if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['number_of_contacts'] &&  
     1931                        if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['number_of_contacts'] && 
    19321932                           $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_dynamic_contacts']) { 
    19331933                                $contacts = new dynamic_contacts(); 
     
    19611961        function add_recipients($recipient_type, $full_address, $mail) 
    19621962        { 
    1963                 $parse_address = imap_rfc822_parse_adrlist($full_address, "");           
    1964                 foreach ($parse_address as $val)  
     1963                $parse_address = imap_rfc822_parse_adrlist($full_address, ""); 
     1964                foreach ($parse_address as $val) 
    19651965                { 
    19661966                        //echo "<script language=\"javascript\">javascript:alert('".$val->mailbox."@".$val->host."');</script>"; 
    19671967                        if ($val->mailbox == "INVALID_ADDRESS") 
    19681968                                continue; 
    1969                          
     1969 
    19701970                        if (empty($val->personal)) 
    19711971                        { 
     
    20012001                return true; 
    20022002        } 
    2003          
     2003 
    20042004        function get_forwarding_attachment($msg_folder, $msg_number, $msg_part, $encoding) 
    20052005        { 
    20062006                $mbox_stream = $this->open_mbox(utf8_decode(urldecode($msg_folder))); 
    2007                 $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID);             
     2007                $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID); 
    20082008                if($encoding == 'base64') 
    20092009                        # The function imap_base64 adds a new line 
     
    20142014                        $fileContent = base64_decode($fileContent); 
    20152015                else if($encoding == 'quoted-printable') 
    2016                         $fileContent = quoted_printable_decode($fileContent);                            
     2016                        $fileContent = quoted_printable_decode($fileContent); 
    20172017                return $fileContent; 
    20182018        } 
    2019          
     2019 
    20202020        function del_last_caracter($string) 
    20212021        { 
    20222022                $string = substr($string,0,(strlen($string) - 1)); 
    2023                 return $string;  
    2024         } 
    2025          
     2023                return $string; 
     2024        } 
     2025 
    20262026        function del_last_two_caracters($string) 
    20272027        { 
    20282028                $string = substr($string,0,(strlen($string) - 2)); 
    2029                 return $string;  
    2030         } 
    2031          
     2029                return $string; 
     2030        } 
     2031 
    20322032        function messages_sort($sort_box_type,$sort_box_reverse, $search_box_type,$offsetBegin,$offsetEnd) 
    20332033        { 
     
    21012101                if(!is_array($sort)) 
    21022102                        $sort = array(); 
    2103                          
     2103 
    21042104                if ($slice_array) 
    21052105                        $sort = array_slice($sort,$offsetBegin-1,$offsetEnd-($offsetBegin-1),true); 
    2106                          
     2106 
    21072107 
    21082108                return $sort; 
     
    21112111 
    21122112 
    2113         function move_search_messages($params){          
    2114                 $params['selected_messages'] = urldecode($params['selected_messages']);  
     2113        function move_search_messages($params){ 
     2114                $params['selected_messages'] = urldecode($params['selected_messages']); 
    21152115                $params['new_folder'] = urldecode($params['new_folder']); 
    21162116                $params['new_folder_name'] = urldecode($params['new_folder_name']); 
    21172117                $sel_msgs = explode(",", $params['selected_messages']); 
    2118                 @reset($sel_msgs);       
     2118                @reset($sel_msgs); 
    21192119                $sorted_msgs = array(); 
    21202120                foreach($sel_msgs as $idx => $sel_msg) { 
     
    21222122                         if(array_key_exists($sel_msg[0], $sorted_msgs)){ 
    21232123                                $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; 
    2124                          }       
     2124                         } 
    21252125                         else { 
    21262126                                $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; 
     
    21282128                } 
    21292129                @ksort($sorted_msgs); 
    2130                 $last_return = false;            
    2131                 foreach($sorted_msgs as $folder => $msgs_number) {                       
     2130                $last_return = false; 
     2131                foreach($sorted_msgs as $folder => $msgs_number) { 
    21322132                        $params['msgs_number'] = $msgs_number; 
    2133                         $params['folder'] = $folder;     
     2133                        $params['folder'] = $folder; 
    21342134                        if($params['new_folder'] && $folder != $params['new_folder']){ 
    2135                                 $last_return = $this -> move_messages($params);                          
     2135                                $last_return = $this -> move_messages($params); 
    21362136                        } 
    21372137                        elseif(!$params['new_folder'] || $params['delete'] ){ 
     
    21422142                return $last_return; 
    21432143        } 
    2144          
     2144 
    21452145        function move_messages($params) 
    21462146        { 
    2147                 $folder = $params['folder'];             
    2148                 $mbox_stream = $this->open_mbox($folder);                
     2147                $folder = $params['folder']; 
     2148                $mbox_stream = $this->open_mbox($folder); 
    21492149                $newmailbox = ($params['new_folder']); 
    21502150                $newmailbox = mb_convert_encoding($newmailbox, "UTF7-IMAP","ISO_8859-1"); 
     
    21562156                                                'border_ID' => $params['border_ID'], 
    21572157                                                'status' => true); //Status foi adicionado para validar as permissoes ACL 
    2158                  
     2158 
    21592159                //Este bloco tem a finalidade de averiguar as permissoes para pastas compartilhadas 
    21602160        if (substr($folder,0,4) == 'user'){ 
     
    21772177        } 
    21782178        //Este bloco tem a finalidade de transformar o CPF das pastas compartilhadas em common name 
    2179         if (substr($new_folder_name,0,4) == 'user'){             
     2179        if (substr($new_folder_name,0,4) == 'user'){ 
    21802180                $this->ldap = new ldap_functions(); 
    21812181                $tmp_folder_name = explode($this->imap_delimiter, $new_folder_name); 
     
    21852185                                        $return['new_folder_name'] = $cn; 
    21862186        } 
    2187                  
    2188                 // Caso estejamos no box principal, nao eh necessario pegar a informacao da mensagem anterior.           
     2187 
     2188                // Caso estejamos no box principal, nao eh necessario pegar a informacao da mensagem anterior. 
    21892189                if (($params['get_previous_msg']) && ($params['border_ID'] != 'null') && ($params['border_ID'] != '')) 
    21902190                { 
     
    21932193                        $return['previous_msg']['body'] = str_replace(array('{','}'), array('&#123;','&#125;'), $return['previous_msg']['body']); 
    21942194                } 
    2195                  
    2196                 $mbox_stream = $this->open_mbox($folder);        
     2195 
     2196                $mbox_stream = $this->open_mbox($folder); 
    21972197                if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { 
    21982198                        imap_expunge($mbox_stream); 
     
    22012201                        return $return; 
    22022202                }else { 
    2203                         if(strstr(imap_last_error(),'Over quota')) {                             
     2203                        if(strstr(imap_last_error(),'Over quota')) { 
    22042204                                $accountID      = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminUsername']; 
    2205                                 $pass           = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminPW'];                                                                        
    2206                                 $userID         = $_SESSION['phpgw_info']['expressomail']['user']['userid'];                                                             
     2205                                $pass           = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminPW']; 
     2206                                $userID         = $_SESSION['phpgw_info']['expressomail']['user']['userid']; 
    22072207                                $server         = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 
    22082208                                $mbox           = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}INBOX", $accountID, $pass) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error())))); 
    22092209                                if(!$mbox) 
    22102210                                        return imap_last_error(); 
    2211                                 $quota  = imap_get_quotaroot($mbox_stream, "INBOX");                             
     2211                                $quota  = imap_get_quotaroot($mbox_stream, "INBOX"); 
    22122212                                if(! imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, 2.1 * $quota['usage'])) { 
    22132213                                        if($mbox_stream) 
    22142214                                                imap_close($mbox_stream); 
    2215                                         if($mbox)                                                                        
     2215                                        if($mbox) 
    22162216                                                imap_close($mbox); 
    2217                                         return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n";                                                                
     2217                                        return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n"; 
    22182218                                } 
    22192219                                if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { 
     
    22252225                                                if($mbox) 
    22262226                                                        imap_close($mbox); 
    2227                                                 return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n";                                                          
     2227                                                return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; 
    22282228                                        } 
    2229                                         return $return;                                                                                                  
     2229                                        return $return; 
    22302230                                } 
    22312231                                else { 
     
    22352235                                                if($mbox) 
    22362236                                                        imap_close($mbox); 
    2237                                                 return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n";                                                          
     2237                                                return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; 
    22382238                                        } 
    2239                                         return imap_last_error();                                
    2240                                 } 
    2241                                  
     2239                                        return imap_last_error(); 
     2240                                } 
     2241 
    22422242                        } 
    22432243                        else { 
     
    22462246                                return "move_messages() line ".__LINE__.": ". imap_last_error()." folder:".$newmailbox; 
    22472247                        } 
    2248                 }                
    2249         } 
    2250          
     2248                } 
     2249        } 
     2250 
    22512251        function save_msg($params) 
    22522252        { 
    2253                  
     2253 
    22542254                include_once("class.phpmailer.php"); 
    22552255                $mail = new PHPMailer(); 
     
    22662266                $attachments = $params['FILES']; 
    22672267                $return_files = $params['FILES']; 
    2268                   
     2268 
    22692269                $folder = $params['folder']; 
    2270                 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1");                
     2270                $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 
    22712271                // Fix problem with cyrus delimiter changes. 
    2272                 // Dots in names: enabled/disabled.                              
     2272                // Dots in names: enabled/disabled. 
    22732273                $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); 
    22742274                $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); 
    22752275                // End Fix. 
    2276                                          
     2276 
    22772277                $mail->SaveMessageInFolder = $folder; 
    22782278                $mail->SMTPDebug = false; 
    2279                                                  
     2279 
    22802280                $mail->IsSMTP(); 
    22812281                $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; 
     
    22832283                $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; 
    22842284                $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 
    2285                  
     2285 
    22862286                $mail->Sender = $mail->From; 
    22872287                $mail->SenderName = $mail->FromName; 
    22882288                $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 
    22892289                $mail->From =  $_SESSION['phpgw_info']['expressomail']['user']['email']; 
    2290                                  
     2290 
    22912291                $this->add_recipients("to", $toaddress, &$mail); 
    22922292                $this->add_recipients("cc", $ccaddress, &$mail); 
     
    22942294                $mail->IsHTML(true); 
    22952295                $mail->Body = $body; 
    2296                  
     2296 
    22972297                //      Build CID for embedded Images!!! 
    22982298                $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU'; 
     
    23062306                $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); 
    23072307                        } 
    2308                         $cid = $cid_array[$cid_imgs[4][$j].$val];  
     2308                        $cid = $cid_array[$cid_imgs[4][$j].$val]; 
    23092309                        $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 
    2310                          
     2310 
    23112311                                if ($msg_uid != $cid_imgs[4][$j]) // The image isn't in the same mail? 
    23122312                                { 
     
    23282328                                        $attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2]; 
    23292329                                        $file_description = unserialize(rawurldecode($attach_img)); 
    2330                                         foreach($file_description as $i => $descriptor){                                 
     2330                                        foreach($file_description as $i => $descriptor){ 
    23312331                                                $file_description[$i]  = eregi_replace('\'*\'','',$descriptor); 
    23322332                                        } 
     
    23432343                                } 
    23442344                                $tempDir = ini_get("session.save_path"); 
    2345                                 $file = "cidimage_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].$cid_imgs[6][$j].".dat";                                        
     2345                                $file = "cidimage_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].$cid_imgs[6][$j].".dat"; 
    23462346                                $f = fopen($tempDir.'/'.$file,"w"); 
    23472347                                fputs($f,$fileContent); 
     
    23502350                                        $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); 
    23512351                                //else 
    2352                                 //      return "Error loading image attachment content";                                                 
    2353  
    2354                 } 
    2355          
    2356         //      Build Forwarding Attachments!!!          
     2352                                //      return "Error loading image attachment content"; 
     2353 
     2354                } 
     2355 
     2356        //      Build Forwarding Attachments!!! 
    23572357                if (count($forwarding_attachments) > 0) 
    23582358                { 
     
    23612361                                $file_description = unserialize(rawurldecode($forwarding_attachment)); 
    23622362                                $tmp = array_values($file_description); 
    2363                                 foreach($file_description as $i => $descriptor){                                 
     2363                                foreach($file_description as $i => $descriptor){ 
    23642364                                        $tmp[$i]  = eregi_replace('\'*\'','',$descriptor); 
    23652365                                } 
    23662366                                $file_description = $tmp; 
    2367                                  
     2367 
    23682368                                $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 
    23692369                                $fileName = $file_description[2]; 
    2370                                  
     2370 
    23712371                                $file_description[5] = strlen($fileContent); //Size of file 
    23722372                                $return_forward[] = $file_description; 
    2373                          
     2373 
    23742374                                        $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); 
    23752375                        } 
    23762376                } 
    2377                  
     2377 
    23782378                if ((count($return_forward) > 0) && (count($return_files) > 0)) 
    23792379                        $return_files = array_merge_recursive($return_forward,$return_files); 
     
    23812381                        if (count($return_files) < 1) 
    23822382                                $return_files = $return_forward; 
    2383          
     2383 
    23842384                //      Build Uploading Attachments!!! 
    23852385                $sizeof_attachments = count($attachments); 
     
    24192419                                        imagecopyresampled($image_new, $image_big, 0, 0, 0, 0, $new_width, $new_height, $width, $height); 
    24202420                                        $tmpDir = ini_get("session.save_path"); 
    2421                                         $_file = "/cidimage_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".dat";  
     2421                                        $_file = "/cidimage_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".dat"; 
    24222422                                        imagejpeg($image_new,$tmpDir.$_file, 85); 
    24232423                                        $mail->AddAttachment($tmpDir.$_file, $attach['name'], "base64", $this->get_file_type($tmpDir.$_file)); 
     
    24272427                                // optional name 
    24282428                                } 
    2429          
    2430          
    2431          
    2432                  
     2429 
     2430 
     2431 
     2432 
    24332433                if(!empty($mail->AltBody)) 
    24342434            $mail->ContentType = "multipart/alternative"; 
     
    24372437                $mail->SetMessageType(); 
    24382438                $header = $mail->CreateHeader(); 
    2439                 $body = $mail->CreateBody();  
    2440  
    2441                 $mbox_stream = $this->open_mbox($folder);        
     2439                $body = $mail->CreateBody(); 
     2440 
     2441                $mbox_stream = $this->open_mbox($folder); 
    24422442                $new_header = str_replace("\n", "\r\n", $header); 
    24432443                $new_body = str_replace("\n", "\r\n", $body); 
     
    24492449                if($mbox_stream) 
    24502450                        imap_close($mbox_stream); 
    2451                 if (is_array($return_files))               
     2451                if (is_array($return_files)) 
    24522452                        foreach ($return_files as $index => $_attachment) { 
    24532453                                if (array_key_exists("name",$_attachment)){ 
     
    24612461                        } 
    24622462                } 
    2463                  
     2463 
    24642464                $return['files'] = serialize($return_files); 
    24652465                $return["subject"] = $subject; 
    2466                                  
     2466 
    24672467                if (!$return['append']) 
    24682468                        $return['append'] = imap_last_error(); 
    2469                  
     2469 
    24702470                return $return; 
    24712471        } 
    2472          
     2472 
    24732473        function set_messages_flag($params) 
    24742474        { 
     
    24792479                $return["msgs_to_set"] = $msgs_to_set; 
    24802480                $return["flag"] = $flag; 
    2481                  
     2481 
    24822482                if(!$this->mbox && !is_resource($this->mbox)) 
    24832483                        $this->mbox = $this->open_mbox($folder); 
    2484                  
     2484 
    24852485                if ($flag == "unseen") 
    24862486                        $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Seen", ST_UID); 
     
    25022502                                preg_match('/importance *: *(.*)\r/i', 
    25032503                                        imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) 
    2504                                         ,$importance);           
     2504                                        ,$importance); 
    25052505                                if(strtolower($importance[1])=="high" && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) { 
    25062506                                        $flag_importance=true; 
     
    25082508                                else { 
    25092509                                        $unflagged_msgs.=$msg_number.","; 
    2510                                 }                                
     2510                                } 
    25112511                        } 
    25122512 
     
    25272527                        } 
    25282528                } 
    2529                  
     2529 
    25302530                if($this->mbox && is_resource($this->mbox)) 
    25312531                        imap_close($this->mbox); 
    25322532                return $return; 
    25332533        } 
    2534          
     2534 
    25352535        function get_file_type($file_name) 
    25362536        { 
    25372537                $file_name = strtolower($file_name); 
    25382538                $strFileType = strrev(substr(strrev($file_name),0,4)); 
    2539                 if ($strFileType == ".asf")  
     2539                if ($strFileType == ".asf") 
    25402540                        return "video/x-ms-asf"; 
    25412541                if ($strFileType == ".avi") 
     
    25632563                if ($strFileType == ".htm" || $strFileType == "html") 
    25642564                        return "text/html"; 
    2565                 if ($strFileType == ".xml")  
     2565                if ($strFileType == ".xml") 
    25662566                        return "text/xml"; 
    2567                 if ($strFileType == ".xsl")  
     2567                if ($strFileType == ".xsl") 
    25682568                        return "text/xsl"; 
    2569                 if ($strFileType == ".css")  
     2569                if ($strFileType == ".css") 
    25702570                        return "text/css"; 
    2571                 if ($strFileType == ".php")  
     2571                if ($strFileType == ".php") 
    25722572                        return "text/php"; 
    2573                 if ($strFileType == ".asp")  
     2573                if ($strFileType == ".asp") 
    25742574                        return "text/asp"; 
    25752575                if ($strFileType == ".pdf") 
     
    25992599                if ($strFileType == ".stw") 
    26002600                        return "application/vnd.sun.xml.writer.template"; 
    2601                  
    2602                  
    2603                 return "application/octet-stream";               
    2604         } 
    2605          
     2601 
     2602 
     2603                return "application/octet-stream"; 
     2604        } 
     2605 
    26062606        function htmlspecialchars_encode($str) 
    26072607        { 
     
    26122612                return  str_replace( array('&amp;','&quot;','&#039;','&lt;','&gt;','&#123;','&#125;'), array('&', '"','\'','<','>','{','}'), $str); 
    26132613        } 
    2614          
     2614 
    26152615        function get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$offsetBegin = 0,$offsetEnd = 0) 
    26162616        { 
     
    26202620                return $this->messages_sort($sort_box_type,$sort_box_reverse, $search_box_type,$offsetBegin,$offsetEnd); 
    26212621        } 
    2622          
     2622 
    26232623        function get_info_next_msg($params) 
    26242624        { 
     
    26292629                $reuse_border = $params['reuse_border']; 
    26302630                $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 
    2631                 $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse);                               
    2632                  
     2631                $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); 
     2632 
    26332633                $success = false; 
    26342634                if (is_array($sort_array_msg)) 
     
    26492649                        return $params; 
    26502650                } 
    2651                  
     2651 
    26522652                $params = array(); 
    26532653                $params['msg_number'] = $sort_array_msg[($i+1)]; 
    26542654                $params['msg_folder'] = $folder; 
    2655                  
    2656                 $return = $this->get_info_msg($params);          
     2655 
     2656                $return = $this->get_info_msg($params); 
    26572657                $return["reuse_border"] = $reuse_border; 
    26582658                return $return; 
     
    26682668                $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 
    26692669                $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); 
    2670                  
     2670 
    26712671                $success = false; 
    26722672                if (is_array($sort_array_msg)) 
     
    26862686                        return $params; 
    26872687                } 
    2688                  
     2688 
    26892689                $params = array(); 
    26902690                $params['msg_number'] = $sort_array_msg[($i-1)]; 
    26912691                $params['msg_folder'] = $folder; 
    2692                  
     2692 
    26932693                $return = $this->get_info_msg($params); 
    26942694                $return["reuse_border"] = $reuse_border; 
    26952695                return $return; 
    26962696        } 
    2697          
     2697 
    26982698        // This function updates the values: quota, paging and new messages menu. 
    26992699        function get_menu_values($params){ 
    27002700                $return_array = array(); 
    27012701                $return_array = $this->get_quota($params); 
    2702                  
     2702 
    27032703                $mbox_stream = $this->open_mbox($params['folder']); 
    2704                 $return_array['num_msgs'] = imap_num_msg($mbox_stream);          
     2704                $return_array['num_msgs'] = imap_num_msg($mbox_stream); 
    27052705                if($mbox_stream) 
    27062706                        imap_close($mbox_stream); 
    2707                                  
    2708                 return $return_array;  
    2709         } 
    2710          
     2707 
     2708                return $return_array; 
     2709        } 
     2710 
    27112711        function get_quota($params){ 
    27122712                // folder_id = user/{uid} for shared folders 
    27132713                if(substr($params['folder_id'],0,5) != 'INBOX' && preg_match('/user\\'.$this->imap_delimiter.'/i', $params['folder_id'])){ 
    27142714                        $array_folder =  explode($this->imap_delimiter,$params['folder_id']); 
    2715                         $folder_id = "user".$this->imap_delimiter.$array_folder[1];              
     2715                        $folder_id = "user".$this->imap_delimiter.$array_folder[1]; 
    27162716                } 
    27172717                // folder_id = INBOX for inbox folders 
    27182718                else 
    27192719                        $folder_id = "INBOX"; 
    2720                  
     2720 
    27212721                if(!$this->mbox || !is_resource($this->mbox)) 
    27222722                        $this->mbox = $this->open_mbox(); 
     
    27252725                if($this->mbox && is_resource($this->mbox)) 
    27262726                        imap_close($this->mbox); 
    2727                          
     2727 
    27282728                if (!$quota){ 
    27292729                        return array( 
     
    27332733                        ); 
    27342734                } 
    2735                  
     2735 
    27362736                if(count($quota) && $quota['limit']) { 
    27372737                        $quota_limit = (($quota['limit']/1024)* 100 + .5 )* .01; 
     
    27522752                        ); 
    27532753                } 
    2754                 else  
     2754                else 
    27552755                        return array(); 
    27562756        } 
    2757          
     2757 
    27582758        function send_notification($params){ 
    27592759                require_once("class.phpmailer.php"); 
    27602760                $mail = new PHPMailer(); 
    2761                   
     2761 
    27622762                $toaddress = $params['notificationto']; 
    2763                  
     2763 
    27642764                $subject = 'Confirmação de leitura: ' . $params['subject']; 
    27652765                $body = 'Sua mensagem: ' . $params['subject'] . '<br>'; 
     
    27762776                $mail->IsHTML(true); 
    27772777                $mail->Body = $body; 
    2778                  
     2778 
    27792779                if(!$mail->Send()){ 
    27802780                        return $mail->ErrorInfo; 
     
    27832783                        return true; 
    27842784        } 
    2785          
     2785 
    27862786        function empty_trash() 
    27872787        { 
    2788                 $folder = 'INBOX' . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'];  
     2788                $folder = 'INBOX' . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']; 
    27892789                $mbox_stream = $this->open_mbox($folder); 
    27902790                $return = imap_delete($mbox_stream,'1:*'); 
     
    27932793                return $return; 
    27942794        } 
    2795          
     2795 
    27962796        function search($params) 
    27972797        { 
    27982798                include("class.imap_attachment.inc.php"); 
    2799                 $imap_attachment = new imap_attachment();                                
     2799                $imap_attachment = new imap_attachment(); 
    28002800                $criteria = $params['criteria']; 
    28012801                $return = array(); 
    28022802                $folders = $this->get_folders_list(); 
    2803                  
     2803 
    28042804                $j = 0; 
    28052805                foreach($folders as $folder) 
     
    28072807                        $mbox_stream = $this->open_mbox($folder); 
    28082808                        $messages = imap_search($mbox_stream, $criteria, SE_UID); 
    2809                          
     2809 
    28102810                        if ($messages == '') 
    28112811                                continue; 
    2812                  
     2812 
    28132813                        $i = 0; 
    28142814                        $return[$j] = array(); 
    28152815                        $return[$j]['folder_name'] = $folder['name']; 
    2816                          
     2816 
    28172817                        foreach($messages as $msg_number) 
    28182818                        { 
     
    28202820                                if (!is_object($header)) 
    28212821                                        return false; 
    2822                                  
     2822 
    28232823                                $return[$j][$i]['msg_folder']   = $folder['name']; 
    28242824                                $return[$j][$i]['msg_number']   = $msg_number; 
     
    28292829                                $return[$j][$i]['Draft']                = $header->Draft; 
    28302830                                $return[$j][$i]['Flagged']              = $header->Flagged; 
    2831          
     2831 
    28322832                                $date_msg = gmdate("d/m/Y",$header->udate); 
    28332833                                if (gmdate("d/m/Y") == $date_msg) 
     
    28352835                                else 
    28362836                                        $return[$j][$i]['udate'] = $date_msg; 
    2837                          
     2837 
    28382838                                $fromaddress = imap_mime_header_decode($header->fromaddress); 
    28392839                                $return[$j][$i]['fromaddress'] = ''; 
    28402840                                foreach ($fromaddress as $tmp) 
    28412841                                        $return[$j][$i]['fromaddress'] .= $this->replace_maior_menor($tmp->text); 
    2842                          
     2842 
    28432843                                $from = $header->from; 
    28442844                                $return[$j][$i]['from'] = array(); 
     
    28462846                                $return[$j][$i]['from']['name'] = $tmp[0]->text; 
    28472847                                $return[$j][$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; 
    2848                                 $return[$j][$i]['from']['full'] ='"' . $return[$j][$i]['from']['name'] . '" ' . '<' . $return[$j][$i]['from']['email'] . '>';  
     2848                                $return[$j][$i]['from']['full'] ='"' . $return[$j][$i]['from']['name'] . '" ' . '<' . $return[$j][$i]['from']['email'] . '>'; 
    28492849 
    28502850                                $to = $header->to; 
     
    28532853                                $return[$j][$i]['to']['name'] = $tmp[0]->text; 
    28542854                                $return[$j][$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; 
    2855                                 $return[$j][$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>';  
     2855                                $return[$j][$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; 
    28562856 
    28572857                                $subject = imap_mime_header_decode($header->fetchsubject); 
     
    28622862                                $return[$j][$i]['Size'] = $header->Size; 
    28632863                                $return[$j][$i]['reply_toaddress'] = $header->reply_toaddress; 
    2864                          
     2864 
    28652865                                $return[$j][$i]['attachment'] = array(); 
    28662866                                $return[$j][$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($mbox_stream, $msg_number); 
    2867                                                  
     2867 
    28682868                                $i++; 
    28692869                        } 
     
    28722872                                imap_close($mbox_stream); 
    28732873                } 
    2874          
     2874 
    28752875                return $return; 
    28762876        } 
    2877          
     2877 
    28782878        function delete_and_show_previous_message($params) 
    28792879        { 
    28802880                $return = $this->get_info_previous_msg($params); 
    2881                  
     2881 
    28822882                $params_tmp1 = array(); 
    28832883                $params_tmp1['msgs_to_delete'] = $params['msg_number']; 
    28842884                $params_tmp1['folder'] = $params['msg_folder']; 
    28852885                $return_tmp1 = $this->delete_msg($params_tmp1); 
    2886                  
     2886 
    28872887                $return['msg_number_deleted'] = $return_tmp1; 
    2888                  
     2888 
    28892889                return $return; 
    28902890        } 
    2891                  
    2892          
     2891 
     2892 
    28932893        function automatic_trash_cleanness($params) 
    28942894        { 
     
    29082908//      Fix the search problem with special characters!!!! 
    29092909        function remove_accents($string) { 
    2910                 return strtr($string,  
    2911                 "?Ó??ó?Ý?úÁÀÃÂÄÇÉÈÊËÍÌ?ÎÏÑÕÔÓÒÖÚÙ?ÛÜ?áàãâäçéèêëíì?îïñóòõôöúù?ûüýÿ",  
     2910                return strtr($string, 
     2911                "?Ó??ó?Ý?úÁÀÃÂÄÇÉÈÊËÍÌ?ÎÏÑÕÔÓÒÖÚÙ?ÛÜ?áàãâäçéèêëíì?îïñóòõôöúù?ûüýÿ", 
    29122912                "SOZsozYYuAAAAACEEEEIIIIINOOOOOUUUUUsaaaaaceeeeiiiiinooooouuuuuyy"); 
    29132913        } 
    29142914 
    2915         function search_msg($params = ''){               
     2915        function search_msg($params = ''){ 
    29162916                $retorno = ""; 
    29172917                $mbox_stream = ""; 
     
    29202920                } 
    29212921                else { 
    2922                         $search = explode(",",$params['condition']);                     
     2922                        $search = explode(",",$params['condition']); 
    29232923                } 
    29242924 
     
    29382938                                                $filter .= '"'.$filter_array[1].'"'; 
    29392939                                        } 
    2940                                 }                
    2941                                 $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" );  
     2940                                } 
     2941                                $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 
    29422942                                $filter = $this->remove_accents($filter); 
    29432943                                //Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name 
     
    29502950                                } 
    29512951                                $folder_name = implode($this->imap_delimiter,$folder_name); 
    2952                                  
     2952 
    29532953                                if(!is_resource($mbox_stream)) 
    29542954                                        $mbox_stream = $this->open_mbox($name_box); 
    29552955                                else 
    29562956                                        imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); 
    2957                          
    2958                                 if (preg_match("/^.?\bALL\b/", $filter)){ // Quick Search, note: this ALL isn't the same ALL from imap_search    
    2959                                  
     2957 
     2958                                if (preg_match("/^.?\bALL\b/", $filter)){ // Quick Search, note: this ALL isn't the same ALL from imap_search 
     2959 
    29602960                                        $all_criterias = array ("TO","SUBJECT","FROM","CC"); 
    29612961                                        foreach($all_criterias as $criteria_fixed) 
    29622962                                        { 
    29632963                                                $_filter = $criteria_fixed . substr($filter,4); 
    2964                                          
     2964 
    29652965                                                $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); 
    2966                                                  
     2966 
    29672967                                                if($search_criteria && count($search_criteria) < 50) 
    29682968                                                { 
     
    29722972                                                                        $retorno .= $m_token; 
    29732973                                                        } 
    2974                                                 }                                                
    2975                                                 else if(count($search_criteria) >= 50)                                                   
    2976                                                         return "many results";                                           
     2974                                                } 
     2975                                                else if(count($search_criteria) >= 50) 
     2976                                                        return "many results"; 
    29772977                                        } 
    29782978                                } 
     
    29882988                } 
    29892989                if($mbox_stream) 
    2990                         imap_close($mbox_stream);                
    2991                                                  
     2990                        imap_close($mbox_stream); 
     2991 
    29922992                return $retorno ? $retorno : "none"; 
    29932993        } 
    2994          
     2994 
    29952995        function get_msg($uid_msg,$name_box, $mbox_stream ) 
    29962996        { 
     
    30143014                        $from = $header->from[0]->personal; 
    30153015                $ret_msg = $this->decode_string($from) . "--" . $subject . "--". gmdate("d/m/Y",$header ->udate)."--". $this->size_msg($header->Size) ."--". $flag; 
    3016                 return $ret_msg;                     
    3017         }        
     3016                return $ret_msg; 
     3017        } 
    30183018 
    30193019        function size_msg($size){ 
    30203020                $var = floor($size/1024); 
    30213021                if($var >= 1){ 
    3022                         return $var." kb";       
     3022                        return $var." kb"; 
    30233023                }else{ 
    3024                         return $size ." b";      
     3024                        return $size ." b"; 
    30253025                } 
    30263026        } 
     
    30493049           } 
    30503050        } 
    3051          
     3051 
    30523052        function getacl() 
    30533053        { 
    30543054                $this->ldap = new ldap_functions(); 
    3055                  
     3055 
    30563056                $return = array(); 
    3057                 $mbox_stream = $this->open_mbox();       
     3057                $mbox_stream = $this->open_mbox(); 
    30583058                $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); 
    3059                  
     3059 
    30603060                $i = 0; 
    30613061                foreach ($mbox_acl as $user => $acl) 
     
    30703070                return $return; 
    30713071        } 
    3072          
     3072 
    30733073        function setacl($params) 
    30743074        { 
     
    30763076                if (!count($old_users)) 
    30773077                        $old_users = array(); 
    3078                  
     3078 
    30793079                $tmp_array = array(); 
    30803080                foreach ($old_users as $index => $user_info) 
     
    30833083                } 
    30843084                $old_users = $tmp_array; 
    3085                  
     3085 
    30863086                $users = unserialize($params['users']); 
    30873087                if (!count($users)) 
    30883088                        $users = array(); 
    3089                  
     3089 
    30903090                //$add_share = array_diff($users, $old_users); 
    30913091                $remove_share = array_diff($old_users, $users); 
     
    31103110                        } 
    31113111                }*/ 
    3112                  
     3112 
    31133113                if (count($remove_share)) 
    31143114                { 
     
    31233123                        } 
    31243124                        } 
    3125                         }        
    3126                 } 
    3127                  
     3125                        } 
     3126                } 
     3127 
    31283128                return true; 
    31293129        } 
    3130          
     3130 
    31313131        function getaclfromuser($params) 
    31323132        { 
    31333133                $useracl = $params['user']; 
    3134                  
     3134 
    31353135                $return = array(); 
    31363136                $return[$useracl] = 'false'; 
    3137                 $mbox_stream = $this->open_mbox();       
     3137                $mbox_stream = $this->open_mbox(); 
    31383138                $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); 
    3139                  
     3139 
    31403140                foreach ($mbox_acl as $user => $acl) 
    31413141                { 
     
    31613161                return $mbox_acl[$this->username]; 
    31623162        } 
    3163          
     3163 
    31643164 
    31653165        function setaclfromuser($params) 
     
    31673167                $user = $params['user']; 
    31683168                $acl = $params['acl']; 
    3169                  
     3169 
    31703170                $mbox_stream = $this->open_mbox(); 
    31713171 
     
    31903190                        return true; 
    31913191        } 
    3192          
     3192 
    31933193        function download_attachment($msg,$msgno) 
    31943194        { 
    3195                 $array_parts_attachments = array();              
     3195                $array_parts_attachments = array(); 
    31963196                $array_parts_attachments['names'] = ''; 
    31973197                include_once("class.imap_attachment.inc.php"); 
    3198                 $imap_attachment = new imap_attachment();                
    3199                  
     3198                $imap_attachment = new imap_attachment(); 
     3199 
    32003200                if (count($msg->fname[$msgno]) > 0) 
    32013201                { 
     
    32143214                $array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2)); 
    32153215                return $array_parts_attachments; 
    3216         }        
     3216        } 
    32173217 
    32183218        function spam($params) 
     
    32653265                $pdate = date_parse($header->MailDate); 
    32663266                $header->udate +=  $pdate['zone']*(-60); 
    3267                  
     3267 
    32683268                if($header->Flagged != "F" && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) { 
    32693269                        $flag = preg_match('/importance *: *(.*)\r/i', 
    32703270                                                imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) 
    3271                                                 ,$importance);           
     3271                                                ,$importance); 
    32723272                        $header->Flagged = $flag==0?false:strtolower($importance[1])=="high"?"F":false; 
    32733273                } 
    3274                  
     3274 
    32753275                return $header; 
    32763276        } 
     
    33143314        //error_log("source: $source\nversao: " . PHP_VERSION, 3, '/tmp/teste.log'); 
    33153315        $source = str_replace(" ", "+", $source,$i); 
    3316          
     3316 
    33173317        if (version_compare(PHP_VERSION, '5.2.0', '>=')){ 
    33183318            if(!$source = base64_decode($source,true)) 
     
    33563356 
    33573357    } 
    3358      
     3358 
    33593359//Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Trata fontes de emails enviados via POST para o servidor por um xmlhttprequest, as partes codificados com 
    33603360//Base64 os "+" são substituidos por " " no envio e essa função arruma esse efeito. 
Note: See TracChangeset for help on using the changeset viewer.