Changeset 432


Ignore:
Timestamp:
09/16/08 15:21:54 (16 years ago)
Author:
rafaelraymundo
Message:

Referencias ao Mobile adicionadas em ambos os arquivos

Location:
trunk
Files:
2 edited

Legend:

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

    r426 r432  
    77{ 
    88        var $public_functions = array 
    9         (        
     9        ( 
    1010                'get_range_msgs'                                => True, 
    1111                'get_info_msg'                                  => True, 
     
    2626                $this->imap_port          = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; 
    2727                $this->imap_delimiter = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter']; 
    28                 $this->functions          = new functions();             
     28                $this->functions          = new functions(); 
    2929                $this->has_cid = false; 
    30                  
     30 
    3131                if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') 
    3232                { 
     
    5353                $msg_range_begin = $params['msg_range_begin']; 
    5454                $msg_range_end = $params['msg_range_end']; 
    55                 $sort_box_type = $params['sort_box_type'];               
     55                $sort_box_type = $params['sort_box_type']; 
    5656                $sort_box_reverse = $params['sort_box_reverse']; 
    5757                $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 
    58                 $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse);                                
    59                  
     58                $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); 
     59 
    6060                $return = array(); 
    6161                $i = 0; 
    6262                $num_msgs = (is_array($sort_array_msg) ? count($sort_array_msg) : 0); 
    63                 if($num_msgs) {  
     63                if($num_msgs) { 
    6464                        for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= $num_msgs)); $msg_range_begin++) 
    6565                { 
     
    6868                        $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); 
    6969                        if (!is_object($header)) 
    70                                 return false;                    
    71                          
     70                                return false; 
     71 
    7272                        $return[$i]['Recent'] = $header->Recent; 
    7373                        $return[$i]['Unseen'] = $header->Unseen; 
     
    7777                        else { 
    7878                                $return[$i]['Answered'] = $header->Answered; 
    79                                 $return[$i]['Draft']    = $header->Draft;        
     79                                $return[$i]['Draft']    = $header->Draft; 
    8080                        } 
    8181                        $return[$i]['Deleted'] = $header->Deleted; 
    8282                        $return[$i]['Flagged'] = $header->Flagged; 
    83                          
     83 
    8484                        $return[$i]['msg_number'] = $msg_number; 
    8585                        //$return[$i]['msg_folder'] = $folder; 
    86                          
     86 
    8787                        $date_msg = date("d/m/Y",$header->udate); 
    8888                        if (date("d/m/Y") == $date_msg) 
     
    9090                        else 
    9191                                $return[$i]['udate'] = $date_msg; 
    92                          
     92 
    9393                        $from = $header->from; 
    9494                        $return[$i]['from'] = array(); 
     
    108108 
    109109                        $return[$i]['Size'] = $header->Size; 
    110                          
     110 
    111111                        $return[$i]['attachment'] = array(); 
    112                         $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number);                       
     112                        $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); 
    113113                        $i++; 
    114114                } 
    115115                } 
    116                 $return['num_msgs'] = $num_msgs;                 
    117                  
     116                $return['num_msgs'] = $num_msgs; 
     117 
    118118                return $return; 
    119119        } 
    120          
     120 
    121121        function decode_string($string) 
    122         {        
     122        { 
    123123                if ((strpos(strtolower($string), '=?iso-8859-1') !== false) || (strpos(strtolower($string), '=?windows-1252') !== false)) 
    124124                { 
     
    145145                        return $this->htmlspecialchars_encode($string); 
    146146        } 
    147          
     147 
    148148        function get_info_msg($params) 
    149149        { 
     
    151151                $msg_number = $params['msg_number']; 
    152152                $msg_folder = $params['msg_folder']; 
    153                  
     153 
    154154                if(!$this->mbox || !is_resource($this->mbox)) 
    155                         $this->mbox = $this->open_mbox($msg_folder);             
    156                  
     155                        $this->mbox = $this->open_mbox($msg_folder); 
     156 
     157 
     158                //if(!$this->mbox) 
     159                //      $this->mbox = $this->open_mbox($msg_folder); 
     160 
    157161                $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); 
    158162                if (!$header) { 
     
    162166                $all_header = explode("\n", imap_fetchheader($this->mbox, $msg_number, FT_UID)); 
    163167                $return_get_body = $this->get_body_msg($msg_number, $msg_folder); 
    164                  
     168 
    165169                $return['body']                 = $return_get_body['body']; 
    166170                $return['attachments']  = $return_get_body['attachments']; 
    167171                $return['thumbs']               = $return_get_body['thumbs']; 
    168172                $return['signature']    = $return_get_body['signature']; 
    169                  
     173 
    170174                foreach($all_header as $line) { 
    171175                        if (eregi("^Disposition-Notification-To", $line)) { 
     
    176180                $return['Recent']       = $header->Recent; 
    177181                $return['Unseen']       = $header->Unseen; 
    178                 $return['Deleted']      = $header->Deleted;              
     182                $return['Deleted']      = $header->Deleted; 
    179183                $return['Flagged']      = $header->Flagged; 
    180184 
     
    184188                else { 
    185189                        $return['Answered']     = $header->Answered; 
    186                         $return['Draft']        = $header->Draft;        
     190                        $return['Draft']        = $header->Draft; 
    187191                } 
    188192 
    189193                $return['msg_number'] = $msg_number; 
    190194                $return['msg_folder'] = $msg_folder; 
    191          
     195 
    192196                $date_msg = date("d/m/Y",$header->udate); 
    193197                if (date("d/m/Y") == $date_msg) 
     
    195199                else 
    196200                        $return['udate'] = $date_msg; 
    197                  
    198                 $return['msg_day'] = $date_msg;  
     201 
     202                $return['msg_day'] = $date_msg; 
    199203                $return['msg_hour'] = date("H:i",$header->udate); 
    200                  
     204 
    201205                if (date("d/m/Y") == $date_msg) //no dia 
    202206                { 
    203207                        $return['fulldate'] = date("d/m/Y H:i",$header->udate); 
    204208                        $return['smalldate'] = date("H:i",$header->udate); 
    205                          
     209 
    206210                        $timestamp_now = strtotime("now"); 
    207211                        $timestamp_msg_time = $header->udate; 
    208212                        $timestamp_diff = $timestamp_now - $timestamp_msg_time; 
    209                          
     213 
    210214                        if (gmdate("H",$timestamp_diff) > 0) 
    211215                        { 
     
    229233                        $return['smalldate'] = date("d/m/Y",$header->udate); 
    230234                } 
    231                  
     235 
    232236                $from = $header->from; 
    233237                $return['from'] = array(); 
     
    244248                else 
    245249                        $return['from']['full'] = $return['from']['email']; 
    246                  
     250 
    247251                // Sender attribute 
    248252                $sender = $header->sender; 
     
    296300                { 
    297301                        $return['toaddress2'] = "&lt;Empty&gt;"; 
    298                 }        
    299                  
     302                } 
     303 
    300304                $cc = $header->cc; 
    301305                $return['cc'] = ""; 
     
    325329                { 
    326330                        $return['cc'] = ""; 
    327                 }        
    328  
    329                 ## 
    330                 # @AUTHOR Rodrigo Souza dos Santos 
    331                 # @DATE 2008/09/12 
    332                 # @BRIEF Adding the BCC field. 
    333                 ## 
    334                 $bcc = $header->bcc; 
    335                 $return['bcc'] = ""; 
    336                 if (!empty($bcc)) 
    337                 { 
    338                         foreach ($bcc as $tmp_bcc) 
    339                         { 
    340                                 if (!empty($tmp_bcc->personal)) 
    341                                 { 
    342                                         $personal_tmp_bcc = imap_mime_header_decode($tmp_bcc->personal); 
    343                                         $return['bcc'] .= '"' . $personal_tmp_bcc[0]->text . '"'; 
    344                                         $return['bcc'] .= " "; 
    345                                         $return['bcc'] .= "&lt;"; 
    346                                         $return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; 
    347                                         $return['bcc'] .= "&gt;"; 
    348                                         $return['bcc'] .= ", "; 
    349                                 } 
    350                                 else 
    351                                 { 
    352                                         $return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; 
    353                                         $return['bcc'] .= ", "; 
    354                                 } 
    355                         } 
    356                         $return['bcc'] = $this->del_last_two_caracters($return['bcc']); 
    357                 } 
    358                 else 
    359                 { 
    360                         $return['bcc'] = ""; 
    361                 }        
     331                } 
    362332 
    363333                $reply_to = $header->reply_to; 
     
    391361                $return['Size'] = $header->Size; 
    392362                $return['reply_toaddress'] = $header->reply_toaddress; 
    393                  
     363 
    394364                return $return; 
    395365        } 
    396          
     366 
    397367        function get_body_msg($msg_number, $msg_folder) 
    398368        { 
     
    401371                $msg->fetch_structure($msg_number); 
    402372                $return = array(); 
    403                 $return['attachments'] = $this-> download_attachment($msg,$msg_number);          
     373                $return['attachments'] = $this-> download_attachment($msg,$msg_number); 
    404374                if(!$this->has_cid) 
    405375                { 
    406376                        $return['thumbs']  = $this->get_thumbs($msg,$msg_number,urlencode($msg_folder)); 
    407377                        $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); 
    408                 }                        
    409                  
     378                } 
     379 
    410380                if(!$msg->structure[$msg_number]->parts) //Simple message, only 1 piece 
    411381                { 
    412382                        $attachment = array(); //No attachments 
    413                          
     383 
    414384                        $content = ''; 
    415385                        if (strtolower($msg->structure[$msg_number]->subtype) == "plain") 
     
    422392                        } 
    423393                } 
    424                 else  
     394                else 
    425395                { //Complicated message, multiple parts 
    426396                        $html_body = ''; 
     
    428398                        $has_multipart = true; 
    429399                        $this->has_cid = false; 
    430                          
     400 
    431401                        if (strtolower($msg->structure[$msg_number]->subtype) == "related") 
    432402                                $this->has_cid = true; 
    433                          
     403 
    434404                        if (strtolower($msg->structure[$msg_number]->subtype) == "alternative") 
    435                                 $show_only_html = true;                  
     405                        { 
     406                                $show_only_html = false; 
     407                                foreach($msg->pid[$msg_number] as $values => $msg_part) 
     408                                { 
     409                                        $file_type = strtolower($msg->file_type[$msg_number][$values]); 
     410                                        if($file_type == "text/html") 
     411                                                $show_only_html = true; 
     412                                } 
     413                        } 
    436414                        else 
    437415                                $show_only_html = false; 
     
    439417                        foreach($msg->pid[$msg_number] as $values => $msg_part) 
    440418                        { 
    441                                  
     419 
    442420                                $file_type = strtolower($msg->file_type[$msg_number][$values]); 
    443421                                if($file_type == "message/rfc822") 
    444422                                        $has_multipart = false; 
    445          
     423 
    446424                                if($file_type == "multipart/alternative") 
    447425                                        $has_multipart = false; 
    448          
    449                                 if(($file_type == "text/plain"  
     426 
     427                                if(($file_type == "text/plain" 
    450428                                        || $file_type == "text/html") 
    451429                                        && $file_type != 'attachment') 
     
    455433                                                // if TXT file size > 100kb, then it will not expand. 
    456434                                                if(!($file_type == "text/plain" && $msg->fsize[$msg_number][$values] > 102400)) { 
    457                                                         $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])));                                                      
     435                                                        $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]))); 
    458436                                                } 
    459437                                        } 
    460438                                        // if HTML attachment file size > 300kb, then it will not expand. 
    461                                         else if($file_type == "text/html"  && $msg->fsize[$msg_number][$values] < 307200) 
     439                                        else if($file_type == "text/html"  && $msg->fsize[$msg_number][$values] < 3072000) 
    462440                                        { 
    463441                                                $content .= $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]); 
     
    467445                                else if($file_type == "message/delivery-status"){ 
    468446                                        $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 
    469                                         $content .= nl2br($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]));                                            
     447                                        $content .= nl2br($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values])); 
    470448 
    471449                                } 
    472450                                else if($file_type == "message/rfc822" || $file_type == "text/rfc822-headers"){ 
    473                                          
     451 
    474452                                        include_once("class.imap_attachment.inc.php"); 
    475453                                        $att = new imap_attachment(); 
    476454                                        $attachments =  $att -> get_attachment_info($this->mbox,$msg_number); 
    477                                         if($attachments['number_attachments'] > 0) {                                                                                             
     455                                        if($attachments['number_attachments'] > 0) { 
    478456                                                foreach($attachments ['attachment'] as $index => $attachment){ 
    479457                                                        if(strtolower($attachment['type']) == "delivery-status" || 
    480                                                                 strtolower($attachment['type']) == "rfc822" ||                                                           
     458                                                                strtolower($attachment['type']) == "rfc822" || 
    481459                                                                strtolower($attachment['type']) == "rfc822-headers" || 
    482460                                                                strtolower($attachment['type']) == "plain" 
    483461                                                        ){ 
    484                                                                 $obj = imap_rfc822_parse_headers(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values]);                                     
    485                                                                 $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>";                                    
     462                                                                $obj = imap_rfc822_parse_headers(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values]); 
     463                                                                $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 
    486464                                                                $content .= "<br><table  style='margin:2px;border:1px solid black;background:#EAEAEA'>"; 
    487465                                                                $content .= "<tr><td><b>".$this->functions->getLang("Subject").":</b></td><td>".$this->decode_string($obj->subject)."</td></tr>"; 
     
    489467                                                                $content .= "<tr><td><b>".$this->functions->getLang("Date").":</b></td><td>".$obj->date."</td></tr>"; 
    490468                                                                $content .= "<tr><td><b>".$this->functions->getLang("TO").":</b></td><td>".$this->decode_string($obj->to[0]->mailbox."@".$obj->to[0]->host)."</td></tr>"; 
    491                                                                 $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>";                                                                
     469                                                                $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>"; 
    492470                                                                $ix_part =      strtolower($attachment['type']) == "delivery-status" ? 1 : 0; 
    493                                                                 $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]));                                                           
    494                                                                 break;                   
     471                                                                $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])); 
     472                                                                break; 
    495473                                                        } 
    496474                                                } 
     
    502480                                        $content .= nl2br(imap_base64(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID))); 
    503481                                else if(!strtolower($msg->structure[$msg_number]->subtype) == "mixed") 
    504                                         $content .= nl2br(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID));                          
    505                         } 
    506                 }  
     482                                        $content .= nl2br(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID)); 
     483                        } 
     484                } 
    507485                // Force message with flag Seen (imap_fetchbody not works correctly) 
    508                 $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen");                                
     486                $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen"); 
    509487                $this->set_messages_flag($params); 
    510488                $content = $this->process_embedded_images($msg,$msg_number,$content, $msg_folder); 
     
    513491                return $return; 
    514492        } 
    515          
     493 
    516494        function htmlfilter($body) 
    517495        { 
    518496                require_once('htmlfilter.inc'); 
    519                  
     497 
    520498                $tag_list = Array( 
    521499                                false, 
     
    590568                                          '\\1round:\\2\\1' 
    591569                                        ) 
    592                                     ),      
    593            
     570                                    ), 
     571 
    594572                          '/^style/i' => 
    595573                              Array( 
     
    617595                                '/^a$/i' => Array('target' => '"_new"') 
    618596                ); 
    619          
    620          
     597 
     598 
    621599                $trusted_body = sanitize($body, 
    622600                                $tag_list, 
     
    628606                                $add_attr_to_tag 
    629607                ); 
    630          
     608 
    631609            return $trusted_body; 
    632610        } 
    633          
     611 
    634612        function decodeBody($body, $encoding, $charset=null) 
    635613        { 
     
    642620                if ($encoding == 'quoted-printable') 
    643621            { 
    644                          
     622 
    645623                        for($i=0;$i<256;$i++) { 
    646624                                $c1=dechex($i); 
     
    649627                                $myqprinta[]=$c1; 
    650628                                $myqprintb[]=chr($i); 
    651                         }                
     629                        } 
    652630                        $body = str_replace($myqprinta,$myqprintb,($body)); 
    653631                        $body = quoted_printable_decode($body); 
    654                 while (ereg("=\n", $body))  
     632                while (ereg("=\n", $body)) 
    655633                { 
    656634                        $body = ereg_replace ("=\n", '', $body); 
    657635                } 
    658636        } 
    659         else if ($encoding == 'base64')  
     637        else if ($encoding == 'base64') 
    660638        { 
    661639                $body = base64_decode($body); 
    662640        } 
    663         /*else if ($encoding == '7bit')  
     641        /*else if ($encoding == '7bit') 
    664642        { 
    665                 $body = quoted_printable_decode($body);                                          
     643                $body = quoted_printable_decode($body); 
    666644        }*/ 
    667645                // All other encodings are returned raw. 
     
    671649                        return $body; 
    672650        } 
    673          
     651 
    674652        function process_embedded_images($msg, $msgno, $body, $msg_folder) 
    675653        { 
     
    688666                        } 
    689667                } 
    690                  
     668 
    691669                return $body; 
    692670        } 
    693          
     671 
    694672        function replace_special_characters($body) 
    695673        { 
    696674                // Suspected TAGS! 
    697                 /*$tag_list = Array(    
     675                /*$tag_list = Array( 
    698676                        'blink','object','meta', 
    699677                        'html','link','frame', 
     
    704682                */ 
    705683 
    706                 // Layout problem: Change html elements  
    707                 // with absolute position to relate position, CASE INSENSITIVE.  
     684                // Layout problem: Change html elements 
     685                // with absolute position to relate position, CASE INSENSITIVE. 
    708686                $body = @eregi_replace("POSITION: ABSOLUTE;","",$body); 
    709687 
     
    713691 
    714692                $body = $this-> replace_links($body); 
    715                 $blocked_tags = array();                 
     693                $blocked_tags = array(); 
    716694                foreach($tag_list as $index => $tag) { 
    717695                        $new_body = eregi_replace("<$tag", "<!--$tag", $body); 
     
    725703        } 
    726704 
    727         function replace_links($body) {                                  
    728                 $matches = array(); 
     705        function replace_links($body) { 
     706                // Search for links,then open the link in new window. 
     707                //$body = @ereg_replace('[a-zA-Z]+://(([.]?[a-zA-Z0-9_/-])*)', '<a href="\\0" title="'.$this->functions->getLang("Open in New Window").'">\\0</a>',$body); 
     708                //Search for emails, then open a new message tab. 
     709                //$body = @ereg_replace('[a-zA-Z0-9!#$%&\'*+/=?^_`{|}~]+@([.]?[a-zA-Z0-9_/-])*', '<a title=\''.$this->functions->getLang("New Message").' -> \\0\'" onclick="Element(\'msg_number\').value=\'\\0\';new_message(\'new\',\'null\')" href="#">\\0</a>',$body); 
     710                //$matches = array(); 
    729711                // Verify exception. 
    730                 @preg_match("/<a href=\"notes:\/\/\//",$body,$matches); 
     712                //@preg_match("/<a href=\"notes:\/\/\//",$body,$matches); 
    731713                // It no has exception,then open the link in new window. 
    732                 if(count($matches)) 
    733                         return $body; 
    734                 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); 
     714                /*if(!count($matches)){ 
     715                        $body = @eregi_replace("<a (.*) href=", "<a \\1 target='_blank' href=", $body); 
     716                        $body = @str_replace("<a href=", "<a target='_blank' href=", $body); 
     717                        $body = @eregi_replace("target=\"\"", "target='_blank'", $body); 
     718                        $body = @eregi_replace("target=''", "target='_blank'", $body); 
     719                }*/ 
     720                $body = preg_replace('/(?<=[\s|(<br>)|\n|\r|;])((http(s?):\/\/((?:[\w]\.?)+(?::[\d]+)?[\/.\-~&=?%;@#,+\w]*))|((?:www?\.)(?:\w\.?)*(?::\d+)?[\/\w.\-~&=?%;@+]*))/i', '<a href="http$3://$4$5" target="_blank">http$3://$4$5</a>', $body); 
     721                return $body; 
    735722        } 
    736723 
    737724        function get_signature($msg, $msg_number, $msg_folder) 
    738         {  
     725        { 
    739726                foreach ($msg->file_type[$msg_number] as $index => $file_type) 
    740727                { 
    741728                        $file_type = strtolower($file_type); 
    742                         if(strtolower($msg->encoding[$msg_number][$index]) == 'base64')  
    743                         { 
    744                                 if ($file_type == 'application/x-pkcs7-signature')  
     729                        if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') 
     730                        { 
     731                                if ($file_type == 'application/x-pkcs7-signature') 
    745732                                { 
    746733                                        $export_mail = new ExportEml(); 
     
    748735                                        $params['msgs_to_export'] = $msg_number; 
    749736                                    $tempDir = ini_get("session.save_path"); 
    750                                         $cert_file = $tempDir."/certificate_".base_convert(microtime(), 10, 36).".crt";                                  
     737                                        $cert_file = $tempDir."/certificate_".base_convert(microtime(), 10, 36).".crt"; 
    751738                                        $result = openssl_pkcs7_verify($export_mail->export_msg($params),PKCS7_NOVERIFY,$cert_file); 
    752739                                        if (file_exists($cert_file)) 
     
    768755                        } 
    769756                } 
    770                 return $sign;    
     757                return $sign; 
    771758        } 
    772759 
     
    789776        return $thumbs_array; 
    790777        } 
    791                  
     778 
    792779        /*function delete_msg($params) 
    793780        { 
    794781                $folder = $params['folder']; 
    795782                $msgs_to_delete = explode(",",$params['msgs_to_delete']); 
    796                  
     783 
    797784                $mbox_stream = $this->open_mbox($folder); 
    798                  
     785 
    799786                foreach ($msgs_to_delete as $msg_number){ 
    800787                        imap_delete($mbox_stream, $msg_number, FT_UID); 
     
    807794        function delete_msgs($params) 
    808795        { 
    809                  
     796 
    810797                $folder = $params['folder']; 
    811798                $folder =  mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); 
    812799                $msgs_number = explode(",",$params['msgs_number']); 
    813800                $border_ID = $params['border_ID']; 
    814                  
     801 
    815802                $return = array(); 
    816                  
    817                 if ($params['get_previous_msg']){ 
     803 
     804                if ($params['get_previous_msg']) 
    818805                        $return['previous_msg'] = $this->get_info_previous_msg($params); 
    819                         // Fix problem in unserialize function JS. 
    820                         $return['previous_msg']['body'] = str_replace(array('{','}'), array('&#123;','&#125;'), $return['previous_msg']['body']); 
    821                 } 
    822806 
    823807                //$mbox_stream = $this->open_mbox($folder); 
    824808                $mbox_stream = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password) or die(serialize(array('imap_error' => imap_last_error()))); 
    825                  
     809 
    826810                foreach ($msgs_number as $msg_number) 
    827811                { 
     
    829813                                $return['msgs_number'][] = $msg_number; 
    830814                } 
    831                  
     815 
    832816                $return['folder'] = $folder; 
    833817                $return['border_ID'] = $border_ID; 
    834                  
     818 
    835819                if($mbox_stream) 
    836820                        imap_close($mbox_stream, CL_EXPUNGE); 
     
    838822        } 
    839823 
    840                  
     824 
    841825        function refresh($params) 
    842826        { 
    843827                include("class.imap_attachment.inc.php"); 
    844                 $imap_attachment = new imap_attachment();                
     828                $imap_attachment = new imap_attachment(); 
    845829                $folder = $params['folder']; 
    846830                $msg_range_begin = $params['msg_range_begin']; 
    847831                $msg_range_end = $params['msg_range_end']; 
    848832                $msgs_existent = $params['msgs_existent']; 
    849                 $sort_box_type = $params['sort_box_type'];               
     833                $sort_box_type = $params['sort_box_type']; 
    850834                $sort_box_reverse = $params['sort_box_reverse']; 
    851835                $msgs_in_the_server = array(); 
     
    855839                if(!count($sort_array_msg)) 
    856840                        return array(); 
    857                          
     841 
    858842                $num_msgs = (count($sort_array_msg) - imap_num_recent($this->mbox)); 
    859843                $msgs_in_the_client = explode(",", $msgs_existent); 
    860844 
    861                  
     845 
    862846                for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= count($sort_array_msg))); $msg_range_begin++) 
    863847                { 
     
    874858                        } 
    875859                } 
    876                  
     860 
    877861                $msg_to_insert  = array_diff($msgs_in_the_server, $msgs_in_the_client); 
    878862                $msg_to_delete = array_diff($msgs_in_the_client, $msgs_in_the_server); 
    879                  
     863 
    880864                $msgs_to_exec = array(); 
    881865                if ((count($msg_to_insert)) && ($msgs_existent)) 
     
    903887                        } 
    904888                } 
    905                  
     889 
    906890                $return = array(); 
    907891                $i = 0; 
     
    911895                        if (!is_object($header)) 
    912896                                return false; 
    913                          
     897 
    914898                        $return[$i]['msg_number']       = $msg_number; 
    915899                        $return[$i]['command']          = $command; 
    916                          
     900 
    917901                        $return[$i]['msg_folder']       = $folder; 
    918902                        $return[$i]['Recent']           = $header->Recent; 
     
    928912                        else 
    929913                                $return[$i]['udate'] = $date_msg; 
    930                          
     914 
    931915                        $from = $header->from; 
    932916                        $return[$i]['from'] = array(); 
     
    934918                        $return[$i]['from']['name'] = $tmp[0]->text; 
    935919                        $return[$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; 
    936                         //$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>';  
     920                        //$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>'; 
    937921                        if(!$return[$i]['from']['name']) 
    938922                                $return[$i]['from']['name'] = $return[$i]['from']['email']; 
    939                          
     923 
    940924                        /*$toaddress = imap_mime_header_decode($header->toaddress); 
    941925                        $return[$i]['toaddress'] = ''; 
     
    948932                        $return[$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; 
    949933                        $return[$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; 
    950                          
     934 
    951935                        $return[$i]['subject'] = $this->decode_string($header->fetchsubject); 
    952936 
    953937                        $return[$i]['Size'] = $header->Size; 
    954938                        $return[$i]['reply_toaddress'] = $header->reply_toaddress; 
    955                          
     939 
    956940                        $return[$i]['attachment'] = array(); 
    957941                        $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); 
     
    965949        } 
    966950 
    967         function get_folders_list($params = null) 
    968         { 
    969                 $mbox_stream = $this->open_mbox();               
     951        function get_folders_list() 
     952        { 
     953                $mbox_stream = $this->open_mbox(); 
    970954                $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; 
    971955                $folders_list = imap_getmailboxes($mbox_stream, $serverString, "*"); 
    972956                $tmp = array(); 
    973957                $result = array(); 
    974                  
     958 
    975959                if (is_array($folders_list)) { 
    976960                        reset($folders_list); 
    977                 $ldap = new ldap_functions(); 
    978                          
     961                $this->ldap = new ldap_functions(); 
     962 
    979963                        $i = 0; 
    980964                        while (list($key, $val) = each($folders_list)) { 
    981965                                $status = imap_status($mbox_stream, $val->name, SA_UNSEEN); 
    982966                                $result[$i]['folder_unseen'] = $status->unseen; 
    983                          
     967 
    984968                                //$tmp_folder_id = explode("}", imap_utf7_decode($val->name)); 
    985969                                $tmp_folder_id = explode("}", mb_convert_encoding($val->name, "ISO_8859-1", "UTF7-IMAP" )); 
    986970                                $folder_id = $tmp_folder_id[1]; 
    987971                                $result[$i]['folder_id'] = $folder_id; 
    988                                  
     972 
    989973                                $tmp_folder_parent = explode($this->imap_delimiter, $folder_id); 
    990974                                $result[$i]['folder_name'] = array_pop($tmp_folder_parent); 
    991975                                $result[$i]['folder_name'] = $result[$i]['folder_name'] == 'INBOX' ? 'Inbox' : $result[$i]['folder_name']; 
    992976                                if (is_numeric($result[$i]['folder_name']))     { 
    993                                         if ($cn = $ldap->uid2cn($result[$i]['folder_name'])){ 
     977                                        if ($cn = $this->ldap->uid2cn($result[$i]['folder_name'])){ 
    994978                                                $result[$i]['folder_name'] = $cn; 
    995979                                        } 
    996980                                } 
    997                                  
     981 
    998982                                $tmp_folder_parent = implode($this->imap_delimiter, $tmp_folder_parent); 
    999983                                $result[$i]['folder_parent'] = $tmp_folder_parent == 'INBOX' ? '' : $tmp_folder_parent; 
    1000                                          
     984 
    1001985                                if (($val->attributes == 32) && ($result[$i]['folder_name'] != 'Inbox')) 
    1002986                                        $result[$i]['folder_hasChildren'] = 1; 
     
    1004988                                        $result[$i]['folder_hasChildren'] = 0; 
    1005989 
    1006                                 $i++;                            
     990                                $i++; 
    1007991                        } 
    1008992                } 
    1009                  
     993 
    1010994                foreach ($result as $folder_info) 
    1011995                { 
    1012996                        $array_tmp[] = $folder_info['folder_id']; 
    1013997                } 
    1014                  
     998 
    1015999                natcasesort($array_tmp); 
    1016                  
     1000 
    10171001                foreach ($array_tmp as $key => $folder_id) 
    10181002                { 
    10191003                        $result2[] = $result[$key]; 
    10201004                } 
    1021                  
    1022                 $current_folder = "INBOX"; 
    1023                 if($params && $params['folder']) 
    1024                         $current_folder = $params['folder']; 
    1025                 return array_merge($result2, $this->get_quota(array(folder_id => $current_folder))); 
    1026         } 
    1027          
     1005 
     1006                if($mbox_stream && is_resource($mbox_stream)){ 
     1007                        imap_close($mbox_stream); 
     1008                } 
     1009 
     1010                return array_merge($result2); 
     1011        } 
     1012 
    10281013        function create_mailbox($arr) 
    10291014        { 
     
    10321017                $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 
    10331018                $namebox =  mb_convert_encoding($namebox, "UTF7-IMAP", "UTF-8"); 
    1034                  
     1019 
    10351020                $result = "Ok"; 
    10361021                if(!imap_createmailbox($mbox_stream,"{".$imap_server."}$namebox")) 
    10371022                { 
    10381023                        $result = implode("<br />\n", imap_errors()); 
    1039                 }        
    1040                  
     1024                } 
     1025 
    10411026                if($mbox_stream) 
    10421027                        imap_close($mbox_stream); 
    1043                                          
     1028 
    10441029                return $result; 
    1045                  
    1046         } 
    1047          
     1030 
     1031        } 
     1032 
    10481033        function create_extra_mailbox($arr) 
    10491034        { 
     
    10521037                $mbox_stream = $this->open_mbox(); 
    10531038                $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 
    1054                 foreach($nameboxs as $key=>$tmp){                        
     1039                foreach($nameboxs as $key=>$tmp){ 
    10551040                        if($tmp != ""){ 
    10561041                                if(!imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}$tmp"))){ 
    10571042                                        $result = implode("<br />\n", imap_errors()); 
    10581043                                        if($mbox_stream) 
    1059                                                 imap_close($mbox_stream);                                        
     1044                                                imap_close($mbox_stream); 
    10601045                                        return $result; 
    10611046                                } 
     
    10661051                return true; 
    10671052        } 
    1068          
     1053 
    10691054        function delete_mailbox($arr) 
    10701055        { 
     
    10731058                $mbox_stream = $this->open_mbox(); 
    10741059                //$del_folder = imap_deletemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox"); 
    1075                  
     1060 
    10761061                $result = "Ok"; 
    10771062                $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); 
     
    10841069                return $result; 
    10851070        } 
    1086          
     1071 
    10871072        function ren_mailbox($arr) 
    10881073        { 
     
    10921077                $mbox_stream = $this->open_mbox(); 
    10931078                //$ren_folder = imap_renamemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox","{".$imap_server."}INBOX.$new_box"); 
    1094                  
     1079 
    10951080                $result = "Ok"; 
    10961081                $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); 
    10971082                $new_box = mb_convert_encoding($new_box, "UTF7-IMAP","UTF-8"); 
    1098                  
     1083 
    10991084                if(!imap_renamemailbox($mbox_stream,"{".$imap_server."}$namebox","{".$imap_server."}$new_box")) 
    11001085                { 
    1101                         $result = imap_errors();                         
     1086                        $result = imap_errors(); 
    11021087                } 
    11031088                if($mbox_stream) 
    11041089                        imap_close($mbox_stream); 
    11051090                return $result; 
    1106                  
    1107         } 
    1108          
     1091 
     1092        } 
     1093 
    11091094        function get_num_msgs($params) 
    11101095        { 
     
    11141099                        if(!$this->mbox || !is_resource($this->mbox)) 
    11151100                        return imap_last_error(); 
    1116                 }                
     1101                } 
    11171102                $num_msgs = imap_num_msg($this->mbox); 
    1118                 if($this->mbox || is_resource($this->mbox)) 
     1103                if($this->mbox && is_resource($this->mbox)) 
    11191104                        imap_close($this->mbox); 
    1120                  
     1105 
    11211106                return $num_msgs; 
    11221107        } 
    1123          
     1108 
    11241109        function send_mail($params) 
    11251110        { 
     
    11391124                $attachments = $params['FILES']; 
    11401125                $forwarding_attachments = $params['forwarding_attachments']; 
    1141                   
     1126 
    11421127                $folder =$params['folder']; 
    1143                 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1");                
    1144                 $folder_name = $params['folder_name'];           
     1128                $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 
     1129                $folder_name = $params['folder_name']; 
    11451130                // Fix problem with cyrus delimiter changes. 
    1146                 // Dots in names: enabled/disabled.                              
     1131                // Dots in names: enabled/disabled. 
    11471132                $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); 
    11481133                $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); 
    11491134                // End Fix. 
    1150                 if ($folder != 'null'){                  
     1135                if ($folder != 'null'){ 
    11511136                        $mail->SaveMessageInFolder = $folder; 
    11521137                } 
    11531138//////////////////////////////////////////////////////////////////////////////////////////////////// 
    11541139                $mail->SMTPDebug = false; 
    1155                                  
     1140 
    11561141                $mail->IsSMTP(); 
    11571142                $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; 
     
    11651150                        $mail->From = $fromaddress[1]; 
    11661151                } 
    1167                                  
     1152 
    11681153                $this->add_recipients("to", $toaddress, &$mail); 
    11691154                $this->add_recipients("cc", $ccaddress, &$mail); 
     
    11751160//////////////////////////////////////////////////////////////////////////////////////////////////// 
    11761161                //      Build CID for embedded Images!!! 
    1177                 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU'; 
     1162                $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&amp;msg_num=(.+)?&amp;msg_part=(.+)?)"/isU'; 
    11781163                $cid_imgs = ''; 
    11791164                $name_cid_files = array(); 
    11801165                preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); 
    11811166                $cid_array = array(); 
    1182                 foreach($cid_imgs[6] as $j => $val){ 
    1183                                 if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) ) 
     1167                foreach($cid_imgs[4] as $j => $val){ 
     1168                                if ( !array_key_exists($cid_imgs[3][$j].$val, $cid_array) ) 
    11841169                        { 
    1185                 $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); 
     1170                $cid_array[$cid_imgs[3][$j].$val] = base_convert(microtime(), 10, 36); 
    11861171                        } 
    1187                         $cid = $cid_array[$cid_imgs[4][$j].$val];  
     1172                        $cid = $cid_array[$cid_imgs[3][$j].$val]; 
    11881173                        $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 
    1189                          
    1190                                 if ($msg_uid != $cid_imgs[4][$j]) // The image isn't in the same mail? 
     1174 
     1175                                if ($msg_uid != $cid_imgs[3][$j]) // The image isn't in the same mail? 
    11911176                                { 
    1192                                         $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); 
     1177                                        $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[3][$j], $cid_imgs[4][$j], 'base64'); 
    11931178                                        $fileName = "image_".($j).".jpg"; 
    11941179                                        $fileCode = "base64"; 
     
    11971182                                else 
    11981183                                { 
    1199                                         $attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2]; 
     1184                                        $attach_img = $forwarding_attachments[$cid_imgs[4][$j]-2]; 
    12001185                                        $file_description = unserialize(rawurldecode($attach_img)); 
    12011186 
    1202                                         foreach($file_description as $i => $descriptor){                                 
     1187                                        foreach($file_description as $i => $descriptor){ 
    12031188                                                $file_description[$i]  = eregi_replace('\'*\'','',$descriptor); 
    12041189                                        } 
     
    12071192                                        $fileCode = $file_description[4]; 
    12081193                                        $fileType = $this->get_file_type($file_description[2]); 
    1209                                         unset($forwarding_attachments[$cid_imgs[6][$j]-2]); 
     1194                                        unset($forwarding_attachments[$cid_imgs[4][$j]-2]); 
    12101195                                } 
    12111196                                $tempDir = ini_get("session.save_path"); 
    1212                                 $file = "cid_image_".base_convert(microtime(), 10, 36).".dat";                                   
     1197                                $file = "cid_image_".base_convert(microtime(), 10, 36).".dat"; 
    12131198                                $f = fopen($tempDir.'/'.$file,"w"); 
    12141199                                fputs($f,$fileContent); 
     
    12171202                                        $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); 
    12181203                                //else 
    1219                                 //      return "Error loading image attachment content";                                                 
     1204                                //      return "Error loading image attachment content"; 
    12201205 
    12211206                } 
     
    12321217                        } 
    12331218                        if( $total_uploaded_size > $upload_max_filesize) 
    1234                                 return 'false';                  
    1235                 }                        
     1219                                return 'false'; 
     1220                } 
    12361221//////////////////////////////////////////////////////////////////////////////////////////////////// 
    12371222                //      Build Forwarding Attachments!!! 
     
    12421227                                $name_cid_files[count($name_cid_files)] = $name_cid_files[0]; 
    12431228                                $name_cid_files[0] = null; 
    1244                         }                        
    1245                          
     1229                        } 
     1230 
    12461231                        foreach($forwarding_attachments as $forwarding_attachment) 
    12471232                        { 
    12481233                                        $file_description = unserialize(rawurldecode($forwarding_attachment)); 
    12491234                                        $tmp = array_values($file_description); 
    1250                                         foreach($file_description as $i => $descriptor){                                 
     1235                                        foreach($file_description as $i => $descriptor){ 
    12511236                                                $tmp[$i]  = eregi_replace('\'*\'','',$descriptor); 
    12521237                                        } 
    1253                                         $file_description = $tmp;                                        
     1238                                        $file_description = $tmp; 
    12541239                                        $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 
    12551240                                        $fileName = $file_description[2]; 
     
    12721257                else 
    12731258                { 
    1274                         if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True")  
     1259                        if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True") 
    12751260                        { 
    12761261                                $userid = $_SESSION['phpgw_info']['expressomail']['user']['userid']; 
     
    12781263                                $now = date("d/m/y H:i:s"); 
    12791264                                $addrs = $toaddress.$ccaddress.$ccoaddress; 
    1280                                 $sent = trim($sent);                                                                                             
     1265                                $sent = trim($sent); 
    12811266                                error_log("$now - $userip - $sent [$subject] - $userid => $addrs\r\n", 3, "/home/expressolivre/mail_senders.log"); 
    12821267                        } 
    12831268                        if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_dynamic_contacts']) 
    12841269                        { 
    1285                                 $contacts = new dynamic_contacts(); 
    1286                                 $contacts->add_dynamic_contacts($toaddress.$ccaddress.$ccoaddress); 
     1270                        $contacts = new dynamic_contacts(); 
     1271                        $contacts->add_dynamic_contacts($toaddress.$ccaddress.$ccoaddress); 
    12871272                        } 
    12881273                        return true; 
     
    12921277        function add_recipients($recipient_type, $full_address, $mail) 
    12931278        { 
    1294                 $parse_address = imap_rfc822_parse_adrlist($full_address, "");           
    1295                 foreach ($parse_address as $val)  
     1279                $parse_address = imap_rfc822_parse_adrlist($full_address, ""); 
     1280                foreach ($parse_address as $val) 
    12961281                { 
    12971282                        //echo "<script language=\"javascript\">javascript:alert('".$val->mailbox."@".$val->host."');</script>"; 
    12981283                        if ($val->mailbox == "INVALID_ADDRESS") 
    12991284                                continue; 
    1300                          
     1285 
    13011286                        if (empty($val->personal)) 
    13021287                        { 
     
    13321317                return true; 
    13331318        } 
    1334          
     1319 
    13351320        function get_forwarding_attachment($msg_folder, $msg_number, $msg_part, $encoding) 
    13361321        { 
    1337                 $mbox_stream = $this->open_mbox($msg_folder);                    
    1338                 $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID);             
     1322                $mbox_stream = $this->open_mbox($msg_folder); 
     1323                $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID); 
    13391324                if($encoding == 'base64') 
    1340                         # The function imap_base64 adds a new line 
    1341                         # at ASCII text, with CRLF line terminators. 
    1342                         # So is being exchanged for base64_decode. 
    1343                         # 
    1344                         #$fileContent = imap_base64($fileContent); 
    1345                         $fileContent = base64_decode($fileContent); 
     1325                        $fileContent = imap_base64($fileContent); 
    13461326                else if($encoding == 'quoted-printable') 
    1347                         $fileContent = quoted_printable_decode($fileContent);                            
     1327                        $fileContent = quoted_printable_decode($fileContent); 
    13481328                return $fileContent; 
    13491329        } 
    1350          
     1330 
    13511331        function del_last_caracter($string) 
    13521332        { 
    13531333                $string = substr($string,0,(strlen($string) - 1)); 
    1354                 return $string;  
    1355         } 
    1356          
     1334                return $string; 
     1335        } 
     1336 
    13571337        function del_last_two_caracters($string) 
    13581338        { 
    13591339                $string = substr($string,0,(strlen($string) - 2)); 
    1360                 return $string;  
    1361         } 
    1362          
     1340                return $string; 
     1341        } 
     1342 
    13631343        function imap_sortfrom($sort_box_reverse, $search_box_type) 
    13641344        { 
    13651345                $sortfrom = array(); 
    13661346                $sortfrom_uid = array(); 
    1367                  
     1347 
    13681348                $num_msgs = imap_num_msg($this->mbox); 
    13691349                for ($i=1; $i<=$num_msgs; $i++) 
     
    13781358                                continue; 
    13791359                        } 
    1380                         // List ANSWERED messages.                       
     1360                        // List ANSWERED messages. 
    13811361                        elseif($search_box_type == "ANSWERED" && !trim($header->Answered)){ 
    1382                                 continue;                                
    1383                         } 
    1384                         // List FLAGGED messages.                        
     1362                                continue; 
     1363                        } 
     1364                        // List FLAGGED messages. 
    13851365                        elseif($search_box_type == "FLAGGED" && !trim($header->Flagged)){ 
    13861366                                continue; 
    13871367                        } 
    1388                                                  
    1389                         if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email'])                              
     1368 
     1369                        if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email']) 
    13901370                                $from = $header->to; 
    13911371                        else 
    13921372                                $from = $header->from; 
    1393                          
    1394                         $tmp = imap_mime_header_decode($from[0]->personal);                      
    1395                          
     1373 
     1374                        $tmp = imap_mime_header_decode($from[0]->personal); 
     1375 
    13961376                        if ($tmp[0]->text != "") 
    13971377                                $sortfrom[$i] = $tmp[0]->text; 
     
    13991379                                $sortfrom[$i] = $from[0]->mailbox . "@" . $from[0]->host; 
    14001380                } 
    1401                  
     1381 
    14021382                natcasesort($sortfrom); 
    1403                  
     1383 
    14041384                foreach($sortfrom as $index => $header_msg) 
    1405                 {        
     1385                { 
    14061386                        $sortfrom_uid[] = imap_uid($this->mbox, $index); 
    14071387                } 
    1408                  
     1388 
    14091389                if ($sort_box_reverse) 
    14101390                        $sortfrom_uid = array_reverse($sortfrom_uid); 
    1411                  
     1391 
    14121392                return $sortfrom_uid; 
    14131393        } 
    14141394 
    1415         function move_search_messages($params){          
    1416                 $params['selected_messages'] = urldecode($params['selected_messages']);  
     1395        function move_search_messages($params){ 
     1396                $params['selected_messages'] = urldecode($params['selected_messages']); 
    14171397                $params['new_folder'] = urldecode($params['new_folder']); 
    14181398                $params['new_folder_name'] = urldecode($params['new_folder_name']); 
    14191399                $sel_msgs = explode(",", $params['selected_messages']); 
    1420                 @reset($sel_msgs);       
     1400                @reset($sel_msgs); 
    14211401                $sorted_msgs = array(); 
    14221402                foreach($sel_msgs as $idx => $sel_msg) { 
     
    14241404                         if(array_key_exists($sel_msg[0], $sorted_msgs)){ 
    14251405                                $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; 
    1426                          }       
     1406                         } 
    14271407                         else { 
    14281408                                $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; 
     
    14301410                } 
    14311411                @ksort($sorted_msgs); 
    1432                 $last_return = false;            
    1433                 foreach($sorted_msgs as $folder => $msgs_number) {                       
     1412                $last_return = false; 
     1413                foreach($sorted_msgs as $folder => $msgs_number) { 
    14341414                        $params['msgs_number'] = $msgs_number; 
    1435                         $params['folder'] = $folder;     
     1415                        $params['folder'] = $folder; 
    14361416                        if($params['new_folder'] && $folder != $params['new_folder']){ 
    1437                                 $last_return = $this -> move_messages($params);                          
     1417                                $last_return = $this -> move_messages($params); 
    14381418                        } 
    14391419                        elseif(!$params['new_folder'] || $params['delete'] ){ 
     
    14441424                return $last_return; 
    14451425        } 
    1446          
     1426 
    14471427        function move_messages($params) 
    14481428        { 
    1449                 $folder = $params['folder'];             
    1450                 $mbox_stream = $this->open_mbox($folder);                
     1429                $folder = $params['folder']; 
     1430                $mbox_stream = $this->open_mbox($folder); 
    14511431                $newmailbox = ($params['new_folder']); 
    14521432                $newmailbox = mb_convert_encoding($newmailbox, "UTF7-IMAP","ISO_8859-1"); 
     
    14581438                                                'border_ID' => $params['border_ID'], 
    14591439                                                'status' => true); //Status foi adicionado para validar as permissoes ACL 
    1460                  
     1440 
    14611441                //Este bloco tem a finalidade de averiguar as permissoes para pastas compartilhadas 
    14621442        if (substr($folder,0,4) == 'user'){ 
     
    14781458                        } 
    14791459        } 
    1480                                  
    1481                 // Caso estejamos no box principal, nao eh necessario pegar a informacao da mensagem anterior.           
     1460        //Este bloco tem a finalidade de transformar o CPF das pastas compartilhadas em common name 
     1461        if (substr($new_folder_name,0,4) == 'user'){ 
     1462                $this->ldap = new ldap_functions(); 
     1463                $tmp_folder_name = explode($this->imap_delimiter, $new_folder_name); 
     1464                        $return['new_folder_name'] = array_pop($tmp_folder_name); 
     1465                        if (is_numeric($return['new_folder_name'])) 
     1466                                if( $cn = $this->ldap->uid2cn($return['new_folder_name'])) 
     1467                                        $return['new_folder_name'] = $cn; 
     1468        } 
     1469 
     1470                // Caso estejamos no box principal, nï¿œo ï¿œ necessï¿œrio pegar a informaᅵᅵo da mensagem anterior. 
    14821471                if (($params['get_previous_msg']) && ($params['border_ID'] != 'null') && ($params['border_ID'] != '')) 
    1483                 { 
    14841472                        $return['previous_msg'] = $this->get_info_previous_msg($params); 
    1485                         // Fix problem in unserialize function JS. 
    1486                         $return['previous_msg']['body'] = str_replace(array('{','}'), array('&#123;','&#125;'), $return['previous_msg']['body']); 
    1487                 } 
    1488                  
    1489                 $mbox_stream = $this->open_mbox($folder);        
     1473 
     1474                $mbox_stream = $this->open_mbox($folder); 
    14901475                if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { 
    14911476                        imap_expunge($mbox_stream); 
     
    14941479                        return $return; 
    14951480                }else { 
    1496                         if(strstr(imap_last_error(),'Over quota')) {                             
     1481                        if(strstr(imap_last_error(),'Over quota')) { 
    14971482                                $accountID      = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminUsername']; 
    1498                                 $pass           = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminPW'];                                                                        
    1499                                 $userID         = $_SESSION['phpgw_info']['expressomail']['user']['userid'];                                                             
     1483                                $pass           = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminPW']; 
     1484                                $userID         = $_SESSION['phpgw_info']['expressomail']['user']['userid']; 
    15001485                                $server         = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 
    15011486                                $mbox           = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}INBOX", $accountID, $pass) or die(serialize(array('imap_error' => imap_last_error()))); 
    15021487                                if(!$mbox) 
    15031488                                        return imap_last_error(); 
    1504                                 $quota  = imap_get_quotaroot($mbox_stream, "INBOX");                             
     1489                                $quota  = imap_get_quotaroot($mbox_stream, "INBOX"); 
    15051490                                if(! imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, 2.1 * $quota['usage'])) { 
    15061491                                        if($mbox_stream) 
    15071492                                                imap_close($mbox_stream); 
    1508                                         if($mbox)                                                                        
     1493                                        if($mbox) 
    15091494                                                imap_close($mbox); 
    1510                                         return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n";                                                                
     1495                                        return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n"; 
    15111496                                } 
    15121497                                if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { 
     
    15181503                                                if($mbox) 
    15191504                                                        imap_close($mbox); 
    1520                                                 return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n";                                                          
     1505                                                return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; 
    15211506                                        } 
    1522                                         return $return;                                                                                                  
     1507                                        return $return; 
    15231508                                } 
    15241509                                else { 
     
    15281513                                                if($mbox) 
    15291514                                                        imap_close($mbox); 
    1530                                                 return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n";                                                          
     1515                                                return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; 
    15311516                                        } 
    1532                                         return imap_last_error();                                
    1533                                 } 
    1534                                  
     1517                                        return imap_last_error(); 
     1518                                } 
     1519 
    15351520                        } 
    15361521                        else { 
     
    15391524                                return "move_messages() line ".__LINE__.": ". imap_last_error()." folder:".$newmailbox; 
    15401525                        } 
    1541                 }                
    1542         } 
    1543          
     1526                } 
     1527        } 
     1528 
    15441529        function save_msg($params) 
    15451530        { 
    1546                  
     1531 
    15471532                include_once("class.phpmailer.php"); 
    15481533                $mail = new PHPMailer(); 
     
    15591544                $attachments = $params['FILES']; 
    15601545                $return_files = $params['FILES']; 
    1561                   
     1546 
    15621547                $folder = $params['folder']; 
    1563                 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1");                
     1548                $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 
    15641549                // Fix problem with cyrus delimiter changes. 
    1565                 // Dots in names: enabled/disabled.                              
     1550                // Dots in names: enabled/disabled. 
    15661551                $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); 
    15671552                $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); 
    15681553                // End Fix. 
    1569                                          
     1554 
    15701555                $mail->SaveMessageInFolder = $folder; 
    15711556                $mail->SMTPDebug = false; 
    1572                                                  
     1557 
    15731558                $mail->IsSMTP(); 
    15741559                $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; 
     
    15761561                $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; 
    15771562                $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 
    1578                  
     1563 
    15791564                $mail->Sender = $mail->From; 
    15801565                $mail->SenderName = $mail->FromName; 
    15811566                $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 
    15821567                $mail->From =  $_SESSION['phpgw_info']['expressomail']['user']['email']; 
    1583                                  
     1568 
    15841569                $this->add_recipients("to", $toaddress, &$mail); 
    15851570                $this->add_recipients("cc", $ccaddress, &$mail); 
     
    15871572                $mail->IsHTML(true); 
    15881573                $mail->Body = $body; 
    1589                  
     1574 
    15901575                //      Build CID for embedded Images!!! 
    1591                 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU'; 
     1576                $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&amp;msg_num=(.+)?&amp;msg_part=(.+)?)"/isU'; 
    15921577                $cid_imgs = ''; 
    15931578                $name_cid_files = array(); 
    15941579                preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); 
    15951580                $cid_array = array(); 
    1596                 foreach($cid_imgs[6] as $j => $val){ 
    1597                                 if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) ) 
     1581                foreach($cid_imgs[4] as $j => $val){ 
     1582                                if ( !array_key_exists($cid_imgs[3][$j].$val, $cid_array) ) 
    15981583                        { 
    1599                 $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); 
     1584                $cid_array[$cid_imgs[3][$j].$val] = base_convert(microtime(), 10, 36); 
    16001585                        } 
    1601                         $cid = $cid_array[$cid_imgs[4][$j].$val];  
     1586                        $cid = $cid_array[$cid_imgs[3][$j].$val]; 
    16021587                        $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 
    1603                          
    1604                                 if ($msg_uid != $cid_imgs[4][$j]) // The image isn't in the same mail? 
     1588 
     1589                                if ($msg_uid != $cid_imgs[3][$j]) // The image isn't in the same mail? 
    16051590                                { 
    1606                                         $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); 
    1607                                         //prototype: get_forwarding_attachment ( folder, msg number, part, encoding) 
     1591                                        $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[3][$j], $cid_imgs[4][$j], 'base64'); 
    16081592                                        $fileName = "image_".($j).".jpg"; 
    16091593                                        $fileCode = "base64"; 
    16101594                                        $fileType = "image/jpg"; 
    1611                                         $file_attached[0] = $cid_imgs[2][$j]; 
    1612                                         $file_attached[1] = $cid_imgs[4][$j]; 
    1613                                         $file_attached[2] = $fileName; 
    1614                                         $file_attached[3] = $cid_imgs[6][$j]; 
    1615                                         $file_attached[4] = 'base64'; 
    1616                                         $file_attached[5] = strlen($fileContent); //Size of file 
    1617                                         $return_forward[] = $file_attached; 
    16181595                                } 
    16191596                                else 
    16201597                                { 
    1621                                         $attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2]; 
     1598                                        $attach_img = $forwarding_attachments[$cid_imgs[4][$j]-2]; 
    16221599                                        $file_description = unserialize(rawurldecode($attach_img)); 
    1623                                         foreach($file_description as $i => $descriptor){                                 
     1600                                        foreach($file_description as $i => $descriptor){ 
    16241601                                                $file_description[$i]  = eregi_replace('\'*\'','',$descriptor); 
    16251602                                        } 
     
    16281605                                        $fileCode = $file_description[4]; 
    16291606                                        $fileType = $this->get_file_type($file_description[2]); 
    1630                                         unset($forwarding_attachments[$cid_imgs[6][$j]-2]); 
     1607                                        unset($forwarding_attachments[$cid_imgs[4][$j]-2]); 
    16311608                                        if (!empty($file_description)) 
    16321609                                        { 
     
    16361613                                } 
    16371614                                $tempDir = ini_get("session.save_path"); 
    1638                                 $file = "cid_image_".base_convert(microtime(), 10, 36).".dat";                                   
     1615                                $file = "cid_image_".base_convert(microtime(), 10, 36).".dat"; 
    16391616                                $f = fopen($tempDir.'/'.$file,"w"); 
    16401617                                fputs($f,$fileContent); 
     
    16431620                                        $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); 
    16441621                                //else 
    1645                                 //      return "Error loading image attachment content";                                                 
    1646  
    1647                 } 
    1648          
    1649         //      Build Forwarding Attachments!!!          
     1622                                //      return "Error loading image attachment content"; 
     1623 
     1624                } 
     1625 
     1626        //      Build Forwarding Attachments!!! 
    16501627                if (count($forwarding_attachments) > 0) 
    16511628                { 
     
    16541631                                $file_description = unserialize(rawurldecode($forwarding_attachment)); 
    16551632                                $tmp = array_values($file_description); 
    1656                                 foreach($file_description as $i => $descriptor){                                 
     1633                                foreach($file_description as $i => $descriptor){ 
    16571634                                        $tmp[$i]  = eregi_replace('\'*\'','',$descriptor); 
    16581635                                } 
    16591636                                $file_description = $tmp; 
    1660                                  
     1637 
    16611638                                $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 
    16621639                                $fileName = $file_description[2]; 
    1663                                  
     1640 
    16641641                                $file_description[5] = strlen($fileContent); //Size of file 
    16651642                                $return_forward[] = $file_description; 
    1666                          
     1643 
    16671644                                        $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); 
    16681645                        } 
    16691646                } 
    1670                  
     1647 
    16711648                if ((count($return_forward) > 0) && (count($return_files) > 0)) 
    16721649                        $return_files = array_merge_recursive($return_forward,$return_files); 
     
    16741651                        if (count($return_files) < 1) 
    16751652                                $return_files = $return_forward; 
    1676          
     1653 
    16771654                //      Build Uploading Attachments!!! 
    16781655                if (count($attachments)) 
    16791656                        foreach ($attachments as $attach) 
    1680                                 $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name']));  // optional name                   
    1681          
    1682          
    1683                  
     1657                                $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name']));  // optional name 
     1658 
     1659 
     1660 
    16841661                if(!empty($mail->AltBody)) 
    16851662            $mail->ContentType = "multipart/alternative"; 
     
    16891666        $header = $mail->CreateHeader(); 
    16901667        $body = $mail->CreateBody(); 
    1691          
     1668 
    16921669        if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') 
    16931670                { 
     
    17031680                $imap_port      = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; 
    17041681                $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$folder, $username, $password); 
    1705          
     1682 
    17061683                $new_header = str_replace("\n", "\r\n", $header); 
    17071684                $new_body = str_replace("\n", "\r\n", $body); 
    1708                  
     1685 
    17091686                $return['append'] = imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".$folder, $new_header . $new_body, "\\Seen \\Draft"); 
    17101687                $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); 
    17111688                $return['msg_no'] = $status->uidnext - 1; 
    17121689                $return['folder_id'] = $folder; 
    1713                  
     1690 
    17141691                if($mbox_stream) 
    17151692                        imap_close($mbox_stream); 
    1716                                  
     1693 
    17171694                foreach ($return_files as $index => $_attachment) { 
    17181695                        if (array_key_exists("name",$_attachment)){ 
     
    17261703                        } 
    17271704                } 
    1728                  
     1705 
    17291706                $return['files'] = serialize($return_files); 
    1730                                  
     1707 
    17311708                if (!$return['append']) 
    17321709                        $return['append'] = imap_last_error(); 
    1733                  
     1710 
    17341711                return $return; 
    17351712        } 
    1736          
     1713 
    17371714        function set_messages_flag($params) 
    17381715        { 
     
    17431720                $return["msgs_to_set"] = $msgs_to_set; 
    17441721                $return["flag"] = $flag; 
    1745                  
     1722 
    17461723                if(!$this->mbox && !is_resource($this->mbox)) 
    17471724                        $this->mbox = $this->open_mbox($folder); 
    1748                  
     1725 
    17491726                if ($flag == "unseen") 
    17501727                        $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Seen", ST_UID); 
     
    17611738                elseif ($flag == "unflagged") 
    17621739                        $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Flagged", ST_UID); 
    1763                  
     1740 
    17641741                if($this->mbox && is_resource($this->mbox)) 
    17651742                        imap_close($this->mbox); 
    17661743                return $return; 
    17671744        } 
    1768          
     1745 
    17691746        function get_file_type($file_name) 
    17701747        { 
    17711748                $file_name = strtolower($file_name); 
    17721749                $strFileType = strrev(substr(strrev($file_name),0,4)); 
    1773                 if ($strFileType == ".asf")  
     1750                if ($strFileType == ".asf") 
    17741751                        return "video/x-ms-asf"; 
    17751752                if ($strFileType == ".avi") 
     
    17971774                if ($strFileType == ".htm" || $strFileType == "html") 
    17981775                        return "text/html"; 
    1799                 if ($strFileType == ".xml")  
     1776                if ($strFileType == ".xml") 
    18001777                        return "text/xml"; 
    1801                 if ($strFileType == ".xsl")  
     1778                if ($strFileType == ".xsl") 
    18021779                        return "text/xsl"; 
    1803                 if ($strFileType == ".css")  
     1780                if ($strFileType == ".css") 
    18041781                        return "text/css"; 
    1805                 if ($strFileType == ".php")  
     1782                if ($strFileType == ".php") 
    18061783                        return "text/php"; 
    1807                 if ($strFileType == ".asp")  
     1784                if ($strFileType == ".asp") 
    18081785                        return "text/asp"; 
    18091786                if ($strFileType == ".pdf") 
     
    18331810                if ($strFileType == ".stw") 
    18341811                        return "application/vnd.sun.xml.writer.template"; 
    1835                  
    1836                  
    1837                 return "application/octet-stream";               
    1838         } 
    1839          
     1812 
     1813 
     1814                return "application/octet-stream"; 
     1815        } 
     1816 
    18401817        function htmlspecialchars_encode($str) 
    18411818        { 
    1842                 return  str_replace( array('&', '"','\'','<','>','{','}'), array('&amp;','&quot;','&#039;','&lt;','&gt;','&#123;','&#125;'), $str); 
     1819                /*// replace  '  and  "  with htmlspecialchars */ 
     1820                $str = ereg_replace('&', '&amp;', $str); 
     1821                // any ampersand & that ia already in a "&amp;" should NOT be encoded 
     1822                //$str = preg_replace("/&(?![:alnum:]*;)/", "&amp;", $str); 
     1823                $str = ereg_replace('"', '&quot;', $str); 
     1824                $str = ereg_replace('\'', '&#039;', $str); 
     1825 
     1826                $str = ereg_replace('<', '&lt;', $str); 
     1827                $str = ereg_replace('>', '&gt;', $str); 
     1828                // these {  and  }  must be html encoded or else they conflict with the template system 
     1829                $str = str_replace("{", '&#123;', $str); 
     1830                $str = str_replace("}", '&#125;', $str); 
     1831                return $str; 
    18431832        } 
    18441833        function htmlspecialchars_decode($str) 
    18451834        { 
    1846                 return  str_replace( array('&amp;','&quot;','&#039;','&lt;','&gt;','&#123;','&#125;'), array('&', '"','\'','<','>','{','}'), $str); 
    1847         } 
    1848          
     1835                /*// replace  '  and  "  with htmlspecialchars */ 
     1836                $str = ereg_replace('&amp;','&',  $str); 
     1837                // any ampersand & that ia already in a "&amp;" should NOT be encoded 
     1838                //$str = preg_replace("/&(?![:alnum:]*;)/", "&amp;", $str); 
     1839                $str = ereg_replace('&quot;', '"', $str); 
     1840                $str = ereg_replace('&#039;', '\'', $str); 
     1841                $str = ereg_replace('&lt;','<', $str); 
     1842                $str = ereg_replace('&gt;', '>', $str); 
     1843                // these {  and  }  must be html encoded or else they conflict with the template system 
     1844                $str = str_replace('&#123;', "{", $str); 
     1845                $str = str_replace( '&#125;',"}", $str); 
     1846                return $str; 
     1847        } 
     1848 
    18491849        function get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse){ 
    1850                  
     1850 
    18511851                if(!$this->mbox || !is_resource($this->mbox)){ 
    18521852                        $this->mbox = $this->open_mbox($folder); 
    18531853                } 
     1854 
    18541855                switch($sort_box_type){ 
    18551856                        case 'SORTFROM': 
    1856                                 return $this->imap_sortfrom($sort_box_reverse, $search_box_type);                                
     1857                                return $this->imap_sortfrom($sort_box_reverse, $search_box_type); 
    18571858                        case 'SORTSUBJECT': 
    1858                                 return imap_sort($this->mbox, SORTSUBJECT, $sort_box_reverse, SE_UID, $search_box_type);                                 
     1859                                return imap_sort($this->mbox, SORTSUBJECT, $sort_box_reverse, SE_UID, $search_box_type); 
    18591860                        case 'SORTSIZE': 
    1860                                 return imap_sort($this->mbox, SORTSIZE, $sort_box_reverse, SE_UID, $search_box_type);                            
     1861                                return imap_sort($this->mbox, SORTSIZE, $sort_box_reverse, SE_UID, $search_box_type); 
    18611862                        default: 
    1862                                 return imap_sort($this->mbox, SORTARRIVAL, $sort_box_reverse, SE_UID, $search_box_type);                                                 
    1863                 }                
    1864         }        
    1865          
     1863                                return imap_sort($this->mbox, SORTARRIVAL, $sort_box_reverse, SE_UID, $search_box_type); 
     1864                } 
     1865        } 
     1866 
    18661867        function get_info_next_msg($params) 
    18671868        { 
     
    18721873                $reuse_border = $params['reuse_border']; 
    18731874                $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 
    1874                 $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse);                               
    1875                  
     1875                $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); 
     1876 
    18761877                $success = false; 
    18771878                if (is_array($sort_array_msg)) 
     
    18921893                        return $params; 
    18931894                } 
    1894                  
     1895 
    18951896                $params = array(); 
    18961897                $params['msg_number'] = $sort_array_msg[($i+1)]; 
    18971898                $params['msg_folder'] = $folder; 
    1898                  
    1899                 $return = $this->get_info_msg($params);          
     1899 
     1900                $return = $this->get_info_msg($params); 
    19001901                $return["reuse_border"] = $reuse_border; 
    19011902                return $return; 
     
    19111912                $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 
    19121913                $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); 
    1913                  
     1914 
    19141915                $success = false; 
    19151916                if (is_array($sort_array_msg)) 
     
    19291930                        return $params; 
    19301931                } 
    1931                  
     1932 
    19321933                $params = array(); 
    19331934                $params['msg_number'] = $sort_array_msg[($i-1)]; 
    19341935                $params['msg_folder'] = $folder; 
    1935                  
     1936 
    19361937                $return = $this->get_info_msg($params); 
    19371938                $return["reuse_border"] = $reuse_border; 
    19381939                return $return; 
    19391940        } 
    1940          
     1941 
    19411942        // This function updates the values: quota, paging and new messages menu. 
    19421943        function get_menu_values($params){ 
    19431944                $return_array = array(); 
    19441945                $return_array = $this->get_quota($params); 
    1945                  
     1946 
    19461947                $mbox_stream = $this->open_mbox($params['folder']); 
    1947                 $return_array['num_msgs'] = imap_num_msg($mbox_stream);          
     1948                $return_array['num_msgs'] = imap_num_msg($mbox_stream); 
    19481949                if($mbox_stream) 
    19491950                        imap_close($mbox_stream); 
    1950                                  
    1951                 return $return_array;  
    1952         } 
    1953          
     1951 
     1952                return $return_array; 
     1953        } 
     1954 
    19541955        function get_quota($params){ 
    1955                 // folder_id = user/{uid} for shared folders 
    1956                 if(substr($params['folder_id'],0,5) != 'INBOX' && preg_match('/user\\'.$this->imap_delimiter.'/i', $params['folder_id'])){ 
    1957                         $array_folder =  explode($this->imap_delimiter,$params['folder_id']); 
    1958                         $folder_id = "user".$this->imap_delimiter.$array_folder[1];              
    1959                 } 
    1960                 // folder_id = INBOX for inbox folders 
    1961                 else 
    1962                         $folder_id = "INBOX"; 
    1963                  
     1956                $folder_id = $params['folder_id']; 
    19641957                if(!$this->mbox || !is_resource($this->mbox)) 
    19651958                        $this->mbox = $this->open_mbox(); 
     
    19681961                if($this->mbox && is_resource($this->mbox)) 
    19691962                        imap_close($this->mbox); 
    1970                          
     1963 
    19711964                if (!$quota){ 
    19721965                        return array( 
     
    19761969                        ); 
    19771970                } 
    1978                  
     1971 
    19791972                if(count($quota) && $quota['limit']) { 
    19801973                        $quota_limit = (($quota['limit']/1024)* 100 + .5 )* .01; 
     
    19911984                        ); 
    19921985                } 
    1993                 else  
     1986                else 
    19941987                        return array(); 
    19951988        } 
    1996          
     1989 
    19971990        function send_notification($params){ 
    19981991                require_once("class.phpmailer.php"); 
    19991992                $mail = new PHPMailer(); 
    2000                   
     1993 
    20011994                $toaddress = $params['notificationto']; 
    2002                  
    2003                 $subject = 'Confirmaᅵᅵo de leitura: ' . $params['subject']; 
     1995 
     1996                $subject = 'Leitura confirmada da mensagem: ' . $params['subject']; 
    20041997                $body = 'Sua mensagem: ' . $params['subject'] . '<br>'; 
    20051998                $body .= 'foi lida por: ' . $_SESSION['phpgw_info']['expressomail']['user']['fullname'] . ' &lt;' . $_SESSION['phpgw_info']['expressomail']['user']['email'] . '&gt; em ' . date("d/m/Y H:i"); 
     
    20152008                $mail->IsHTML(true); 
    20162009                $mail->Body = $body; 
    2017                  
     2010 
    20182011                if(!$mail->Send()){ 
    20192012                        return $mail->ErrorInfo; 
     
    20222015                        return true; 
    20232016        } 
    2024          
     2017 
    20252018        function empty_trash() 
    20262019        { 
    2027                 $folder = 'INBOX' . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'];  
     2020                $folder = 'INBOX' . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']; 
    20282021                $mbox_stream = $this->open_mbox($folder); 
    20292022                $return = imap_delete($mbox_stream,'1:*'); 
     
    20322025                return $return; 
    20332026        } 
    2034          
     2027 
    20352028        function search($params) 
    20362029        { 
    20372030                include("class.imap_attachment.inc.php"); 
    2038                 $imap_attachment = new imap_attachment();                                
     2031                $imap_attachment = new imap_attachment(); 
    20392032                $criteria = $params['criteria']; 
    20402033                $return = array(); 
    20412034                $folders = $this->get_folders_list(); 
    2042                  
     2035 
    20432036                $j = 0; 
    20442037                foreach($folders as $folder) 
     
    20462039                        $mbox_stream = $this->open_mbox($folder); 
    20472040                        $messages = imap_search($mbox_stream, $criteria, SE_UID); 
    2048                          
     2041 
    20492042                        if ($messages == '') 
    20502043                                continue; 
    2051                  
     2044 
    20522045                        $i = 0; 
    20532046                        $return[$j] = array(); 
    20542047                        $return[$j]['folder_name'] = $folder['name']; 
    2055                          
     2048 
    20562049                        foreach($messages as $msg_number) 
    20572050                        { 
     
    20592052                                if (!is_object($header)) 
    20602053                                        return false; 
    2061                                  
     2054 
    20622055                                $return[$j][$i]['msg_folder']   = $folder['name']; 
    20632056                                $return[$j][$i]['msg_number']   = $msg_number; 
     
    20682061                                $return[$j][$i]['Draft']                = $header->Draft; 
    20692062                                $return[$j][$i]['Flagged']              = $header->Flagged; 
    2070          
     2063 
    20712064                                $date_msg = date("d/m/Y",$header->udate); 
    20722065                                if (date("d/m/Y") == $date_msg) 
     
    20742067                                else 
    20752068                                        $return[$j][$i]['udate'] = $date_msg; 
    2076                          
     2069 
    20772070                                $fromaddress = imap_mime_header_decode($header->fromaddress); 
    20782071                                $return[$j][$i]['fromaddress'] = ''; 
    20792072                                foreach ($fromaddress as $tmp) 
    20802073                                        $return[$j][$i]['fromaddress'] .= $this->replace_maior_menor($tmp->text); 
    2081                          
     2074 
    20822075                                $from = $header->from; 
    20832076                                $return[$j][$i]['from'] = array(); 
     
    20852078                                $return[$j][$i]['from']['name'] = $tmp[0]->text; 
    20862079                                $return[$j][$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; 
    2087                                 $return[$j][$i]['from']['full'] ='"' . $return[$j][$i]['from']['name'] . '" ' . '<' . $return[$j][$i]['from']['email'] . '>';  
     2080                                $return[$j][$i]['from']['full'] ='"' . $return[$j][$i]['from']['name'] . '" ' . '<' . $return[$j][$i]['from']['email'] . '>'; 
    20882081 
    20892082                                $to = $header->to; 
     
    20922085                                $return[$j][$i]['to']['name'] = $tmp[0]->text; 
    20932086                                $return[$j][$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; 
    2094                                 $return[$j][$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>';  
     2087                                $return[$j][$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; 
    20952088 
    20962089                                $subject = imap_mime_header_decode($header->fetchsubject); 
     
    21012094                                $return[$j][$i]['Size'] = $header->Size; 
    21022095                                $return[$j][$i]['reply_toaddress'] = $header->reply_toaddress; 
    2103                          
     2096 
    21042097                                $return[$j][$i]['attachment'] = array(); 
    21052098                                $return[$j][$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($mbox_stream, $msg_number); 
    2106                                                  
     2099 
    21072100                                $i++; 
    21082101                        } 
     
    21112104                                imap_close($mbox_stream); 
    21122105                } 
    2113          
     2106 
    21142107                return $return; 
    21152108        } 
    2116          
     2109 
    21172110        function delete_and_show_previous_message($params) 
    21182111        { 
    21192112                $return = $this->get_info_previous_msg($params); 
    2120                  
     2113 
    21212114                $params_tmp1 = array(); 
    21222115                $params_tmp1['msgs_to_delete'] = $params['msg_number']; 
    21232116                $params_tmp1['folder'] = $params['msg_folder']; 
    21242117                $return_tmp1 = $this->delete_msg($params_tmp1); 
    2125                  
     2118 
    21262119                $return['msg_number_deleted'] = $return_tmp1; 
    2127                  
     2120 
    21282121                return $return; 
    21292122        } 
    2130                  
    2131          
     2123 
     2124 
    21322125        function automatic_trash_cleanness($params) 
    21332126        { 
     
    21472140//      Fix the search problem with special characters!!!! 
    21482141        function remove_accents($string) { 
    2149                 return strtr($string,  
    2150                 "?ï¿œ??ï¿œ?ï¿œ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵ",  
     2142                return strtr($string, 
     2143                "?ï¿œ??ï¿œ?ï¿œ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵ", 
    21512144                "SOZsozYYuAAAAACEEEEIIIIINOOOOOUUUUUsaaaaaceeeeiiiiinooooouuuuuyy"); 
    21522145        } 
    21532146 
    21542147        function search_msg($params = ''){ 
     2148                $this->ldap = new ldap_functions(); 
    21552149                $retorno = ""; 
    21562150                $mbox_stream = ""; 
     
    21712165                                                $filter .= '"'.$filter_array[1].'"'; 
    21722166                                        } 
    2173                                 }                
    2174                                 $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" );  
     2167                                } 
     2168                                $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 
    21752169                                $filter = $this->remove_accents($filter); 
    2176                                  
     2170                                $folder_name = explode($this->imap_delimiter,$name_box); 
     2171                                if (is_numeric($folder_name[1])) 
     2172                                { 
     2173                                        if ($cn = $this->ldap->uid2cn($folder_name[1])) 
     2174                                        { 
     2175                                        $folder_name[1] = $cn;   
     2176                                        } 
     2177                                } 
     2178                                $folder_name = implode($this->imap_delimiter,$folder_name); 
     2179 
    21772180                                if(!is_resource($mbox_stream)) 
    21782181                                        $mbox_stream = $this->open_mbox($name_box); 
    21792182                                else 
    21802183                                        imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); 
    2181                          
    2182                                 if (preg_match("/^.?\bALL\b/", $filter)){ // Quick Search, note: this ALL isn't the same ALL from imap_search    
    2183                                  
     2184 
     2185                                if (preg_match("/^.?\bALL\b/", $filter)){ // Quick Search, note: this ALL isn't the same ALL from imap_search 
     2186 
    21842187                                        $all_criterias = array ("TO","SUBJECT","FROM","CC"); 
    21852188                                        foreach($all_criterias as $criteria_fixed) 
    21862189                                        { 
    21872190                                                $_filter = $criteria_fixed . substr($filter,4); 
    2188                                          
     2191 
    21892192                                                $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); 
    2190                                                  
     2193 
    21912194                                                if($search_criteria && count($search_criteria) < 50) 
    21922195                                                { 
    21932196                                                        foreach($search_criteria as $new_search){ 
    2194                                                                 $m_token = trim("##".mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--".$new_search."##"."\n"); 
     2197                                                                $m_token = trim("##".mb_convert_encoding( $folder_name, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--".$new_search."##"."\n"); 
    21952198                                                                if(!@strstr($retorno,$m_token)) 
    21962199                                                                        $retorno .= $m_token; 
    21972200                                                        } 
    2198                                                 }                                                
    2199                                                 else if(count($search_criteria) >= 50)                                                   
    2200                                                         return "many results";                                           
     2201                                                } 
     2202                                                else if(count($search_criteria) >= 50) 
     2203                                                        return "many results"; 
    22012204                                        } 
    22022205                                } 
     
    22062209                                        { 
    22072210                                                foreach($search_criteria as $new_search) 
    2208                                                         $retorno .= trim("##".mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--" . $new_search."##"."\n"); 
     2211                                                        $retorno .= trim("##".mb_convert_encoding( $folder_name, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--" . $new_search."##"."\n"); 
    22092212                                        } 
    22102213                                } 
     
    22122215                } 
    22132216                if($mbox_stream) 
    2214                         imap_close($mbox_stream);                
    2215                                                  
     2217                        imap_close($mbox_stream); 
     2218 
    22162219                return $retorno ? $retorno : "none"; 
    22172220        } 
    2218          
     2221 
    22192222        function get_msg($uid_msg,$name_box, $mbox_stream ) 
    22202223        { 
    2221                 $header = @imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $uid_msg), 80, 255);          
     2224                $header = @imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $uid_msg), 80, 255); 
    22222225                $subject = $this->decode_string($header->fetchsubject); 
    22232226                $from = $header->from[0]->mailbox; 
    22242227                if($header->from[0]->personal != "") 
    22252228                        $from = $header->from[0]->personal; 
    2226                 $ret_msg = $this->decode_string($from) . "--" . $subject . "--". date("d/m/Y",$header ->udate)."--". $this->size_msg($header->Size); 
    2227                 return $ret_msg;                     
    2228         }        
    2229          
     2229                $ret_msg = $this->decode_string($from) . "--" . $subject . "--". date("d/m/Y",$header ->udate)."--". $this->size_msg($header->Size). "--". $header->Unseen; 
     2230                return $ret_msg; 
     2231        } 
     2232 
    22302233        function size_msg($size){ 
    22312234                $var = floor($size/1024); 
    22322235                if($var >= 1){ 
    2233                         return $var." kb";       
     2236                        return $var." kb"; 
    22342237                }else{ 
    2235                         return $size ." b";      
     2238                        return $size ." b"; 
    22362239                } 
    22372240        } 
     
    22602263           } 
    22612264        } 
    2262          
     2265 
    22632266        function getacl() 
    22642267        { 
    22652268                $this->ldap = new ldap_functions(); 
    2266                  
     2269 
    22672270                $return = array(); 
    2268                 $mbox_stream = $this->open_mbox();       
     2271                $mbox_stream = $this->open_mbox(); 
    22692272                $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); 
    2270                  
     2273 
    22712274                $i = 0; 
    22722275                foreach ($mbox_acl as $user => $acl) 
     
    22812284                return $return; 
    22822285        } 
    2283          
     2286 
    22842287        function setacl($params) 
    22852288        { 
     
    22872290                if (!count($old_users)) 
    22882291                        $old_users = array(); 
    2289                  
     2292 
    22902293                $tmp_array = array(); 
    22912294                foreach ($old_users as $index => $user_info) 
     
    22942297                } 
    22952298                $old_users = $tmp_array; 
    2296                  
     2299 
    22972300                $users = unserialize($params['users']); 
    22982301                if (!count($users)) 
    22992302                        $users = array(); 
    2300                  
     2303 
    23012304                //$add_share = array_diff($users, $old_users); 
    23022305                $remove_share = array_diff($old_users, $users); 
     
    23212324                        } 
    23222325                }*/ 
    2323                  
     2326 
    23242327                if (count($remove_share)) 
    23252328                { 
     
    23342337                        } 
    23352338                        } 
    2336                         }        
    2337                 } 
    2338                  
     2339                        } 
     2340                } 
     2341 
    23392342                return true; 
    23402343        } 
    2341          
     2344 
    23422345        function getaclfromuser($params) 
    23432346        { 
    23442347                $useracl = $params['user']; 
    2345                  
     2348 
    23462349                $return = array(); 
    23472350                $return[$useracl] = 'false'; 
    2348                 $mbox_stream = $this->open_mbox();       
     2351                $mbox_stream = $this->open_mbox(); 
    23492352                $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); 
    2350                  
     2353 
    23512354                foreach ($mbox_acl as $user => $acl) 
    23522355                { 
     
    23672370                //No caso de se tratar da caixa do proprio usuario logado, utiliza a sintaxe abaixo 
    23682371                if(substr($user,0,4) != 'user') 
    2369                 $mbox_acl = imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); 
     2372                  $mbox_acl = imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); 
    23702373                else 
    23712374                  $mbox_acl = imap_getacl($mbox_stream, $user); 
    23722375                return $mbox_acl[$this->username]; 
    23732376        } 
    2374          
     2377 
    23752378 
    23762379        function setaclfromuser($params) 
     
    23782381                $user = $params['user']; 
    23792382                $acl = $params['acl']; 
    2380                  
     2383 
    23812384                $mbox_stream = $this->open_mbox(); 
    23822385 
     
    23882391                        foreach ($mailboxes_list as $key => $val) 
    23892392                        { 
    2390                                 $folder = str_replace($serverString, "", imap_utf7_encode($val->name)); 
    2391                                 $folder = str_replace("&-", "&", $folder); 
     2393                                $folder = str_replace($serverString, "", imap_utf7_decode($val->name)); 
    23922394                                if (!imap_setacl ($mbox_stream, $folder, $user, $acl)) 
    23932395                                { 
    2394                                         $return = imap_last_error(); 
    2395                                 } 
    2396                         } 
    2397                 } 
    2398                 if (isset($return)) 
    2399                         return $return; 
    2400                 else 
    2401                         return true; 
    2402         } 
    2403          
     2396                                        return imap_last_error(); 
     2397                                } 
     2398                        } 
     2399                } 
     2400 
     2401                return true; 
     2402        } 
     2403 
    24042404        function download_attachment($msg,$msgno) 
    24052405        { 
    2406                 $array_parts_attachments = array();              
     2406                $array_parts_attachments = array(); 
    24072407                $array_parts_attachments['names'] = ''; 
    24082408                include("class.imap_attachment.inc.php"); 
    2409                 $imap_attachment = new imap_attachment();                
    2410                  
     2409                $imap_attachment = new imap_attachment(); 
     2410 
    24112411                if (count($msg->fname[$msgno]) > 0) 
    24122412                { 
     
    24252425                $array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2)); 
    24262426                return $array_parts_attachments; 
    2427         }        
     2427        } 
    24282428 
    24292429        function spam($params) 
     
    24392439                        $msg = $header . $body; 
    24402440                        $email = $_SESSION['phpgw_info']['expressomail']['user']['email']; 
    2441                         $username = $this->username; 
     2441                        //$tmp_file = $tmp_dir . "msg." . $email . '.'. $msg_number . time(); 
     2442                        // maybe we can get it faster with regex, don't know how :'( 
     2443                        $signature = trim(substr($header, strpos($header, 'X-DSPAM-Signature:') + 18)); 
    24422444                        strtok($email, '@'); 
    24432445                        $domain = strtok('@'); 
    24442446 
    2445                         //Encontrar a assinatura do dspam no cabecalho 
    2446                         $v = explode("\r\n", $header); 
    2447                         foreach ($v as $linha){ 
    2448                                 if (eregi("^X-DSPAM-Signature", $linha)) { 
    2449                                          
    2450                                         $args = explode(" ",$linha); 
    2451                                         $signature = $args[1]; 
    2452                                 } 
    2453                         } 
    2454  
    24552447                        // feed dspam 
    2456                         switch($is_spam){ 
    2457                                 case 'true':  $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam']; break; 
    2458                                 case 'false': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham']; break; 
    2459                         } 
    2460                         $tags = array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##'); 
    2461                         $cmd = str_replace($tags,array($email,$username,$domain,$signature),$cmd); 
     2448                        if ($is_spam) 
     2449                                $cmd = str_replace( 
     2450                                                        array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##'), 
     2451                                                        array($email, $this->username, $domain, $signature), $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam'] 
     2452                                                ); 
     2453                        else 
     2454                                $cmd = str_replace( 
     2455                                                        array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##'), 
     2456                                                array($email, $this->username, $domain, $signature), $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham'] 
     2457                                        ); 
     2458 
    24622459                        system($cmd); 
     2460 
    24632461                } 
    24642462                imap_close($mbox_stream); 
  • trunk/phpgwapi/inc/functions.inc.php

    r411 r432  
    2222         * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            * 
    2323         \**************************************************************************/ 
    24          
    25          
     24 
     25 
    2626        /***************************************************************************\ 
    2727        * If running in PHP3, then force admin to upgrade                           * 
     
    3838 
    3939        include(PHPGW_API_INC.'/common_functions.inc.php'); 
    40          
     40 
    4141        /*! 
    4242         @function lang 
     
    5353                        $vars = array($m1,$m2,$m3,$m4,$m5,$m6,$m7,$m8,$m9,$m10); 
    5454                } 
    55                 // Get the translation from Lang File, if the database is down. 
    56                 if(!$GLOBALS['phpgw']->translation){ 
    57                         $fn = PHPGW_SERVER_ROOT.'/phpgwapi/setup/phpgw_'.$GLOBALS['_SERVER']['HTTP_ACCEPT_LANGUAGE'].'.lang'; 
    58                         if (file_exists($fn)){ 
    59                                 $fp = fopen($fn,'r'); 
    60                                 while ($data = fgets($fp,16000)){ 
    61                                         list($message_id,$app_name,$null,$content) = explode("\t",substr($data,0,-1)); 
    62                                         $GLOBALS['phpgw_info']['phpgwapi']['lang'][$message_id] =  $content; 
    63                                 } 
    64                                 fclose($fp); 
    65                         } 
    66                         $return = str_replace('%1',$vars[0],$GLOBALS['phpgw_info']['phpgwapi']['lang'][$key]);                   
    67                         return $return;   
    68                 } 
    6955                $value = $GLOBALS['phpgw']->translation->translate("$key",$vars); 
    7056                return $value; 
     
    9480        * Multi-Domain support                                                       * 
    9581        \****************************************************************************/ 
    96          
     82 
    9783        /* make them fix their header */ 
    9884        if (!isset($GLOBALS['phpgw_domain'])) 
     
    162148        } 
    163149        $GLOBALS['phpgw']->db->Halt_On_Error = 'no'; 
    164         /* jakjr: ExpressoLivre: We do not count the config table. */ 
    165         if (! 
    166150        $GLOBALS['phpgw']->db->connect( 
    167151                $GLOBALS['phpgw_info']['server']['db_name'], 
     
    171155                $GLOBALS['phpgw_info']['server']['db_pass'], 
    172156                $GLOBALS['phpgw_info']['server']['db_type'] 
    173         ) ) 
    174         //@$GLOBALS['phpgw']->db->query("SELECT COUNT(config_name) FROM phpgw_config"); 
    175         //if(!@$GLOBALS['phpgw']->db->next_record()) 
    176         { 
    177                  
     157        ); 
     158        @$GLOBALS['phpgw']->db->query("SELECT COUNT(config_name) FROM phpgw_config"); 
     159        if(!@$GLOBALS['phpgw']->db->next_record()) 
     160        { 
     161                $setup_dir = str_replace($_SERVER['PHP_SELF'],'index.php','setup/'); 
    178162                /* BEGIN - CELEPAR - jakjr - 05/06/2006 */ 
    179                 /* $setup_dir = str_replace($_SERVER['PHP_SELF'],'index.php','setup/'); */ 
    180163                /*echo '<center><b>Fatal Error:</b> It appears that you have not created the database tables for ' 
    181164                        .'eGroupWare.  Click <a href="' . $setup_dir . '">here</a> to run setup.</center>';*/ 
    182                 echo '<center><b>'.lang("ExpressoLivre is unavailable at this moment. Code %1<br>Please, try later.","001").'</b></center>'; 
     165                echo '<center><b>ExpressoLivre indisponível no momento. Códgio 001<br>' . 
     166                         'Tente mais tarde.</b></center>'; 
    183167                /* END - CELEPAR - jakjr - 05/06/2006 */ 
    184168                exit; 
     
    188172        /* Fill phpgw_info["server"] array */ 
    189173        // An Attempt to speed things up using cache premise 
    190         /* jakjr: ExpressoLivre does not use cache. */ 
    191         /* 
    192174        $GLOBALS['phpgw']->db->query("select config_value from phpgw_config WHERE config_app='phpgwapi' and config_name='cache_phpgw_info'",__LINE__,__FILE__); 
    193175        if ($GLOBALS['phpgw']->db->num_rows()) 
     
    195177                $GLOBALS['phpgw']->db->next_record(); 
    196178                $GLOBALS['phpgw_info']['server']['cache_phpgw_info'] = stripslashes($GLOBALS['phpgw']->db->f('config_value')); 
    197         }*/ 
    198  
    199         /* jakjr: ExpressoLivre does not use cache. */ 
    200         /*       
     179        } 
     180 
    201181        $cache_query = "select content from phpgw_app_sessions where" 
    202182                ." sessionid = '0' and loginid = '0' and app = 'phpgwapi' and location = 'config'"; 
     
    204184        $GLOBALS['phpgw']->db->query($cache_query,__LINE__,__FILE__); 
    205185        $server_info_cache = $GLOBALS['phpgw']->db->num_rows(); 
    206         */ 
    207         /* 
     186 
    208187        if(@$GLOBALS['phpgw_info']['server']['cache_phpgw_info'] && $server_info_cache) 
    209188        { 
     
    212191        } 
    213192        else 
    214         {*/ 
    215                 $GLOBALS['phpgw']->db->query("SELECT * from phpgw_config WHERE config_app='phpgwapi'",__LINE__,__FILE__); 
     193        { 
     194                $GLOBALS['phpgw']->db->query("select * from phpgw_config WHERE config_app='phpgwapi'",__LINE__,__FILE__); 
    216195                while ($GLOBALS['phpgw']->db->next_record()) 
    217196                { 
     
    219198                } 
    220199 
    221                 /* 
    222200                if(@isset($GLOBALS['phpgw_info']['server']['cache_phpgw_info'])) 
    223201                { 
     
    230208                                . "'0','0','phpgwapi','config','".addslashes(serialize($GLOBALS['phpgw_info']['server']))."')"; 
    231209                        $GLOBALS['phpgw']->db->query($cache_query,__LINE__,__FILE__); 
    232                 }*/ 
    233         //} 
     210                } 
     211        } 
    234212        unset($cache_query); 
    235213        unset($server_info_cache); 
     
    476454                } 
    477455                $GLOBALS['phpgw']->applications->read_installed_apps(); // to get translated app-titles 
    478                  
     456 
    479457                /*************************************************************************\ 
    480458                * Load the header unless the developer turns it off                       * 
Note: See TracChangeset for help on using the changeset viewer.