Changeset 449


Ignore:
Timestamp:
09/18/08 17:08:34 (16 years ago)
Author:
niltonneto
Message:

Alterações revertidas devido ao commit R.432 feito de forma incorreta.

Ocorrências fechadas
#281 - Erro na hora de salvar emails com imagens de outros emails
#325 - Problema ao encaminhar mensagens com anexos formato TXT
#326 - Incluir o campo CCo na cópia da mensagem enviada.
#330 - Problema nos Hyperlinks em mensagens recebidas

File:
1 edited

Legend:

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

    r432 r449  
    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  
    157  
    158                 //if(!$this->mbox) 
    159                 //      $this->mbox = $this->open_mbox($msg_folder); 
    160  
     155                        $this->mbox = $this->open_mbox($msg_folder);             
     156                 
    161157                $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); 
    162158                if (!$header) { 
     
    166162                $all_header = explode("\n", imap_fetchheader($this->mbox, $msg_number, FT_UID)); 
    167163                $return_get_body = $this->get_body_msg($msg_number, $msg_folder); 
    168  
     164                 
    169165                $return['body']                 = $return_get_body['body']; 
    170166                $return['attachments']  = $return_get_body['attachments']; 
    171167                $return['thumbs']               = $return_get_body['thumbs']; 
    172168                $return['signature']    = $return_get_body['signature']; 
    173  
     169                 
    174170                foreach($all_header as $line) { 
    175171                        if (eregi("^Disposition-Notification-To", $line)) { 
     
    180176                $return['Recent']       = $header->Recent; 
    181177                $return['Unseen']       = $header->Unseen; 
    182                 $return['Deleted']      = $header->Deleted; 
     178                $return['Deleted']      = $header->Deleted;              
    183179                $return['Flagged']      = $header->Flagged; 
    184180 
     
    188184                else { 
    189185                        $return['Answered']     = $header->Answered; 
    190                         $return['Draft']        = $header->Draft; 
     186                        $return['Draft']        = $header->Draft;        
    191187                } 
    192188 
    193189                $return['msg_number'] = $msg_number; 
    194190                $return['msg_folder'] = $msg_folder; 
    195  
     191         
    196192                $date_msg = date("d/m/Y",$header->udate); 
    197193                if (date("d/m/Y") == $date_msg) 
     
    199195                else 
    200196                        $return['udate'] = $date_msg; 
    201  
    202                 $return['msg_day'] = $date_msg; 
     197                 
     198                $return['msg_day'] = $date_msg;  
    203199                $return['msg_hour'] = date("H:i",$header->udate); 
    204  
     200                 
    205201                if (date("d/m/Y") == $date_msg) //no dia 
    206202                { 
    207203                        $return['fulldate'] = date("d/m/Y H:i",$header->udate); 
    208204                        $return['smalldate'] = date("H:i",$header->udate); 
    209  
     205                         
    210206                        $timestamp_now = strtotime("now"); 
    211207                        $timestamp_msg_time = $header->udate; 
    212208                        $timestamp_diff = $timestamp_now - $timestamp_msg_time; 
    213  
     209                         
    214210                        if (gmdate("H",$timestamp_diff) > 0) 
    215211                        { 
     
    233229                        $return['smalldate'] = date("d/m/Y",$header->udate); 
    234230                } 
    235  
     231                 
    236232                $from = $header->from; 
    237233                $return['from'] = array(); 
     
    248244                else 
    249245                        $return['from']['full'] = $return['from']['email']; 
    250  
     246                 
    251247                // Sender attribute 
    252248                $sender = $header->sender; 
     
    300296                { 
    301297                        $return['toaddress2'] = "&lt;Empty&gt;"; 
    302                 } 
    303  
     298                }        
     299                 
    304300                $cc = $header->cc; 
    305301                $return['cc'] = ""; 
     
    329325                { 
    330326                        $return['cc'] = ""; 
    331                 } 
     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                }        
    332362 
    333363                $reply_to = $header->reply_to; 
     
    361391                $return['Size'] = $header->Size; 
    362392                $return['reply_toaddress'] = $header->reply_toaddress; 
    363  
     393                 
    364394                return $return; 
    365395        } 
    366  
     396         
    367397        function get_body_msg($msg_number, $msg_folder) 
    368398        { 
     
    371401                $msg->fetch_structure($msg_number); 
    372402                $return = array(); 
    373                 $return['attachments'] = $this-> download_attachment($msg,$msg_number); 
     403                $return['attachments'] = $this-> download_attachment($msg,$msg_number);          
    374404                if(!$this->has_cid) 
    375405                { 
    376406                        $return['thumbs']  = $this->get_thumbs($msg,$msg_number,urlencode($msg_folder)); 
    377407                        $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); 
    378                 } 
    379  
     408                }                        
     409                 
    380410                if(!$msg->structure[$msg_number]->parts) //Simple message, only 1 piece 
    381411                { 
    382412                        $attachment = array(); //No attachments 
    383  
     413                         
    384414                        $content = ''; 
    385415                        if (strtolower($msg->structure[$msg_number]->subtype) == "plain") 
     
    392422                        } 
    393423                } 
    394                 else 
     424                else  
    395425                { //Complicated message, multiple parts 
    396426                        $html_body = ''; 
     
    398428                        $has_multipart = true; 
    399429                        $this->has_cid = false; 
    400  
     430                         
    401431                        if (strtolower($msg->structure[$msg_number]->subtype) == "related") 
    402432                                $this->has_cid = true; 
    403  
     433                         
    404434                        if (strtolower($msg->structure[$msg_number]->subtype) == "alternative") 
    405435                        { 
     
    409439                                        $file_type = strtolower($msg->file_type[$msg_number][$values]); 
    410440                                        if($file_type == "text/html") 
    411                                                 $show_only_html = true; 
     441                                $show_only_html = true;                  
    412442                                } 
    413443                        } 
     
    417447                        foreach($msg->pid[$msg_number] as $values => $msg_part) 
    418448                        { 
    419  
     449                                 
    420450                                $file_type = strtolower($msg->file_type[$msg_number][$values]); 
    421451                                if($file_type == "message/rfc822") 
    422452                                        $has_multipart = false; 
    423  
     453         
    424454                                if($file_type == "multipart/alternative") 
    425455                                        $has_multipart = false; 
    426  
    427                                 if(($file_type == "text/plain" 
     456         
     457                                if(($file_type == "text/plain"  
    428458                                        || $file_type == "text/html") 
    429459                                        && $file_type != 'attachment') 
     
    433463                                                // if TXT file size > 100kb, then it will not expand. 
    434464                                                if(!($file_type == "text/plain" && $msg->fsize[$msg_number][$values] > 102400)) { 
    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]))); 
     465                                                        $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])));                                                      
    436466                                                } 
    437467                                        } 
    438468                                        // if HTML attachment file size > 300kb, then it will not expand. 
    439                                         else if($file_type == "text/html"  && $msg->fsize[$msg_number][$values] < 3072000) 
     469                                        else if($file_type == "text/html"  && $msg->fsize[$msg_number][$values] < 307200) 
    440470                                        { 
    441471                                                $content .= $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]); 
     
    445475                                else if($file_type == "message/delivery-status"){ 
    446476                                        $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 
    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])); 
     477                                        $content .= nl2br($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]));                                            
    448478 
    449479                                } 
    450480                                else if($file_type == "message/rfc822" || $file_type == "text/rfc822-headers"){ 
    451  
     481                                         
    452482                                        include_once("class.imap_attachment.inc.php"); 
    453483                                        $att = new imap_attachment(); 
    454484                                        $attachments =  $att -> get_attachment_info($this->mbox,$msg_number); 
    455                                         if($attachments['number_attachments'] > 0) { 
     485                                        if($attachments['number_attachments'] > 0) {                                                                                             
    456486                                                foreach($attachments ['attachment'] as $index => $attachment){ 
    457487                                                        if(strtolower($attachment['type']) == "delivery-status" || 
    458                                                                 strtolower($attachment['type']) == "rfc822" || 
     488                                                                strtolower($attachment['type']) == "rfc822" ||                                                           
    459489                                                                strtolower($attachment['type']) == "rfc822-headers" || 
    460490                                                                strtolower($attachment['type']) == "plain" 
    461491                                                        ){ 
    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'>"; 
     492                                                                $obj = imap_rfc822_parse_headers(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values]);                                     
     493                                                                $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>";                                    
    464494                                                                $content .= "<br><table  style='margin:2px;border:1px solid black;background:#EAEAEA'>"; 
    465495                                                                $content .= "<tr><td><b>".$this->functions->getLang("Subject").":</b></td><td>".$this->decode_string($obj->subject)."</td></tr>"; 
     
    467497                                                                $content .= "<tr><td><b>".$this->functions->getLang("Date").":</b></td><td>".$obj->date."</td></tr>"; 
    468498                                                                $content .= "<tr><td><b>".$this->functions->getLang("TO").":</b></td><td>".$this->decode_string($obj->to[0]->mailbox."@".$obj->to[0]->host)."</td></tr>"; 
    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>"; 
     499                                                                $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>";                                                                
    470500                                                                $ix_part =      strtolower($attachment['type']) == "delivery-status" ? 1 : 0; 
    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; 
     501                                                                $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]));                                                           
     502                                                                break;                   
    473503                                                        } 
    474504                                                } 
     
    480510                                        $content .= nl2br(imap_base64(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID))); 
    481511                                else if(!strtolower($msg->structure[$msg_number]->subtype) == "mixed") 
    482                                         $content .= nl2br(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID)); 
    483                         } 
    484                 } 
     512                                        $content .= nl2br(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID));                          
     513                        } 
     514                }  
    485515                // Force message with flag Seen (imap_fetchbody not works correctly) 
    486                 $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen"); 
     516                $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen");                                
    487517                $this->set_messages_flag($params); 
    488518                $content = $this->process_embedded_images($msg,$msg_number,$content, $msg_folder); 
     
    491521                return $return; 
    492522        } 
    493  
     523         
    494524        function htmlfilter($body) 
    495525        { 
    496526                require_once('htmlfilter.inc'); 
    497  
     527                 
    498528                $tag_list = Array( 
    499529                                false, 
     
    568598                                          '\\1round:\\2\\1' 
    569599                                        ) 
    570                                     ), 
    571  
     600                                    ),      
     601           
    572602                          '/^style/i' => 
    573603                              Array( 
     
    595625                                '/^a$/i' => Array('target' => '"_new"') 
    596626                ); 
    597  
    598  
     627         
     628         
    599629                $trusted_body = sanitize($body, 
    600630                                $tag_list, 
     
    606636                                $add_attr_to_tag 
    607637                ); 
    608  
     638         
    609639            return $trusted_body; 
    610640        } 
    611  
     641         
    612642        function decodeBody($body, $encoding, $charset=null) 
    613643        { 
     
    620650                if ($encoding == 'quoted-printable') 
    621651            { 
    622  
     652                         
    623653                        for($i=0;$i<256;$i++) { 
    624654                                $c1=dechex($i); 
     
    627657                                $myqprinta[]=$c1; 
    628658                                $myqprintb[]=chr($i); 
    629                         } 
     659                        }                
    630660                        $body = str_replace($myqprinta,$myqprintb,($body)); 
    631661                        $body = quoted_printable_decode($body); 
    632                 while (ereg("=\n", $body)) 
     662                while (ereg("=\n", $body))  
    633663                { 
    634664                        $body = ereg_replace ("=\n", '', $body); 
    635665                } 
    636666        } 
    637         else if ($encoding == 'base64') 
     667        else if ($encoding == 'base64')  
    638668        { 
    639669                $body = base64_decode($body); 
    640670        } 
    641         /*else if ($encoding == '7bit') 
     671        /*else if ($encoding == '7bit')  
    642672        { 
    643                 $body = quoted_printable_decode($body); 
     673                $body = quoted_printable_decode($body);                                          
    644674        }*/ 
    645675                // All other encodings are returned raw. 
     
    649679                        return $body; 
    650680        } 
    651  
     681         
    652682        function process_embedded_images($msg, $msgno, $body, $msg_folder) 
    653683        { 
     
    666696                        } 
    667697                } 
    668  
     698                 
    669699                return $body; 
    670700        } 
    671  
     701         
    672702        function replace_special_characters($body) 
    673703        { 
    674704                // Suspected TAGS! 
    675                 /*$tag_list = Array( 
     705                /*$tag_list = Array(    
    676706                        'blink','object','meta', 
    677707                        'html','link','frame', 
     
    682712                */ 
    683713 
    684                 // Layout problem: Change html elements 
    685                 // with absolute position to relate position, CASE INSENSITIVE. 
     714                // Layout problem: Change html elements  
     715                // with absolute position to relate position, CASE INSENSITIVE.  
    686716                $body = @eregi_replace("POSITION: ABSOLUTE;","",$body); 
    687717 
     
    691721 
    692722                $body = $this-> replace_links($body); 
    693                 $blocked_tags = array(); 
     723                $blocked_tags = array();                 
    694724                foreach($tag_list as $index => $tag) { 
    695725                        $new_body = eregi_replace("<$tag", "<!--$tag", $body); 
     
    703733        } 
    704734 
    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(); 
     735        function replace_links($body) {                                  
     736                $matches = array(); 
    711737                // Verify exception. 
    712                 //@preg_match("/<a href=\"notes:\/\/\//",$body,$matches); 
     738                @preg_match("/<a href=\"notes:\/\/\//",$body,$matches); 
    713739                // It no has exception,then open the link in new window. 
    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; 
     740                if(count($matches)) 
     741                        return $body; 
     742         
     743                $pattern = '/(?<=[\s|(<br>)|\n|\r|;])((http(s?):\/\/((?:[\w]\.?)+(?::[\d]+)?[:\/.\-~&=?%;@#,+\w]*))|((?:www?\.)(?:\w\.?)*(?::\d+)?[\:\/\w.\-~&=?%;@+]*))/i'; 
     744                $replacement = '<a href="http$3://$4$5" target="_blank">$1</a>'; 
     745                return preg_replace($pattern, $replacement, $body);  
     746                 
     747                // Original 
     748                //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); 
    722749        } 
    723750 
    724751        function get_signature($msg, $msg_number, $msg_folder) 
    725         { 
     752        {  
    726753                foreach ($msg->file_type[$msg_number] as $index => $file_type) 
    727754                { 
    728755                        $file_type = strtolower($file_type); 
    729                         if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') 
    730                         { 
    731                                 if ($file_type == 'application/x-pkcs7-signature') 
     756                        if(strtolower($msg->encoding[$msg_number][$index]) == 'base64')  
     757                        { 
     758                                if ($file_type == 'application/x-pkcs7-signature')  
    732759                                { 
    733760                                        $export_mail = new ExportEml(); 
     
    735762                                        $params['msgs_to_export'] = $msg_number; 
    736763                                    $tempDir = ini_get("session.save_path"); 
    737                                         $cert_file = $tempDir."/certificate_".base_convert(microtime(), 10, 36).".crt"; 
     764                                        $cert_file = $tempDir."/certificate_".base_convert(microtime(), 10, 36).".crt";                                  
    738765                                        $result = openssl_pkcs7_verify($export_mail->export_msg($params),PKCS7_NOVERIFY,$cert_file); 
    739766                                        if (file_exists($cert_file)) 
     
    755782                        } 
    756783                } 
    757                 return $sign; 
     784                return $sign;    
    758785        } 
    759786 
     
    776803        return $thumbs_array; 
    777804        } 
    778  
     805                 
    779806        /*function delete_msg($params) 
    780807        { 
    781808                $folder = $params['folder']; 
    782809                $msgs_to_delete = explode(",",$params['msgs_to_delete']); 
    783  
     810                 
    784811                $mbox_stream = $this->open_mbox($folder); 
    785  
     812                 
    786813                foreach ($msgs_to_delete as $msg_number){ 
    787814                        imap_delete($mbox_stream, $msg_number, FT_UID); 
     
    794821        function delete_msgs($params) 
    795822        { 
    796  
     823                 
    797824                $folder = $params['folder']; 
    798825                $folder =  mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); 
    799826                $msgs_number = explode(",",$params['msgs_number']); 
    800827                $border_ID = $params['border_ID']; 
    801  
     828                 
    802829                $return = array(); 
    803  
    804                 if ($params['get_previous_msg']) 
     830                 
     831                if ($params['get_previous_msg']){ 
    805832                        $return['previous_msg'] = $this->get_info_previous_msg($params); 
     833                        // Fix problem in unserialize function JS. 
     834                        $return['previous_msg']['body'] = str_replace(array('{','}'), array('&#123;','&#125;'), $return['previous_msg']['body']); 
     835                } 
    806836 
    807837                //$mbox_stream = $this->open_mbox($folder); 
    808838                $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()))); 
    809  
     839                 
    810840                foreach ($msgs_number as $msg_number) 
    811841                { 
     
    813843                                $return['msgs_number'][] = $msg_number; 
    814844                } 
    815  
     845                 
    816846                $return['folder'] = $folder; 
    817847                $return['border_ID'] = $border_ID; 
    818  
     848                 
    819849                if($mbox_stream) 
    820850                        imap_close($mbox_stream, CL_EXPUNGE); 
     
    822852        } 
    823853 
    824  
     854                 
    825855        function refresh($params) 
    826856        { 
    827857                include("class.imap_attachment.inc.php"); 
    828                 $imap_attachment = new imap_attachment(); 
     858                $imap_attachment = new imap_attachment();                
    829859                $folder = $params['folder']; 
    830860                $msg_range_begin = $params['msg_range_begin']; 
    831861                $msg_range_end = $params['msg_range_end']; 
    832862                $msgs_existent = $params['msgs_existent']; 
    833                 $sort_box_type = $params['sort_box_type']; 
     863                $sort_box_type = $params['sort_box_type'];               
    834864                $sort_box_reverse = $params['sort_box_reverse']; 
    835865                $msgs_in_the_server = array(); 
     
    839869                if(!count($sort_array_msg)) 
    840870                        return array(); 
    841  
     871                         
    842872                $num_msgs = (count($sort_array_msg) - imap_num_recent($this->mbox)); 
    843873                $msgs_in_the_client = explode(",", $msgs_existent); 
    844874 
    845  
     875                 
    846876                for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= count($sort_array_msg))); $msg_range_begin++) 
    847877                { 
     
    858888                        } 
    859889                } 
    860  
     890                 
    861891                $msg_to_insert  = array_diff($msgs_in_the_server, $msgs_in_the_client); 
    862892                $msg_to_delete = array_diff($msgs_in_the_client, $msgs_in_the_server); 
    863  
     893                 
    864894                $msgs_to_exec = array(); 
    865895                if ((count($msg_to_insert)) && ($msgs_existent)) 
     
    887917                        } 
    888918                } 
    889  
     919                 
    890920                $return = array(); 
    891921                $i = 0; 
     
    895925                        if (!is_object($header)) 
    896926                                return false; 
    897  
     927                         
    898928                        $return[$i]['msg_number']       = $msg_number; 
    899929                        $return[$i]['command']          = $command; 
    900  
     930                         
    901931                        $return[$i]['msg_folder']       = $folder; 
    902932                        $return[$i]['Recent']           = $header->Recent; 
     
    912942                        else 
    913943                                $return[$i]['udate'] = $date_msg; 
    914  
     944                         
    915945                        $from = $header->from; 
    916946                        $return[$i]['from'] = array(); 
     
    918948                        $return[$i]['from']['name'] = $tmp[0]->text; 
    919949                        $return[$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; 
    920                         //$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>'; 
     950                        //$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>';  
    921951                        if(!$return[$i]['from']['name']) 
    922952                                $return[$i]['from']['name'] = $return[$i]['from']['email']; 
    923  
     953                         
    924954                        /*$toaddress = imap_mime_header_decode($header->toaddress); 
    925955                        $return[$i]['toaddress'] = ''; 
     
    932962                        $return[$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; 
    933963                        $return[$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; 
    934  
     964                         
    935965                        $return[$i]['subject'] = $this->decode_string($header->fetchsubject); 
    936966 
    937967                        $return[$i]['Size'] = $header->Size; 
    938968                        $return[$i]['reply_toaddress'] = $header->reply_toaddress; 
    939  
     969                         
    940970                        $return[$i]['attachment'] = array(); 
    941971                        $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); 
     
    949979        } 
    950980 
    951         function get_folders_list() 
    952         { 
    953                 $mbox_stream = $this->open_mbox(); 
     981        function get_folders_list($params = null) 
     982        { 
     983                $mbox_stream = $this->open_mbox();               
    954984                $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; 
    955985                $folders_list = imap_getmailboxes($mbox_stream, $serverString, "*"); 
    956986                $tmp = array(); 
    957987                $result = array(); 
    958  
     988                 
    959989                if (is_array($folders_list)) { 
    960990                        reset($folders_list); 
    961991                $this->ldap = new ldap_functions(); 
    962  
     992                         
    963993                        $i = 0; 
    964994                        while (list($key, $val) = each($folders_list)) { 
    965995                                $status = imap_status($mbox_stream, $val->name, SA_UNSEEN); 
    966996                                $result[$i]['folder_unseen'] = $status->unseen; 
    967  
     997                         
    968998                                //$tmp_folder_id = explode("}", imap_utf7_decode($val->name)); 
    969999                                $tmp_folder_id = explode("}", mb_convert_encoding($val->name, "ISO_8859-1", "UTF7-IMAP" )); 
    9701000                                $folder_id = $tmp_folder_id[1]; 
    9711001                                $result[$i]['folder_id'] = $folder_id; 
    972  
     1002                                 
    9731003                                $tmp_folder_parent = explode($this->imap_delimiter, $folder_id); 
    9741004                                $result[$i]['folder_name'] = array_pop($tmp_folder_parent); 
     
    9791009                                        } 
    9801010                                } 
    981  
     1011                                 
    9821012                                $tmp_folder_parent = implode($this->imap_delimiter, $tmp_folder_parent); 
    9831013                                $result[$i]['folder_parent'] = $tmp_folder_parent == 'INBOX' ? '' : $tmp_folder_parent; 
    984  
     1014                                         
    9851015                                if (($val->attributes == 32) && ($result[$i]['folder_name'] != 'Inbox')) 
    9861016                                        $result[$i]['folder_hasChildren'] = 1; 
     
    9881018                                        $result[$i]['folder_hasChildren'] = 0; 
    9891019 
    990                                 $i++; 
     1020                                $i++;                            
    9911021                        } 
    9921022                } 
    993  
     1023                 
    9941024                foreach ($result as $folder_info) 
    9951025                { 
    9961026                        $array_tmp[] = $folder_info['folder_id']; 
    9971027                } 
    998  
     1028                 
    9991029                natcasesort($array_tmp); 
    1000  
     1030                 
    10011031                foreach ($array_tmp as $key => $folder_id) 
    10021032                { 
    10031033                        $result2[] = $result[$key]; 
    10041034                } 
    1005  
    1006                 if($mbox_stream && is_resource($mbox_stream)){ 
    1007                         imap_close($mbox_stream); 
    1008                 } 
    1009  
    1010                 return array_merge($result2); 
    1011         } 
    1012  
     1035                 
     1036                $current_folder = "INBOX"; 
     1037                if($params && $params['folder']) 
     1038                        $current_folder = $params['folder']; 
     1039                return array_merge($result2, $this->get_quota(array(folder_id => $current_folder))); 
     1040        } 
     1041         
    10131042        function create_mailbox($arr) 
    10141043        { 
     
    10171046                $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 
    10181047                $namebox =  mb_convert_encoding($namebox, "UTF7-IMAP", "UTF-8"); 
    1019  
     1048                 
    10201049                $result = "Ok"; 
    10211050                if(!imap_createmailbox($mbox_stream,"{".$imap_server."}$namebox")) 
    10221051                { 
    10231052                        $result = implode("<br />\n", imap_errors()); 
    1024                 } 
    1025  
     1053                }        
     1054                 
    10261055                if($mbox_stream) 
    10271056                        imap_close($mbox_stream); 
    1028  
     1057                                         
    10291058                return $result; 
    1030  
    1031         } 
    1032  
     1059                 
     1060        } 
     1061         
    10331062        function create_extra_mailbox($arr) 
    10341063        { 
     
    10371066                $mbox_stream = $this->open_mbox(); 
    10381067                $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 
    1039                 foreach($nameboxs as $key=>$tmp){ 
     1068                foreach($nameboxs as $key=>$tmp){                        
    10401069                        if($tmp != ""){ 
    10411070                                if(!imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}$tmp"))){ 
    10421071                                        $result = implode("<br />\n", imap_errors()); 
    10431072                                        if($mbox_stream) 
    1044                                                 imap_close($mbox_stream); 
     1073                                                imap_close($mbox_stream);                                        
    10451074                                        return $result; 
    10461075                                } 
     
    10511080                return true; 
    10521081        } 
    1053  
     1082         
    10541083        function delete_mailbox($arr) 
    10551084        { 
     
    10581087                $mbox_stream = $this->open_mbox(); 
    10591088                //$del_folder = imap_deletemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox"); 
    1060  
     1089                 
    10611090                $result = "Ok"; 
    10621091                $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); 
     
    10691098                return $result; 
    10701099        } 
    1071  
     1100         
    10721101        function ren_mailbox($arr) 
    10731102        { 
     
    10771106                $mbox_stream = $this->open_mbox(); 
    10781107                //$ren_folder = imap_renamemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox","{".$imap_server."}INBOX.$new_box"); 
    1079  
     1108                 
    10801109                $result = "Ok"; 
    10811110                $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); 
    10821111                $new_box = mb_convert_encoding($new_box, "UTF7-IMAP","UTF-8"); 
    1083  
     1112                 
    10841113                if(!imap_renamemailbox($mbox_stream,"{".$imap_server."}$namebox","{".$imap_server."}$new_box")) 
    10851114                { 
    1086                         $result = imap_errors(); 
     1115                        $result = imap_errors();                         
    10871116                } 
    10881117                if($mbox_stream) 
    10891118                        imap_close($mbox_stream); 
    10901119                return $result; 
    1091  
    1092         } 
    1093  
     1120                 
     1121        } 
     1122         
    10941123        function get_num_msgs($params) 
    10951124        { 
     
    10991128                        if(!$this->mbox || !is_resource($this->mbox)) 
    11001129                        return imap_last_error(); 
    1101                 } 
     1130                }                
    11021131                $num_msgs = imap_num_msg($this->mbox); 
    11031132                if($this->mbox && is_resource($this->mbox)) 
    11041133                        imap_close($this->mbox); 
    1105  
     1134                 
    11061135                return $num_msgs; 
    11071136        } 
    1108  
     1137         
    11091138        function send_mail($params) 
    11101139        { 
     
    11141143                $db = new db_functions(); 
    11151144                $fromaddress = $params['input_from'] ? explode(';',$params['input_from']) : ""; 
     1145                ## 
     1146                # @AUTHOR Rodrigo Souza dos Santos 
     1147                # @DATE 2008/09/17 
     1148                # @BRIEF Checks if the user has permission to send an email with the email address used. 
     1149                ## 
     1150                if ( is_array($fromaddress) && ($fromaddress[1] != $_SESSION['phpgw_info']['expressomail']['user']['email']) ) 
     1151                { 
     1152                        $deny = true; 
     1153                        foreach( $_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes'] as $key => $val ) 
     1154                                if ( array_key_exists('mail', $val) && $val['mail'][0] == $fromaddress[1] ) 
     1155                                        $deny = false and end($_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes']); 
     1156 
     1157                        if ( $deny ) 
     1158                                return "The server denied your request to send a mail, you cannot use this mail address."; 
     1159                } 
    11161160                $toaddress = implode(',',$db->getAddrs(explode(',',$params['input_to']))); 
    11171161                $ccaddress = implode(',',$db->getAddrs(explode(',',$params['input_cc']))); 
     
    11241168                $attachments = $params['FILES']; 
    11251169                $forwarding_attachments = $params['forwarding_attachments']; 
    1126  
     1170                  
    11271171                $folder =$params['folder']; 
    1128                 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 
    1129                 $folder_name = $params['folder_name']; 
     1172                $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1");                
     1173                $folder_name = $params['folder_name'];           
    11301174                // Fix problem with cyrus delimiter changes. 
    1131                 // Dots in names: enabled/disabled. 
     1175                // Dots in names: enabled/disabled.                              
    11321176                $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); 
    11331177                $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); 
    11341178                // End Fix. 
    1135                 if ($folder != 'null'){ 
     1179                if ($folder != 'null'){                  
    11361180                        $mail->SaveMessageInFolder = $folder; 
    11371181                } 
    11381182//////////////////////////////////////////////////////////////////////////////////////////////////// 
    11391183                $mail->SMTPDebug = false; 
    1140  
     1184                                 
    11411185                $mail->IsSMTP(); 
    11421186                $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; 
     
    11501194                        $mail->From = $fromaddress[1]; 
    11511195                } 
    1152  
     1196                                 
    11531197                $this->add_recipients("to", $toaddress, &$mail); 
    11541198                $this->add_recipients("cc", $ccaddress, &$mail); 
     
    11601204//////////////////////////////////////////////////////////////////////////////////////////////////// 
    11611205                //      Build CID for embedded Images!!! 
    1162                 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&amp;msg_num=(.+)?&amp;msg_part=(.+)?)"/isU'; 
     1206                $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU'; 
    11631207                $cid_imgs = ''; 
    11641208                $name_cid_files = array(); 
    11651209                preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); 
    11661210                $cid_array = array(); 
    1167                 foreach($cid_imgs[4] as $j => $val){ 
    1168                                 if ( !array_key_exists($cid_imgs[3][$j].$val, $cid_array) ) 
     1211                foreach($cid_imgs[6] as $j => $val){ 
     1212                                if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) ) 
    11691213                        { 
    1170                 $cid_array[$cid_imgs[3][$j].$val] = base_convert(microtime(), 10, 36); 
     1214                $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); 
    11711215                        } 
    1172                         $cid = $cid_array[$cid_imgs[3][$j].$val]; 
     1216                        $cid = $cid_array[$cid_imgs[4][$j].$val];  
    11731217                        $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 
    1174  
    1175                                 if ($msg_uid != $cid_imgs[3][$j]) // The image isn't in the same mail? 
     1218                         
     1219                                if ($msg_uid != $cid_imgs[4][$j]) // The image isn't in the same mail? 
    11761220                                { 
    1177                                         $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[3][$j], $cid_imgs[4][$j], 'base64'); 
     1221                                        $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); 
    11781222                                        $fileName = "image_".($j).".jpg"; 
    11791223                                        $fileCode = "base64"; 
     
    11821226                                else 
    11831227                                { 
    1184                                         $attach_img = $forwarding_attachments[$cid_imgs[4][$j]-2]; 
     1228                                        $attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2]; 
    11851229                                        $file_description = unserialize(rawurldecode($attach_img)); 
    11861230 
    1187                                         foreach($file_description as $i => $descriptor){ 
     1231                                        foreach($file_description as $i => $descriptor){                                 
    11881232                                                $file_description[$i]  = eregi_replace('\'*\'','',$descriptor); 
    11891233                                        } 
     
    11921236                                        $fileCode = $file_description[4]; 
    11931237                                        $fileType = $this->get_file_type($file_description[2]); 
    1194                                         unset($forwarding_attachments[$cid_imgs[4][$j]-2]); 
     1238                                        unset($forwarding_attachments[$cid_imgs[6][$j]-2]); 
    11951239                                } 
    11961240                                $tempDir = ini_get("session.save_path"); 
    1197                                 $file = "cid_image_".base_convert(microtime(), 10, 36).".dat"; 
     1241                                $file = "cid_image_".base_convert(microtime(), 10, 36).".dat";                                   
    11981242                                $f = fopen($tempDir.'/'.$file,"w"); 
    11991243                                fputs($f,$fileContent); 
     
    12021246                                        $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); 
    12031247                                //else 
    1204                                 //      return "Error loading image attachment content"; 
     1248                                //      return "Error loading image attachment content";                                                 
    12051249 
    12061250                } 
     
    12171261                        } 
    12181262                        if( $total_uploaded_size > $upload_max_filesize) 
    1219                                 return 'false'; 
    1220                 } 
     1263                                return 'false';                  
     1264                }                        
    12211265//////////////////////////////////////////////////////////////////////////////////////////////////// 
    12221266                //      Build Forwarding Attachments!!! 
     
    12271271                                $name_cid_files[count($name_cid_files)] = $name_cid_files[0]; 
    12281272                                $name_cid_files[0] = null; 
    1229                         } 
    1230  
     1273                        }                        
     1274                         
    12311275                        foreach($forwarding_attachments as $forwarding_attachment) 
    12321276                        { 
    12331277                                        $file_description = unserialize(rawurldecode($forwarding_attachment)); 
    12341278                                        $tmp = array_values($file_description); 
    1235                                         foreach($file_description as $i => $descriptor){ 
     1279                                        foreach($file_description as $i => $descriptor){                                 
    12361280                                                $tmp[$i]  = eregi_replace('\'*\'','',$descriptor); 
    12371281                                        } 
    1238                                         $file_description = $tmp; 
     1282                                        $file_description = $tmp;                                        
    12391283                                        $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 
    12401284                                        $fileName = $file_description[2]; 
     
    12571301                else 
    12581302                { 
    1259                         if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True") 
     1303                        if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True")  
    12601304                        { 
    12611305                                $userid = $_SESSION['phpgw_info']['expressomail']['user']['userid']; 
     
    12631307                                $now = date("d/m/y H:i:s"); 
    12641308                                $addrs = $toaddress.$ccaddress.$ccoaddress; 
    1265                                 $sent = trim($sent); 
     1309                                $sent = trim($sent);                                                                                             
    12661310                                error_log("$now - $userip - $sent [$subject] - $userid => $addrs\r\n", 3, "/home/expressolivre/mail_senders.log"); 
    12671311                        } 
     
    12771321        function add_recipients($recipient_type, $full_address, $mail) 
    12781322        { 
    1279                 $parse_address = imap_rfc822_parse_adrlist($full_address, ""); 
    1280                 foreach ($parse_address as $val) 
     1323                $parse_address = imap_rfc822_parse_adrlist($full_address, "");           
     1324                foreach ($parse_address as $val)  
    12811325                { 
    12821326                        //echo "<script language=\"javascript\">javascript:alert('".$val->mailbox."@".$val->host."');</script>"; 
    12831327                        if ($val->mailbox == "INVALID_ADDRESS") 
    12841328                                continue; 
    1285  
     1329                         
    12861330                        if (empty($val->personal)) 
    12871331                        { 
     
    13171361                return true; 
    13181362        } 
    1319  
     1363         
    13201364        function get_forwarding_attachment($msg_folder, $msg_number, $msg_part, $encoding) 
    13211365        { 
    1322                 $mbox_stream = $this->open_mbox($msg_folder); 
    1323                 $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID); 
     1366                $mbox_stream = $this->open_mbox($msg_folder);                    
     1367                $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID);             
    13241368                if($encoding == 'base64') 
    1325                         $fileContent = imap_base64($fileContent); 
     1369                        # The function imap_base64 adds a new line 
     1370                        # at ASCII text, with CRLF line terminators. 
     1371                        # So is being exchanged for base64_decode. 
     1372                        # 
     1373                        #$fileContent = imap_base64($fileContent); 
     1374                        $fileContent = base64_decode($fileContent); 
    13261375                else if($encoding == 'quoted-printable') 
    1327                         $fileContent = quoted_printable_decode($fileContent); 
     1376                        $fileContent = quoted_printable_decode($fileContent);                            
    13281377                return $fileContent; 
    13291378        } 
    1330  
     1379         
    13311380        function del_last_caracter($string) 
    13321381        { 
    13331382                $string = substr($string,0,(strlen($string) - 1)); 
    1334                 return $string; 
    1335         } 
    1336  
     1383                return $string;  
     1384        } 
     1385         
    13371386        function del_last_two_caracters($string) 
    13381387        { 
    13391388                $string = substr($string,0,(strlen($string) - 2)); 
    1340                 return $string; 
    1341         } 
    1342  
     1389                return $string;  
     1390        } 
     1391         
    13431392        function imap_sortfrom($sort_box_reverse, $search_box_type) 
    13441393        { 
    13451394                $sortfrom = array(); 
    13461395                $sortfrom_uid = array(); 
    1347  
     1396                 
    13481397                $num_msgs = imap_num_msg($this->mbox); 
    13491398                for ($i=1; $i<=$num_msgs; $i++) 
     
    13581407                                continue; 
    13591408                        } 
    1360                         // List ANSWERED messages. 
     1409                        // List ANSWERED messages.                       
    13611410                        elseif($search_box_type == "ANSWERED" && !trim($header->Answered)){ 
    1362                                 continue; 
    1363                         } 
    1364                         // List FLAGGED messages. 
     1411                                continue;                                
     1412                        } 
     1413                        // List FLAGGED messages.                        
    13651414                        elseif($search_box_type == "FLAGGED" && !trim($header->Flagged)){ 
    13661415                                continue; 
    13671416                        } 
    1368  
    1369                         if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email']) 
     1417                                                 
     1418                        if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email'])                              
    13701419                                $from = $header->to; 
    13711420                        else 
    13721421                                $from = $header->from; 
    1373  
    1374                         $tmp = imap_mime_header_decode($from[0]->personal); 
    1375  
     1422                         
     1423                        $tmp = imap_mime_header_decode($from[0]->personal);                      
     1424                         
    13761425                        if ($tmp[0]->text != "") 
    13771426                                $sortfrom[$i] = $tmp[0]->text; 
     
    13791428                                $sortfrom[$i] = $from[0]->mailbox . "@" . $from[0]->host; 
    13801429                } 
    1381  
     1430                 
    13821431                natcasesort($sortfrom); 
    1383  
     1432                 
    13841433                foreach($sortfrom as $index => $header_msg) 
    1385                 { 
     1434                {        
    13861435                        $sortfrom_uid[] = imap_uid($this->mbox, $index); 
    13871436                } 
    1388  
     1437                 
    13891438                if ($sort_box_reverse) 
    13901439                        $sortfrom_uid = array_reverse($sortfrom_uid); 
    1391  
     1440                 
    13921441                return $sortfrom_uid; 
    13931442        } 
    13941443 
    1395         function move_search_messages($params){ 
    1396                 $params['selected_messages'] = urldecode($params['selected_messages']); 
     1444        function move_search_messages($params){          
     1445                $params['selected_messages'] = urldecode($params['selected_messages']);  
    13971446                $params['new_folder'] = urldecode($params['new_folder']); 
    13981447                $params['new_folder_name'] = urldecode($params['new_folder_name']); 
    13991448                $sel_msgs = explode(",", $params['selected_messages']); 
    1400                 @reset($sel_msgs); 
     1449                @reset($sel_msgs);       
    14011450                $sorted_msgs = array(); 
    14021451                foreach($sel_msgs as $idx => $sel_msg) { 
     
    14041453                         if(array_key_exists($sel_msg[0], $sorted_msgs)){ 
    14051454                                $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; 
    1406                          } 
     1455                         }       
    14071456                         else { 
    14081457                                $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; 
     
    14101459                } 
    14111460                @ksort($sorted_msgs); 
    1412                 $last_return = false; 
    1413                 foreach($sorted_msgs as $folder => $msgs_number) { 
     1461                $last_return = false;            
     1462                foreach($sorted_msgs as $folder => $msgs_number) {                       
    14141463                        $params['msgs_number'] = $msgs_number; 
    1415                         $params['folder'] = $folder; 
     1464                        $params['folder'] = $folder;     
    14161465                        if($params['new_folder'] && $folder != $params['new_folder']){ 
    1417                                 $last_return = $this -> move_messages($params); 
     1466                                $last_return = $this -> move_messages($params);                          
    14181467                        } 
    14191468                        elseif(!$params['new_folder'] || $params['delete'] ){ 
     
    14241473                return $last_return; 
    14251474        } 
    1426  
     1475         
    14271476        function move_messages($params) 
    14281477        { 
    1429                 $folder = $params['folder']; 
    1430                 $mbox_stream = $this->open_mbox($folder); 
     1478                $folder = $params['folder'];             
     1479                $mbox_stream = $this->open_mbox($folder);                
    14311480                $newmailbox = ($params['new_folder']); 
    14321481                $newmailbox = mb_convert_encoding($newmailbox, "UTF7-IMAP","ISO_8859-1"); 
     
    14381487                                                'border_ID' => $params['border_ID'], 
    14391488                                                'status' => true); //Status foi adicionado para validar as permissoes ACL 
    1440  
     1489                 
    14411490                //Este bloco tem a finalidade de averiguar as permissoes para pastas compartilhadas 
    14421491        if (substr($folder,0,4) == 'user'){ 
     
    14671516                                        $return['new_folder_name'] = $cn; 
    14681517        } 
    1469  
    1470                 // Caso estejamos no box principal, nï¿œo ï¿œ necessï¿œrio pegar a informaᅵᅵo da mensagem anterior. 
     1518                                 
     1519                // Caso estejamos no box principal, nao eh necessario pegar a informacao da mensagem anterior.           
    14711520                if (($params['get_previous_msg']) && ($params['border_ID'] != 'null') && ($params['border_ID'] != '')) 
     1521                { 
    14721522                        $return['previous_msg'] = $this->get_info_previous_msg($params); 
    1473  
    1474                 $mbox_stream = $this->open_mbox($folder); 
     1523                        // Fix problem in unserialize function JS. 
     1524                        $return['previous_msg']['body'] = str_replace(array('{','}'), array('&#123;','&#125;'), $return['previous_msg']['body']); 
     1525                } 
     1526                 
     1527                $mbox_stream = $this->open_mbox($folder);        
    14751528                if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { 
    14761529                        imap_expunge($mbox_stream); 
     
    14791532                        return $return; 
    14801533                }else { 
    1481                         if(strstr(imap_last_error(),'Over quota')) { 
     1534                        if(strstr(imap_last_error(),'Over quota')) {                             
    14821535                                $accountID      = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminUsername']; 
    1483                                 $pass           = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminPW']; 
    1484                                 $userID         = $_SESSION['phpgw_info']['expressomail']['user']['userid']; 
     1536                                $pass           = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminPW'];                                                                        
     1537                                $userID         = $_SESSION['phpgw_info']['expressomail']['user']['userid'];                                                             
    14851538                                $server         = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 
    14861539                                $mbox           = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}INBOX", $accountID, $pass) or die(serialize(array('imap_error' => imap_last_error()))); 
    14871540                                if(!$mbox) 
    14881541                                        return imap_last_error(); 
    1489                                 $quota  = imap_get_quotaroot($mbox_stream, "INBOX"); 
     1542                                $quota  = imap_get_quotaroot($mbox_stream, "INBOX");                             
    14901543                                if(! imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, 2.1 * $quota['usage'])) { 
    14911544                                        if($mbox_stream) 
    14921545                                                imap_close($mbox_stream); 
    1493                                         if($mbox) 
     1546                                        if($mbox)                                                                        
    14941547                                                imap_close($mbox); 
    1495                                         return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n"; 
     1548                                        return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n";                                                                
    14961549                                } 
    14971550                                if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { 
     
    15031556                                                if($mbox) 
    15041557                                                        imap_close($mbox); 
    1505                                                 return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; 
     1558                                                return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n";                                                          
    15061559                                        } 
    1507                                         return $return; 
     1560                                        return $return;                                                                                                  
    15081561                                } 
    15091562                                else { 
     
    15131566                                                if($mbox) 
    15141567                                                        imap_close($mbox); 
    1515                                                 return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; 
     1568                                                return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n";                                                          
    15161569                                        } 
    1517                                         return imap_last_error(); 
    1518                                 } 
    1519  
     1570                                        return imap_last_error();                                
     1571                                } 
     1572                                 
    15201573                        } 
    15211574                        else { 
     
    15241577                                return "move_messages() line ".__LINE__.": ". imap_last_error()." folder:".$newmailbox; 
    15251578                        } 
    1526                 } 
    1527         } 
    1528  
     1579                }                
     1580        } 
     1581         
    15291582        function save_msg($params) 
    15301583        { 
    1531  
     1584                 
    15321585                include_once("class.phpmailer.php"); 
    15331586                $mail = new PHPMailer(); 
     
    15441597                $attachments = $params['FILES']; 
    15451598                $return_files = $params['FILES']; 
    1546  
     1599                  
    15471600                $folder = $params['folder']; 
    1548                 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 
     1601                $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1");                
    15491602                // Fix problem with cyrus delimiter changes. 
    1550                 // Dots in names: enabled/disabled. 
     1603                // Dots in names: enabled/disabled.                              
    15511604                $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); 
    15521605                $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); 
    15531606                // End Fix. 
    1554  
     1607                                         
    15551608                $mail->SaveMessageInFolder = $folder; 
    15561609                $mail->SMTPDebug = false; 
    1557  
     1610                                                 
    15581611                $mail->IsSMTP(); 
    15591612                $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; 
     
    15611614                $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; 
    15621615                $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 
    1563  
     1616                 
    15641617                $mail->Sender = $mail->From; 
    15651618                $mail->SenderName = $mail->FromName; 
    15661619                $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 
    15671620                $mail->From =  $_SESSION['phpgw_info']['expressomail']['user']['email']; 
    1568  
     1621                                 
    15691622                $this->add_recipients("to", $toaddress, &$mail); 
    15701623                $this->add_recipients("cc", $ccaddress, &$mail); 
     
    15721625                $mail->IsHTML(true); 
    15731626                $mail->Body = $body; 
    1574  
     1627                 
    15751628                //      Build CID for embedded Images!!! 
    1576                 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&amp;msg_num=(.+)?&amp;msg_part=(.+)?)"/isU'; 
     1629                $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU'; 
    15771630                $cid_imgs = ''; 
    15781631                $name_cid_files = array(); 
    15791632                preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); 
    15801633                $cid_array = array(); 
    1581                 foreach($cid_imgs[4] as $j => $val){ 
    1582                                 if ( !array_key_exists($cid_imgs[3][$j].$val, $cid_array) ) 
     1634                foreach($cid_imgs[6] as $j => $val){ 
     1635                                if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) ) 
    15831636                        { 
    1584                 $cid_array[$cid_imgs[3][$j].$val] = base_convert(microtime(), 10, 36); 
     1637                $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); 
    15851638                        } 
    1586                         $cid = $cid_array[$cid_imgs[3][$j].$val]; 
     1639                        $cid = $cid_array[$cid_imgs[4][$j].$val];  
    15871640                        $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 
    1588  
    1589                                 if ($msg_uid != $cid_imgs[3][$j]) // The image isn't in the same mail? 
     1641                         
     1642                                if ($msg_uid != $cid_imgs[4][$j]) // The image isn't in the same mail? 
    15901643                                { 
    1591                                         $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[3][$j], $cid_imgs[4][$j], 'base64'); 
     1644                                        $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); 
     1645                                        //prototype: get_forwarding_attachment ( folder, msg number, part, encoding) 
    15921646                                        $fileName = "image_".($j).".jpg"; 
    15931647                                        $fileCode = "base64"; 
    15941648                                        $fileType = "image/jpg"; 
     1649                                        $file_attached[0] = $cid_imgs[2][$j]; 
     1650                                        $file_attached[1] = $cid_imgs[4][$j]; 
     1651                                        $file_attached[2] = $fileName; 
     1652                                        $file_attached[3] = $cid_imgs[6][$j]; 
     1653                                        $file_attached[4] = 'base64'; 
     1654                                        $file_attached[5] = strlen($fileContent); //Size of file 
     1655                                        $return_forward[] = $file_attached; 
    15951656                                } 
    15961657                                else 
    15971658                                { 
    1598                                         $attach_img = $forwarding_attachments[$cid_imgs[4][$j]-2]; 
     1659                                        $attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2]; 
    15991660                                        $file_description = unserialize(rawurldecode($attach_img)); 
    1600                                         foreach($file_description as $i => $descriptor){ 
     1661                                        foreach($file_description as $i => $descriptor){                                 
    16011662                                                $file_description[$i]  = eregi_replace('\'*\'','',$descriptor); 
    16021663                                        } 
     
    16051666                                        $fileCode = $file_description[4]; 
    16061667                                        $fileType = $this->get_file_type($file_description[2]); 
    1607                                         unset($forwarding_attachments[$cid_imgs[4][$j]-2]); 
     1668                                        unset($forwarding_attachments[$cid_imgs[6][$j]-2]); 
    16081669                                        if (!empty($file_description)) 
    16091670                                        { 
     
    16131674                                } 
    16141675                                $tempDir = ini_get("session.save_path"); 
    1615                                 $file = "cid_image_".base_convert(microtime(), 10, 36).".dat"; 
     1676                                $file = "cid_image_".base_convert(microtime(), 10, 36).".dat";                                   
    16161677                                $f = fopen($tempDir.'/'.$file,"w"); 
    16171678                                fputs($f,$fileContent); 
     
    16201681                                        $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); 
    16211682                                //else 
    1622                                 //      return "Error loading image attachment content"; 
    1623  
    1624                 } 
    1625  
    1626         //      Build Forwarding Attachments!!! 
     1683                                //      return "Error loading image attachment content";                                                 
     1684 
     1685                } 
     1686         
     1687        //      Build Forwarding Attachments!!!          
    16271688                if (count($forwarding_attachments) > 0) 
    16281689                { 
     
    16311692                                $file_description = unserialize(rawurldecode($forwarding_attachment)); 
    16321693                                $tmp = array_values($file_description); 
    1633                                 foreach($file_description as $i => $descriptor){ 
     1694                                foreach($file_description as $i => $descriptor){                                 
    16341695                                        $tmp[$i]  = eregi_replace('\'*\'','',$descriptor); 
    16351696                                } 
    16361697                                $file_description = $tmp; 
    1637  
     1698                                 
    16381699                                $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 
    16391700                                $fileName = $file_description[2]; 
    1640  
     1701                                 
    16411702                                $file_description[5] = strlen($fileContent); //Size of file 
    16421703                                $return_forward[] = $file_description; 
    1643  
     1704                         
    16441705                                        $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); 
    16451706                        } 
    16461707                } 
    1647  
     1708                 
    16481709                if ((count($return_forward) > 0) && (count($return_files) > 0)) 
    16491710                        $return_files = array_merge_recursive($return_forward,$return_files); 
     
    16511712                        if (count($return_files) < 1) 
    16521713                                $return_files = $return_forward; 
    1653  
     1714         
    16541715                //      Build Uploading Attachments!!! 
    16551716                if (count($attachments)) 
    16561717                        foreach ($attachments as $attach) 
    1657                                 $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name']));  // optional name 
    1658  
    1659  
    1660  
     1718                                $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name']));  // optional name                   
     1719         
     1720         
     1721                 
    16611722                if(!empty($mail->AltBody)) 
    16621723            $mail->ContentType = "multipart/alternative"; 
     
    16661727        $header = $mail->CreateHeader(); 
    16671728        $body = $mail->CreateBody(); 
    1668  
     1729         
    16691730        if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') 
    16701731                { 
     
    16801741                $imap_port      = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; 
    16811742                $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$folder, $username, $password); 
    1682  
     1743         
    16831744                $new_header = str_replace("\n", "\r\n", $header); 
    16841745                $new_body = str_replace("\n", "\r\n", $body); 
    1685  
     1746                 
    16861747                $return['append'] = imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".$folder, $new_header . $new_body, "\\Seen \\Draft"); 
    16871748                $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); 
    16881749                $return['msg_no'] = $status->uidnext - 1; 
    16891750                $return['folder_id'] = $folder; 
    1690  
     1751                 
    16911752                if($mbox_stream) 
    16921753                        imap_close($mbox_stream); 
    1693  
     1754                                 
    16941755                foreach ($return_files as $index => $_attachment) { 
    16951756                        if (array_key_exists("name",$_attachment)){ 
     
    17031764                        } 
    17041765                } 
    1705  
     1766                 
    17061767                $return['files'] = serialize($return_files); 
    1707  
     1768                                 
    17081769                if (!$return['append']) 
    17091770                        $return['append'] = imap_last_error(); 
    1710  
     1771                 
    17111772                return $return; 
    17121773        } 
    1713  
     1774         
    17141775        function set_messages_flag($params) 
    17151776        { 
     
    17201781                $return["msgs_to_set"] = $msgs_to_set; 
    17211782                $return["flag"] = $flag; 
    1722  
     1783                 
    17231784                if(!$this->mbox && !is_resource($this->mbox)) 
    17241785                        $this->mbox = $this->open_mbox($folder); 
    1725  
     1786                 
    17261787                if ($flag == "unseen") 
    17271788                        $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Seen", ST_UID); 
     
    17381799                elseif ($flag == "unflagged") 
    17391800                        $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Flagged", ST_UID); 
    1740  
     1801                 
    17411802                if($this->mbox && is_resource($this->mbox)) 
    17421803                        imap_close($this->mbox); 
    17431804                return $return; 
    17441805        } 
    1745  
     1806         
    17461807        function get_file_type($file_name) 
    17471808        { 
    17481809                $file_name = strtolower($file_name); 
    17491810                $strFileType = strrev(substr(strrev($file_name),0,4)); 
    1750                 if ($strFileType == ".asf") 
     1811                if ($strFileType == ".asf")  
    17511812                        return "video/x-ms-asf"; 
    17521813                if ($strFileType == ".avi") 
     
    17741835                if ($strFileType == ".htm" || $strFileType == "html") 
    17751836                        return "text/html"; 
    1776                 if ($strFileType == ".xml") 
     1837                if ($strFileType == ".xml")  
    17771838                        return "text/xml"; 
    1778                 if ($strFileType == ".xsl") 
     1839                if ($strFileType == ".xsl")  
    17791840                        return "text/xsl"; 
    1780                 if ($strFileType == ".css") 
     1841                if ($strFileType == ".css")  
    17811842                        return "text/css"; 
    1782                 if ($strFileType == ".php") 
     1843                if ($strFileType == ".php")  
    17831844                        return "text/php"; 
    1784                 if ($strFileType == ".asp") 
     1845                if ($strFileType == ".asp")  
    17851846                        return "text/asp"; 
    17861847                if ($strFileType == ".pdf") 
     
    18101871                if ($strFileType == ".stw") 
    18111872                        return "application/vnd.sun.xml.writer.template"; 
    1812  
    1813  
    1814                 return "application/octet-stream"; 
    1815         } 
    1816  
     1873                 
     1874                 
     1875                return "application/octet-stream";               
     1876        } 
     1877         
    18171878        function htmlspecialchars_encode($str) 
    18181879        { 
    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; 
     1880                return  str_replace( array('&', '"','\'','<','>','{','}'), array('&amp;','&quot;','&#039;','&lt;','&gt;','&#123;','&#125;'), $str); 
    18321881        } 
    18331882        function htmlspecialchars_decode($str) 
    18341883        { 
    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  
     1884                return  str_replace( array('&amp;','&quot;','&#039;','&lt;','&gt;','&#123;','&#125;'), array('&', '"','\'','<','>','{','}'), $str); 
     1885        } 
     1886         
    18491887        function get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse){ 
    1850  
     1888                 
    18511889                if(!$this->mbox || !is_resource($this->mbox)){ 
    18521890                        $this->mbox = $this->open_mbox($folder); 
     1891                 
    18531892                } 
    18541893 
    18551894                switch($sort_box_type){ 
    18561895                        case 'SORTFROM': 
    1857                                 return $this->imap_sortfrom($sort_box_reverse, $search_box_type); 
     1896                                return $this->imap_sortfrom($sort_box_reverse, $search_box_type);                                
    18581897                        case 'SORTSUBJECT': 
    1859                                 return imap_sort($this->mbox, SORTSUBJECT, $sort_box_reverse, SE_UID, $search_box_type); 
     1898                                return imap_sort($this->mbox, SORTSUBJECT, $sort_box_reverse, SE_UID, $search_box_type);                                 
    18601899                        case 'SORTSIZE': 
    1861                                 return imap_sort($this->mbox, SORTSIZE, $sort_box_reverse, SE_UID, $search_box_type); 
     1900                                return imap_sort($this->mbox, SORTSIZE, $sort_box_reverse, SE_UID, $search_box_type);                            
    18621901                        default: 
    1863                                 return imap_sort($this->mbox, SORTARRIVAL, $sort_box_reverse, SE_UID, $search_box_type); 
    1864                 } 
    1865         } 
    1866  
     1902                                return imap_sort($this->mbox, SORTARRIVAL, $sort_box_reverse, SE_UID, $search_box_type);                                                 
     1903                }                
     1904        }        
     1905         
    18671906        function get_info_next_msg($params) 
    18681907        { 
     
    18731912                $reuse_border = $params['reuse_border']; 
    18741913                $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 
    1875                 $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); 
    1876  
     1914                $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse);                               
     1915                 
    18771916                $success = false; 
    18781917                if (is_array($sort_array_msg)) 
     
    18931932                        return $params; 
    18941933                } 
    1895  
     1934                 
    18961935                $params = array(); 
    18971936                $params['msg_number'] = $sort_array_msg[($i+1)]; 
    18981937                $params['msg_folder'] = $folder; 
    1899  
    1900                 $return = $this->get_info_msg($params); 
     1938                 
     1939                $return = $this->get_info_msg($params);          
    19011940                $return["reuse_border"] = $reuse_border; 
    19021941                return $return; 
     
    19121951                $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 
    19131952                $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); 
    1914  
     1953                 
    19151954                $success = false; 
    19161955                if (is_array($sort_array_msg)) 
     
    19301969                        return $params; 
    19311970                } 
    1932  
     1971                 
    19331972                $params = array(); 
    19341973                $params['msg_number'] = $sort_array_msg[($i-1)]; 
    19351974                $params['msg_folder'] = $folder; 
    1936  
     1975                 
    19371976                $return = $this->get_info_msg($params); 
    19381977                $return["reuse_border"] = $reuse_border; 
    19391978                return $return; 
    19401979        } 
    1941  
     1980         
    19421981        // This function updates the values: quota, paging and new messages menu. 
    19431982        function get_menu_values($params){ 
    19441983                $return_array = array(); 
    19451984                $return_array = $this->get_quota($params); 
    1946  
     1985                 
    19471986                $mbox_stream = $this->open_mbox($params['folder']); 
    1948                 $return_array['num_msgs'] = imap_num_msg($mbox_stream); 
     1987                $return_array['num_msgs'] = imap_num_msg($mbox_stream);          
    19491988                if($mbox_stream) 
    19501989                        imap_close($mbox_stream); 
    1951  
    1952                 return $return_array; 
    1953         } 
    1954  
     1990                                 
     1991                return $return_array;  
     1992        } 
     1993         
    19551994        function get_quota($params){ 
    1956                 $folder_id = $params['folder_id']; 
    1957                 if(!$this->mbox || !is_resource($this->mbox)) 
     1995                // folder_id = user/{uid} for shared folders 
     1996                if(substr($params['folder_id'],0,5) != 'INBOX' && preg_match('/user\\'.$this->imap_delimiter.'/i', $params['folder_id'])){ 
     1997                        $array_folder =  explode($this->imap_delimiter,$params['folder_id']); 
     1998                        $folder_id = "user".$this->imap_delimiter.$array_folder[1];              
     1999                } 
     2000                // folder_id = INBOX for inbox folders 
     2001                else 
     2002                        $folder_id = "INBOX"; 
     2003                 
     2004                if(!$this->mbox) 
    19582005                        $this->mbox = $this->open_mbox(); 
    19592006 
     
    19612008                if($this->mbox && is_resource($this->mbox)) 
    19622009                        imap_close($this->mbox); 
    1963  
     2010                         
    19642011                if (!$quota){ 
    19652012                        return array( 
     
    19692016                        ); 
    19702017                } 
    1971  
     2018                 
    19722019                if(count($quota) && $quota['limit']) { 
    19732020                        $quota_limit = (($quota['limit']/1024)* 100 + .5 )* .01; 
     
    19842031                        ); 
    19852032                } 
    1986                 else 
     2033                else  
    19872034                        return array(); 
    19882035        } 
    1989  
     2036         
    19902037        function send_notification($params){ 
    19912038                require_once("class.phpmailer.php"); 
    19922039                $mail = new PHPMailer(); 
    1993  
     2040                  
    19942041                $toaddress = $params['notificationto']; 
    1995  
    1996                 $subject = 'Leitura confirmada da mensagem: ' . $params['subject']; 
     2042                 
     2043                $subject = 'Confirmação de leitura: ' . $params['subject']; 
    19972044                $body = 'Sua mensagem: ' . $params['subject'] . '<br>'; 
    19982045                $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"); 
     
    20082055                $mail->IsHTML(true); 
    20092056                $mail->Body = $body; 
    2010  
     2057                 
    20112058                if(!$mail->Send()){ 
    20122059                        return $mail->ErrorInfo; 
     
    20152062                        return true; 
    20162063        } 
    2017  
     2064         
    20182065        function empty_trash() 
    20192066        { 
    2020                 $folder = 'INBOX' . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']; 
     2067                $folder = 'INBOX' . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'];  
    20212068                $mbox_stream = $this->open_mbox($folder); 
    20222069                $return = imap_delete($mbox_stream,'1:*'); 
     
    20252072                return $return; 
    20262073        } 
    2027  
     2074         
    20282075        function search($params) 
    20292076        { 
    20302077                include("class.imap_attachment.inc.php"); 
    2031                 $imap_attachment = new imap_attachment(); 
     2078                $imap_attachment = new imap_attachment();                                
    20322079                $criteria = $params['criteria']; 
    20332080                $return = array(); 
    20342081                $folders = $this->get_folders_list(); 
    2035  
     2082                 
    20362083                $j = 0; 
    20372084                foreach($folders as $folder) 
     
    20392086                        $mbox_stream = $this->open_mbox($folder); 
    20402087                        $messages = imap_search($mbox_stream, $criteria, SE_UID); 
    2041  
     2088                         
    20422089                        if ($messages == '') 
    20432090                                continue; 
    2044  
     2091                 
    20452092                        $i = 0; 
    20462093                        $return[$j] = array(); 
    20472094                        $return[$j]['folder_name'] = $folder['name']; 
    2048  
     2095                         
    20492096                        foreach($messages as $msg_number) 
    20502097                        { 
     
    20522099                                if (!is_object($header)) 
    20532100                                        return false; 
    2054  
     2101                                 
    20552102                                $return[$j][$i]['msg_folder']   = $folder['name']; 
    20562103                                $return[$j][$i]['msg_number']   = $msg_number; 
     
    20612108                                $return[$j][$i]['Draft']                = $header->Draft; 
    20622109                                $return[$j][$i]['Flagged']              = $header->Flagged; 
    2063  
     2110         
    20642111                                $date_msg = date("d/m/Y",$header->udate); 
    20652112                                if (date("d/m/Y") == $date_msg) 
     
    20672114                                else 
    20682115                                        $return[$j][$i]['udate'] = $date_msg; 
    2069  
     2116                         
    20702117                                $fromaddress = imap_mime_header_decode($header->fromaddress); 
    20712118                                $return[$j][$i]['fromaddress'] = ''; 
    20722119                                foreach ($fromaddress as $tmp) 
    20732120                                        $return[$j][$i]['fromaddress'] .= $this->replace_maior_menor($tmp->text); 
    2074  
     2121                         
    20752122                                $from = $header->from; 
    20762123                                $return[$j][$i]['from'] = array(); 
     
    20782125                                $return[$j][$i]['from']['name'] = $tmp[0]->text; 
    20792126                                $return[$j][$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; 
    2080                                 $return[$j][$i]['from']['full'] ='"' . $return[$j][$i]['from']['name'] . '" ' . '<' . $return[$j][$i]['from']['email'] . '>'; 
     2127                                $return[$j][$i]['from']['full'] ='"' . $return[$j][$i]['from']['name'] . '" ' . '<' . $return[$j][$i]['from']['email'] . '>';  
    20812128 
    20822129                                $to = $header->to; 
     
    20852132                                $return[$j][$i]['to']['name'] = $tmp[0]->text; 
    20862133                                $return[$j][$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; 
    2087                                 $return[$j][$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; 
     2134                                $return[$j][$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>';  
    20882135 
    20892136                                $subject = imap_mime_header_decode($header->fetchsubject); 
     
    20942141                                $return[$j][$i]['Size'] = $header->Size; 
    20952142                                $return[$j][$i]['reply_toaddress'] = $header->reply_toaddress; 
    2096  
     2143                         
    20972144                                $return[$j][$i]['attachment'] = array(); 
    20982145                                $return[$j][$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($mbox_stream, $msg_number); 
    2099  
     2146                                                 
    21002147                                $i++; 
    21012148                        } 
     
    21042151                                imap_close($mbox_stream); 
    21052152                } 
    2106  
     2153         
    21072154                return $return; 
    21082155        } 
    2109  
     2156         
    21102157        function delete_and_show_previous_message($params) 
    21112158        { 
    21122159                $return = $this->get_info_previous_msg($params); 
    2113  
     2160                 
    21142161                $params_tmp1 = array(); 
    21152162                $params_tmp1['msgs_to_delete'] = $params['msg_number']; 
    21162163                $params_tmp1['folder'] = $params['msg_folder']; 
    21172164                $return_tmp1 = $this->delete_msg($params_tmp1); 
    2118  
     2165                 
    21192166                $return['msg_number_deleted'] = $return_tmp1; 
    2120  
     2167                 
    21212168                return $return; 
    21222169        } 
    2123  
    2124  
     2170                 
     2171         
    21252172        function automatic_trash_cleanness($params) 
    21262173        { 
     
    21402187//      Fix the search problem with special characters!!!! 
    21412188        function remove_accents($string) { 
    2142                 return strtr($string, 
    2143                 "?ï¿œ??ï¿œ?ï¿œ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵ", 
     2189                return strtr($string,  
     2190                "?Ó??ó?Ý?úÁÀÃÂÄÇÉÈÊËÍÌ?ÎÏÑÕÔÓÒÖÚÙ?ÛÜ?áàãâäçéèêëíì?îïñóòõôöúù?ûüýÿ",  
    21442191                "SOZsozYYuAAAAACEEEEIIIIINOOOOOUUUUUsaaaaaceeeeiiiiinooooouuuuuyy"); 
    21452192        } 
     
    21652212                                                $filter .= '"'.$filter_array[1].'"'; 
    21662213                                        } 
    2167                                 } 
    2168                                 $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 
     2214                                }                
     2215                                $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" );  
    21692216                                $filter = $this->remove_accents($filter); 
    21702217                                $folder_name = explode($this->imap_delimiter,$name_box); 
     
    21772224                                } 
    21782225                                $folder_name = implode($this->imap_delimiter,$folder_name); 
    2179  
     2226                                 
    21802227                                if(!is_resource($mbox_stream)) 
    21812228                                        $mbox_stream = $this->open_mbox($name_box); 
    21822229                                else 
    21832230                                        imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); 
    2184  
    2185                                 if (preg_match("/^.?\bALL\b/", $filter)){ // Quick Search, note: this ALL isn't the same ALL from imap_search 
    2186  
     2231                         
     2232                                if (preg_match("/^.?\bALL\b/", $filter)){ // Quick Search, note: this ALL isn't the same ALL from imap_search    
     2233                                 
    21872234                                        $all_criterias = array ("TO","SUBJECT","FROM","CC"); 
    21882235                                        foreach($all_criterias as $criteria_fixed) 
    21892236                                        { 
    21902237                                                $_filter = $criteria_fixed . substr($filter,4); 
    2191  
     2238                                         
    21922239                                                $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); 
    2193  
     2240                                                 
    21942241                                                if($search_criteria && count($search_criteria) < 50) 
    21952242                                                { 
    21962243                                                        foreach($search_criteria as $new_search){ 
    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"); 
     2244                                                                $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"); 
    21982245                                                                if(!@strstr($retorno,$m_token)) 
    21992246                                                                        $retorno .= $m_token; 
    22002247                                                        } 
    2201                                                 } 
    2202                                                 else if(count($search_criteria) >= 50) 
    2203                                                         return "many results"; 
     2248                                                }                                                
     2249                                                else if(count($search_criteria) >= 50)                                                   
     2250                                                        return "many results";                                           
    22042251                                        } 
    22052252                                } 
     
    22092256                                        { 
    22102257                                                foreach($search_criteria as $new_search) 
    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"); 
     2258                                                        $retorno .= trim("##".mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--" . $new_search."##"."\n"); 
    22122259                                        } 
    22132260                                } 
     
    22152262                } 
    22162263                if($mbox_stream) 
    2217                         imap_close($mbox_stream); 
    2218  
     2264                        imap_close($mbox_stream);                
     2265                                                 
    22192266                return $retorno ? $retorno : "none"; 
    22202267        } 
    2221  
     2268         
    22222269        function get_msg($uid_msg,$name_box, $mbox_stream ) 
    22232270        { 
    2224                 $header = @imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $uid_msg), 80, 255); 
     2271                $header = @imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $uid_msg), 80, 255);          
    22252272                $subject = $this->decode_string($header->fetchsubject); 
    22262273                $from = $header->from[0]->mailbox; 
    22272274                if($header->from[0]->personal != "") 
    22282275                        $from = $header->from[0]->personal; 
    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  
     2276                $ret_msg = $this->decode_string($from) . "--" . $subject . "--". date("d/m/Y",$header ->udate)."--". $this->size_msg($header->Size); 
     2277                return $ret_msg;                     
     2278        }        
     2279         
    22332280        function size_msg($size){ 
    22342281                $var = floor($size/1024); 
    22352282                if($var >= 1){ 
    2236                         return $var." kb"; 
     2283                        return $var." kb";       
    22372284                }else{ 
    2238                         return $size ." b"; 
     2285                        return $size ." b";      
    22392286                } 
    22402287        } 
     
    22632310           } 
    22642311        } 
    2265  
     2312         
    22662313        function getacl() 
    22672314        { 
    22682315                $this->ldap = new ldap_functions(); 
    2269  
     2316                 
    22702317                $return = array(); 
    2271                 $mbox_stream = $this->open_mbox(); 
     2318                $mbox_stream = $this->open_mbox();       
    22722319                $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); 
    2273  
     2320                 
    22742321                $i = 0; 
    22752322                foreach ($mbox_acl as $user => $acl) 
     
    22842331                return $return; 
    22852332        } 
    2286  
     2333         
    22872334        function setacl($params) 
    22882335        { 
     
    22902337                if (!count($old_users)) 
    22912338                        $old_users = array(); 
    2292  
     2339                 
    22932340                $tmp_array = array(); 
    22942341                foreach ($old_users as $index => $user_info) 
     
    22972344                } 
    22982345                $old_users = $tmp_array; 
    2299  
     2346                 
    23002347                $users = unserialize($params['users']); 
    23012348                if (!count($users)) 
    23022349                        $users = array(); 
    2303  
     2350                 
    23042351                //$add_share = array_diff($users, $old_users); 
    23052352                $remove_share = array_diff($old_users, $users); 
     
    23242371                        } 
    23252372                }*/ 
    2326  
     2373                 
    23272374                if (count($remove_share)) 
    23282375                { 
     
    23372384                        } 
    23382385                        } 
    2339                         } 
    2340                 } 
    2341  
     2386                        }        
     2387                } 
     2388                 
    23422389                return true; 
    23432390        } 
    2344  
     2391         
    23452392        function getaclfromuser($params) 
    23462393        { 
    23472394                $useracl = $params['user']; 
    2348  
     2395                 
    23492396                $return = array(); 
    23502397                $return[$useracl] = 'false'; 
    2351                 $mbox_stream = $this->open_mbox(); 
     2398                $mbox_stream = $this->open_mbox();       
    23522399                $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); 
    2353  
     2400                 
    23542401                foreach ($mbox_acl as $user => $acl) 
    23552402                { 
     
    23702417                //No caso de se tratar da caixa do proprio usuario logado, utiliza a sintaxe abaixo 
    23712418                if(substr($user,0,4) != 'user') 
    2372                   $mbox_acl = imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); 
     2419                $mbox_acl = imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); 
    23732420                else 
    23742421                  $mbox_acl = imap_getacl($mbox_stream, $user); 
    23752422                return $mbox_acl[$this->username]; 
    23762423        } 
    2377  
     2424         
    23782425 
    23792426        function setaclfromuser($params) 
     
    23812428                $user = $params['user']; 
    23822429                $acl = $params['acl']; 
    2383  
     2430                 
    23842431                $mbox_stream = $this->open_mbox(); 
    23852432 
     
    23912438                        foreach ($mailboxes_list as $key => $val) 
    23922439                        { 
    2393                                 $folder = str_replace($serverString, "", imap_utf7_decode($val->name)); 
     2440                                $folder = str_replace($serverString, "", imap_utf7_encode($val->name)); 
     2441                                $folder = str_replace("&-", "&", $folder); 
    23942442                                if (!imap_setacl ($mbox_stream, $folder, $user, $acl)) 
    23952443                                { 
    2396                                         return imap_last_error(); 
    2397                                 } 
    2398                         } 
    2399                 } 
    2400  
    2401                 return true; 
    2402         } 
    2403  
     2444                                        $return = imap_last_error(); 
     2445                                } 
     2446                        } 
     2447                } 
     2448                if (isset($return)) 
     2449                        return $return; 
     2450                else 
     2451                        return true; 
     2452        } 
     2453         
    24042454        function download_attachment($msg,$msgno) 
    24052455        { 
    2406                 $array_parts_attachments = array(); 
     2456                $array_parts_attachments = array();              
    24072457                $array_parts_attachments['names'] = ''; 
    24082458                include("class.imap_attachment.inc.php"); 
    2409                 $imap_attachment = new imap_attachment(); 
    2410  
     2459                $imap_attachment = new imap_attachment();                
     2460                 
    24112461                if (count($msg->fname[$msgno]) > 0) 
    24122462                { 
     
    24252475                $array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2)); 
    24262476                return $array_parts_attachments; 
    2427         } 
     2477        }        
    24282478 
    24292479        function spam($params) 
     
    24392489                        $msg = $header . $body; 
    24402490                        $email = $_SESSION['phpgw_info']['expressomail']['user']['email']; 
    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)); 
     2491                        $username = $this->username; 
    24442492                        strtok($email, '@'); 
    24452493                        $domain = strtok('@'); 
    24462494 
     2495                        //Encontrar a assinatura do dspam no cabecalho 
     2496                        $v = explode("\r\n", $header); 
     2497                        foreach ($v as $linha){ 
     2498                                if (eregi("^X-DSPAM-Signature", $linha)) { 
     2499                                         
     2500                                        $args = explode(" ",$linha); 
     2501                                        $signature = $args[1]; 
     2502                                } 
     2503                        } 
     2504 
    24472505                        // feed dspam 
    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  
     2506                        switch($is_spam){ 
     2507                                case 'true':  $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam']; break; 
     2508                                case 'false': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham']; break; 
     2509                        } 
     2510                        $tags = array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##'); 
     2511                        $cmd = str_replace($tags,array($email,$username,$domain,$signature),$cmd); 
    24592512                        system($cmd); 
    2460  
    24612513                } 
    24622514                imap_close($mbox_stream); 
Note: See TracChangeset for help on using the changeset viewer.