Ignore:
Timestamp:
07/08/10 17:52:20 (14 years ago)
Author:
amuller
Message:

Ticket #1135 - Aplicando alterações do branches 2.0 no branches 2.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php

    r1969 r3018  
    7777        function get_range_msgs2($params) 
    7878        { 
     79                // Free others requests  
     80                session_write_close();  
    7981                $folder = $params['folder']; 
    8082                $msg_range_begin = $params['msg_range_begin']; 
     
    335337                        $head1 = explode(":",$head); 
    336338                        if ( (strtoupper($head1[0]) == "TO") || 
    337                                         (strtoupper($head1[0]) == "FROM") || 
    338                                         (strtoupper($head1[0]) == "SUBJECT") || 
    339                                         (strtoupper($head1[0]) == "DATE") ) 
    340                                 $header .= $head."\r\n"; 
     339                                (strtoupper($head1[0]) == "FROM") || 
     340                                (strtoupper($head1[0]) == "SUBJECT") || 
     341                                (strtoupper($head1[0]) == "DATE") ||  
     342                                (strtoupper($head1[0]) == "CONTENT-TYPE")) {  
     343 
     344                                        if(strtoupper($head1[0]) == "CONTENT-TYPE"){  
     345                                                $head = str_replace("multipart/mixed","text/html",$head);                         
     346                                        }  
     347                                        $header .= $head."\n";  
     348                                }  
    341349                } 
    342350 
     
    474482                $body = $return_get_body['body']; 
    475483                //Remoção de tags <span></span> para correção de erro no firefox 
    476                 $body = mb_ereg_replace("<span><span>","",$body); 
    477                 $body = mb_ereg_replace("</span></span>","",$body); 
     484                $body = mb_eregi_replace("<span><span>","",$body); 
     485                $body = mb_eregi_replace("</span></span>","",$body); 
    478486 
    479487                if($return_get_body['body']=='isCripted'){ 
     
    492500                } 
    493501 
    494                 $pattern = '/^[ \t]*Disposition-Notification-To(^:)*:(.+)*@(.+)*$/isUm'; 
     502                $pattern = '/^[ \t]*Disposition-Notification-To:[ ]*<?[[:alnum:]\._-]+@[[:alnum:]_-]+[\.[:alnum:]]+>?/sm'; 
    495503                if (preg_match($pattern, $header_, $fields)) 
    496504                { 
    497                         preg_match('/[[:alnum:]\._\-]+@[[:alnum:]_\-\.]+/',$fields[0], $matches); 
    498                         $return['DispositionNotificationTo'] = "<".$matches[0].">"; 
     505                        if(preg_match('/[[:alnum:]\._\-]+@[[:alnum:]_\-\.]+/',$fields[0], $matches)){  
     506                                $return['DispositionNotificationTo'] = "<".$matches[0].">";  
     507                        }  
    499508                } 
    500509 
     
    789798                if(!$msg->structure[$msg_number]->parts) //Simple message, only 1 piece 
    790799                { 
    791             if(strtolower($msg->structure[$msg_number]->subtype) == 'x-pkcs7-mime'){ 
    792                 $return['body']='isCripted'; 
    793                 return $return; 
    794             } 
     800                        if(strtolower($msg->structure[$msg_number]->subtype) == 'x-pkcs7-mime'){ 
     801                                $return['body']='isCripted'; 
     802                                return $return; 
     803                        } 
    795804 
    796805                        $attachment = array(); //No attachments 
    797806 
    798             if(strtolower($msg->structure[$msg_number]->subtype) == 'x-pkcs7-mime'){ 
    799                                         $return['body']='isCripted'; 
    800                                         return $return; 
    801                         } 
    802  
    803                         $content = ''; 
    804                         if (strtolower($msg->structure[$msg_number]->subtype) == "plain") 
    805                         { 
    806                                 $content .= '<span style="font-family: monospace">' . nl2br($this->decodeBody((imap_body($this->mbox, $msg_number, FT_UID)), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0])) . '</span>'; 
    807                         } 
    808                         else if (strtolower($msg->structure[$msg_number]->subtype) == "html") 
    809                         { 
    810                                 $content .= $this->decodeBody(imap_body($this->mbox, $msg_number, FT_UID), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0]); 
    811                         } 
     807                        if(strtolower($msg->structure[$msg_number]->subtype) == 'x-pkcs7-mime'){ 
     808                                $return['body']='isCripted'; 
     809                                return $return; 
     810                        } 
     811 
     812                        $content = '';  
     813                        // If simple message is subtype 'html' or 'plain', then get content body.  
     814                        if(strtolower($msg->structure[$msg_number]->subtype) == "html" ||   
     815                                strtolower( $msg -> structure[ $msg_number ] -> subtype ) == 'plain'){  
     816 
     817                                        $content = $this->decodeBody(  
     818                                                imap_body( $this -> mbox, $msg_number, FT_UID ),  
     819                                                $msg -> encoding[ $msg_number ][ 0 ],  
     820                                                $msg -> charset[ $msg_number ][ 0 ]  
     821                                        );  
     822 
     823                                        if ( strtolower( $msg -> structure[ $msg_number ] -> subtype ) == 'plain' )  
     824                                        {  
     825                                                $content = str_replace( array( '<', '>' ), array( ' #$<$# ', ' #$>$# ' ), $content );  
     826                                                $content = htmlentities( $content );  
     827                                                $content = $this -> replace_links( $content );  
     828                                                $content = str_replace( array( ' #$&lt;$# ', ' #$&gt;$# ' ), array( '&lt;', '&gt;' ), $content );  
     829                                                $content = '<pre style="white-space:pre;word-wrap: break-word;white-space:pre-wrap;font-family: monospace;font-size:12px">' . $content . '</pre>';  
     830 
     831                                                $return[ 'body' ] = $content;  
     832 
     833                                                return $return;  
     834                                        }  
     835                                } 
    812836                } 
    813837                else 
     
    836860 
    837861                                $file_type = strtolower($msg->file_type[$msg_number][$values]); 
    838                                 if($file_type == "message/rfc822") 
    839                                         $has_multipart = false; 
    840  
    841                                 if($file_type == "multipart/alternative") 
    842                                         $has_multipart = false; 
     862                                if($file_type == "message/rfc822" || $file_type == "multipart/alternative")  
     863                                {  
     864                                        // Show only 'text/html' part, when message/rfc822 format contains 'text/plain' alternative part.  
     865                                        if(array_key_exists($values+1, $msg->file_type[$msg_number]) &&  
     866                                                strtolower($msg->file_type[$msg_number][$values+1]) == 'text/plain' &&  
     867                                                array_key_exists($values+2, $msg->file_type[$msg_number]) &&  
     868                                                strtolower($msg->file_type[$msg_number][$values+2]) == 'text/html') {  
     869                                                        $has_multipart = false;  
     870                                                }  
     871                                }        
    843872 
    844873                                if(($file_type == "text/plain" 
    845874                                        || $file_type == "text/html") 
    846                                         && $file_type != 'attachment') 
     875                                                && $file_type != 'attachment') 
    847876                                { 
    848877                                        if($file_type == "text/plain" && !$show_only_html && $has_multipart) 
     
    850879                                                // if TXT file size > 100kb, then it will not expand. 
    851880                                                if(!($file_type == "text/plain" && $msg->fsize[$msg_number][$values] > 102400)) { 
    852                                                         $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]))); 
     881                                                         $content .= htmlentities($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]));  
     882                                                         $content = '<pre style="white-space:pre;word-wrap: break-word;white-space:pre-wrap;font-family: monospace;font-size:12px">' . $content . '</pre>';     
    853883                                                } 
    854884                                        } 
     
    860890                                        } 
    861891                                } 
    862                                 else if($file_type == "message/delivery-status"){ 
     892                                 else if($file_type == "message/delivery-status" || $file_type == "message/feedback-report"){  
    863893                                        $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 
    864                                         $content .= nl2br($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values])); 
    865  
     894                                         $content .= $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]);  
     895                                        $content = '<pre style="white-space:pre;word-wrap: break-word;white-space:pre-wrap;font-family: monospace;font-size:12px">' . $content . '</pre>';  
    866896                                } 
    867897                                else if($file_type == "message/rfc822" || $file_type == "text/rfc822-headers"){ 
     
    870900                                        $att = new imap_attachment(); 
    871901                                        $attachments =  $att -> get_attachment_info($this->mbox,$msg_number); 
    872                                         if($attachments['number_attachments'] > 0) { 
    873                                                 foreach($attachments ['attachment'] as $index => $attachment) 
    874                                                 { 
    875                                                         if ( in_array( strtolower( $attachment[ 'type' ] ), array( 'delivery-status', 'rfc822', 'rfc822-headers', 'plain' ) ) ) 
    876                                                         { 
    877                                                                 $obj = imap_rfc822_parse_headers( imap_fetchbody( $this -> mbox, $msg_number, $msg_part, FT_UID ), $msg -> encoding[ $msg_number ][ $values ] ); 
    878  
    879                                                                 $content .= '<hr align="left" width="95%" style="border:1px solid #DCDCDC">'; 
    880                                                                 $content .= '<br><table  style="margin:2px;border:1px solid black;background:#EAEAEA">'; 
    881  
    882                                                                 $content .= '<tr><td><b>' . $this->functions->getLang("Subject") 
    883                                                                         . ':</b></td><td>' .$this->decode_string($obj->subject) . '</td></tr>'; 
    884  
    885                                                                 $content .= '<tr><td><b>' . $this -> functions -> getLang( 'From' ) . ':</b></td><td>' 
    886                                                                         . $this -> replace_links( $this -> decode_string( $obj -> from[ 0 ] -> mailbox . '@' . $obj -> from[ 0 ] -> host) ) 
    887                                                                         . '</td></tr>'; 
    888  
    889                                                                 $content .= '<tr><td><b>' . $this->functions->getLang("Date") . ':</b></td><td>' . $obj->date . '</td></tr>'; 
    890  
    891                                                                 $content .= '<tr><td><b>' . $this -> functions -> getLang( 'TO' ) . ':</b></td><td>' 
    892                                                                         . $this -> replace_links( $this -> decode_string( $obj -> to[ 0 ] -> mailbox . '@' . $obj -> to[ 0 ] -> host ) ) 
    893                                                                         . '</td></tr>'; 
    894  
    895                                                                 if ( $obj->cc ) 
    896                                                                         $content .= '<tr><td><b>' . $this -> functions -> getLang( 'CC' ) . ':</b></td><td>' 
    897                                                                                 . $this -> replace_links( $this -> decode_string( $obj -> cc[ 0 ] -> mailbox . '@' . $obj -> cc[ 0 ] -> host ) ) 
    898                                                                                 . '</td></tr>'; 
    899  
    900                                                                 $content .= '</table><br>'; 
    901  
    902                                                                 $content .= $this->decodeBody( 
    903                                                                         imap_fetchbody( 
    904                                                                                 $this->mbox, 
    905                                                                                 $msg_number, 
    906                                                                                 ( $attachment['part_in_msg'] + ( 
    907                                                                                         ( strtolower( $attachment[ 'type' ] ) == 'delivery-status' ) ? 0 : 1 ) 
    908                                                                                 ) . ".1", 
    909                                                                                 FT_UID 
    910                                                                         ), 
    911                                                                         $msg->encoding[ $msg_number ][ $values ], 
    912                                                                         $msg->charset[ $msg_number ][ $values ] 
    913                                                                 ); 
    914                                                                 break; 
     902                                        if($attachments['number_attachments'] > 0) {  
     903                                                foreach($attachments ['attachment'] as $index => $attachment)  
     904                                                {  
     905                                                        if ( in_array( strtolower( $attachment[ 'type' ] ), array( 'delivery-status', 'rfc822', 'rfc822-headers', 'plain' ) ) )  
     906                                                        {  
     907                                                                $obj = imap_rfc822_parse_headers( imap_fetchbody( $this -> mbox, $msg_number, $msg_part, FT_UID ), $msg -> encoding[ $msg_number ][ $values ] );  
     908 
     909                                                                $content .= '<hr align="left" width="95%" style="border:1px solid #DCDCDC">';  
     910                                                                $content .= '<br><table  style="margin:2px;border:1px solid black;background:#EAEAEA">';  
     911 
     912                                                                $content .= '<tr><td><b>' . $this->functions->getLang("Subject")  
     913                                                                        . ':</b></td><td>' .$this->decode_string($obj->subject) . '</td></tr>';  
     914 
     915                                                                $content .= '<tr><td><b>' . $this -> functions -> getLang( 'From' ) . ':</b></td><td>'  
     916                                                                        . $this -> replace_links( $this -> decode_string( $obj -> from[ 0 ] -> mailbox . '@' . $obj -> from[ 0 ] -> host) )  
     917                                                                        . '</td></tr>';  
     918 
     919                                                                $content .= '<tr><td><b>' . $this->functions->getLang("Date") . ':</b></td><td>' . $obj->date . '</td></tr>';  
     920 
     921                                                                $content .= '<tr><td><b>' . $this -> functions -> getLang( 'TO' ) . ':</b></td><td>'  
     922                                                                        . $this -> replace_links( $this -> decode_string( $obj -> to[ 0 ] -> mailbox . '@' . $obj -> to[ 0 ] -> host ) )  
     923                                                                        . '</td></tr>';  
     924 
     925                                                                if ( $obj->cc )  
     926                                                                        $content .= '<tr><td><b>' . $this -> functions -> getLang( 'CC' ) . ':</b></td><td>'  
     927                                                                                . $this -> replace_links( $this -> decode_string( $obj -> cc[ 0 ] -> mailbox . '@' . $obj -> cc[ 0 ] -> host ) )  
     928                                                                                . '</td></tr>';  
     929 
     930                                                                $content .= '</table><br>';  
     931 
     932 
     933                                                                $id = ( ( strtolower( $attachment[ 'type' ] ) == 'delivery-status' ) ? false : true );  
     934                                                                if ( strtolower( $msg->structure[$msg_number]->parts[1]->parts[0]->subtype ) == 'plain' )  
     935                                                                {  
     936                                                                        $id = !$id;  
     937                                                                        if ( $msg->structure[$msg_number]->parts[1]->parts[0]->encoding == 4 )  
     938                                                                                $msg->encoding[ $msg_number ][ $values ] = 'quoted-printable';  
     939                                                                }  
     940 
     941                                                                $body = $this->decodeBody(  
     942                                                                        imap_fetchbody(  
     943                                                                                $this->mbox,  
     944                                                                                $msg_number,  
     945                                                                                ( $attachment['part_in_msg'] + ( ( int ) $id ) ) . ".1",  
     946                                                                                FT_UID  
     947                                                                        ),  
     948                                                                        $msg->encoding[ $msg_number ][ $values ],  
     949                                                                        $msg->charset[ $msg_number ][ $values ]  
     950                                                                );  
     951 
     952                                                                if ( strtolower( $msg->structure[$msg_number]->parts[1]->parts[0]->subtype ) == 'plain' )  
     953                                                                {  
     954                                                                        $body = str_replace( array( '<', '>' ), array( ' #$<$# ', ' #$>$# ' ), $body );  
     955                                                                        $body = htmlentities( $body );  
     956                                                                        $body = $this -> replace_links( $body );  
     957                                                                        $body = str_replace( array( ' #$&lt;$# ', ' #$&gt;$# ' ), array( '&lt;', '&gt;' ), $body );  
     958                                                                        $body = '<pre style="white-space:pre;word-wrap: break-word;white-space:pre-wrap;font-family: monospace;font-size:12px">' . $body . '</pre>';  
     959                                                                }  
     960 
     961                                                                $content .= $body;  
     962                                                                break;  
    915963                                                        } 
    916964                                                } 
     
    11511199        function replace_links( $body ) 
    11521200        { 
    1153                 $matches = array( ); 
    1154                 // Verify exception. 
    1155                 @preg_match( "/<a href=\"notes:\/\/\//", $body, $matches ); 
    1156  
    1157                 // If there is no exception, then open the link in new window. 
    1158                 if ( count( $matches ) ) 
    1159                         return $body; 
    1160  
    1161                 // All links should be moderated and they should only have the attribute 'target="blank"'. 
    1162                 $pattern = '/<a[^>]+href="([^>"]+)"[^>]*>(.*)<\/a>/im'; 
    1163                 $replacement = '<a href="$1" target="_blank">$2</a>'; 
     1201                // Domains and IPs addresses found in the text and which is not a link yet should be replaced by one.  
     1202                // See more informations in www.iana.org  
     1203                $octets = array(  
     1204                        'first' => '(2[0-3][0-9]|1[0-9]{2}|[1-9][0-9]?)',  
     1205                        'middle' => '(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})',  
     1206                        'last' => '(25[0-4]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)'  
     1207                );  
     1208 
     1209                $ip = "\b{$octets[ 'first' ]}\.({$octets[ 'middle' ]}\.){2}{$octets[ 'last' ]}\b";  
     1210 
     1211                $top_level_domains = '(\.(ac|ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|as|asia|at|au|aw|ax|az|'  
     1212                        . 'ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bl|bm|bn|bo|br|bs|bt|bv|bw|by|bz|'  
     1213                        . 'ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cu|cv|cx|cy|cz|'  
     1214                        . 'de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|'  
     1215                        . 'ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|'  
     1216                        . 'hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir|is|it|je|jm|jo|jobs|jp|'  
     1217                        . 'ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|'  
     1218                        . 'ma|mc|md|me|mf|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|'  
     1219                        . 'mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|'  
     1220                        . 'pa|pe|pf|pg|ph|pk|pl|pm|pn|pro|ps|pt|pw|py|qa|re|ro|rs|ru|rw|'  
     1221                        . 'sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|'  
     1222                        . 'tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|travel|tt|tv|tw|tz|'  
     1223                        . 'ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw))+\b';  
     1224 
     1225                $path = '(?>\/[\w\d\/\.\'\(\)\-\+~?!&#@$%|:;,*=_]+)?';  
     1226                $port = '(?>:\d{2,5})?';  
     1227                $domain = '(?>[\w\d_\-]+)';  
     1228                $subdomain = "(?>{$domain}\.)*";  
     1229                $protocol = '(?>(http|ftp)(s)?:\/\/)?';  
     1230                $url = "(?>{$protocol}((?>{$subdomain}{$domain}{$top_level_domains}|{$ip}){$port}{$path}))";  
     1231 
     1232                $pattern = "/(<\w[^>]+|[\/\"'@=])?{$url}/"; 
     1233                ini_set( 'pcre.backtrack_limit', 300000 );  
     1234 
     1235                /*  
     1236                // PHP 5.3  
     1237                $replace = function( $matches )  
     1238                {  
     1239                        if ( $matches[ 1 ] )  
     1240                                return $matches[ 0 ];  
     1241 
     1242                        $url = ( $matches[ 2 ] ) ? $matches[ 2 ] : 'http';  
     1243                        $url .= "{$matches[ 3 ]}://{$matches[ 4 ]}";  
     1244                        return "<a href=\"{$url}\" target=\"_blank\">{$matches[ 4 ]}</a>";  
     1245                };  
     1246                $body = preg_replace_callback( $pattern, $replace, $body );  
     1247                 */  
     1248 
     1249                // PHP 5.2.x - Remover assim que possível  
     1250                $body = preg_replace_callback( $pattern,  
     1251                        create_function(  
     1252                                '$matches',  
     1253                                'if ( $matches[ 1 ] ) return $matches[ 0 ];'  
     1254                                . '$url = ( $matches[ 2 ] ) ? $matches[ 2 ] : "http";' 
     1255                                . '$url .= "{$matches[ 3 ]}://{$matches[ 4 ]}";' 
     1256                                . 'return "<a href=\"{$url}\" target=\"_blank\">{$matches[ 4 ]}</a>";' 
     1257                        ), $body 
     1258                ); 
     1259                ini_set( 'pcre.backtrack_limit', 100000 );  
     1260                // E-mail address in the text should create a new e-mail on ExpressoMail 
     1261                $pattern = '/( |<|&lt;|>)([A-Za-z0-9\.~?\/_=#\-]*@[A-Za-z0-9\.~?\/_=#\-]*)( |>|&gt;|<)/im';  
     1262                $replacement = '$1<a href="mailto:$2">$2</a>$3'; 
    11641263                $body = preg_replace( $pattern, $replacement, $body ); 
    11651264 
    1166                 // Url found in the text and which is not a link yet should be replaced by one. 
    1167                 $pattern = '/(^|\w>|[ \(\[])((http(s)?:\/\/)?([\w\d_\-@]{2,}(\.[\w\d~?\/_=&#;\-:@$]+)+))/im'; 
    1168                 $replacement = '$1<a href="http$4://$5" target="_blank">$2</a>'; 
    1169                 $body = preg_replace( $pattern, $replacement, $body ); 
    1170  
    1171                 // E-mail address in the text should create a new e-mail on ExpressoMail 
    1172                 $pattern = '/( |<|&lt;|>)([A-Za-z0-9\.~?\/_=#\-]*@[A-Za-z0-9\.~?\/_=#\-]*)( |>|&gt;|<)/im'; 
    1173                 $replacement = '$1<a href="javascript:new_message_to(\'$2\')">$2</a>$3'; 
    1174                 $body = preg_replace( $pattern, $replacement, $body ); 
    1175  
    1176                 // If there is an link with a "mailto:" in href attribute, it will changed to create a new e-mail on ExpressoMail. 
    1177                 $pattern = '/<a[^>]+href=["\']mailto:([^"]+)["\'][^>]*>([^<]+)<\/a>/im'; 
    1178                 $replacement = '<a href="javascript:new_message_to(\'$1\')">$2</a>'; 
    1179                 $body = preg_replace( $pattern, $replacement, $body ); 
    1180  
    11811265                return $body; 
    11821266        } 
     
    11841268        function get_signature($msg, $msg_number, $msg_folder) 
    11851269        { 
    1186         include_once("../security/classes/CertificadoB.php"); 
     1270        include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php"); 
    11871271                include_once("class.db_functions.inc.php"); 
    11881272                foreach ($msg->file_type[$msg_number] as $index => $file_type) 
     
    15571641                        $this->delete_mailbox(array("del_past" => "INBOX/decifradas")); 
    15581642                } 
    1559                 $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; 
    1560                 $folders_list = imap_getmailboxes($mbox_stream, $serverString, ($params && $params['noSharedFolders']) ? "INBOX/*" : "*"); 
    1561                 $folders_list = array_slice($folders_list,0,$this->foldersLimit); 
    1562  
    1563                 $tmp = array(); 
    1564                 $resultMine = array(); 
    1565                 $resultDefault = array(); 
     1643 
    15661644 
    15671645                $inbox = 'INBOX'; 
    15681646                $trash = $inbox . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']; 
    1569                 $drafts = $inbox . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']; 
    1570                 $spam = $inbox . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']; 
    1571                 $sent = $inbox . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']; 
     1647                $drafts = $inbox . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']; 
     1648                $spam = $inbox . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']; 
     1649                $sent = $inbox . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']; 
     1650                $uid2cn = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'];  
     1651                // Free others requests  
     1652                session_write_close();  
     1653 
     1654                $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}";  
     1655                $folders_list = imap_getmailboxes($mbox_stream, $serverString, ($params && $params['noSharedFolders']) ? "INBOX/*" : "*");  
     1656                $folders_list = array_slice($folders_list,0,$this->foldersLimit);  
     1657 
     1658                $tmp = array();  
     1659                $resultMine = array();  
     1660                $resultDefault = array();  
    15721661 
    15731662                if (is_array($folders_list)) { 
     
    15931682                                $result[$i]['folder_name'] = array_pop($tmp_folder_parent); 
    15941683                                $result[$i]['folder_name'] = $result[$i]['folder_name'] == 'INBOX' ? 'Inbox' : $result[$i]['folder_name']; 
    1595                                 if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($folder_id,0,4) == 'user') { 
     1684                                if ($uid2cn && substr($folder_id,0,4) == 'user') { 
    15961685                                        //$this->ldap = new ldap_functions(); 
    15971686                                        if ($cn = $this->ldap->uid2cn($result[$i]['folder_name'])) { 
     
    17981887                                return "The server denied your request to send a mail, you cannot use this mail address."; 
    17991888                } 
    1800  
    1801                 //new_message_to backs to mailto: pattern 
    1802                 $params['body'] = eregi_replace("<a href=\"javascript:new_message_to\('([^>]+)'\)\">[^>]+</a>","<a href='mailto:\\1'>\\1</a>",$params['body']); 
    18031889 
    18041890                $toaddress = implode(',',$db->getAddrs(explode(',',$params['input_to']))); 
     
    19972083            $mail->Certs_crypt = $aux_mails; 
    19982084        } 
    1999  
    2000 //////////////////////////////////////////////////////////////////////////////////////////////////// 
    2001                 //      Build CID for embedded Images!!! 
    2002                 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU'; 
    2003                 $cid_imgs = ''; 
    2004                 $name_cid_files = array(); 
    2005                 preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); 
    2006                 $cid_array = array(); 
    2007                 foreach($cid_imgs[6] as $j => $val){ 
    2008                                 if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) ) 
    2009                         { 
    2010                 $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); 
    2011                         } 
    2012                         $cid = $cid_array[$cid_imgs[4][$j].$val]; 
    2013                         $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 
    2014  
    2015                                 if (!$forwarding_attachments[$cid_imgs[6][$j]-2]) // The image isn't in the same mail? 
    2016                                 { 
    2017                                         $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); 
    2018                                         $fileName = "image_".($j).".jpg"; 
    2019                                         $fileCode = "base64"; 
    2020                                         $fileType = "image/jpg"; 
    2021                                 } 
    2022                                 else 
    2023                                 { 
    2024                                         $attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2]; 
    2025                                         $file_description = unserialize(rawurldecode($attach_img)); 
    2026  
    2027                                         foreach($file_description as $i => $descriptor){ 
    2028                                                 $file_description[$i]  = eregi_replace('\'*\'','',$descriptor); 
    2029                                         } 
    2030                                         $fileContent = $this->get_forwarding_attachment($file_description[0], $cid_imgs[4][$j], $file_description[3], 'base64'); 
    2031                                         $fileName = $file_description[2]; 
    2032                                         $fileCode = $file_description[4]; 
    2033                                         $fileType = $this->get_file_type($file_description[2]); 
    2034                                         unset($forwarding_attachments[$cid_imgs[6][$j]-2]); 
    2035                                 } 
    2036                                 $tempDir = ini_get("session.save_path"); 
    2037                                 $file = "cidimage_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].$cid_imgs[6][$j].".dat"; 
    2038                                 $f = fopen($tempDir.'/'.$file,"w"); 
    2039                                 fputs($f,$fileContent); 
    2040                                 fclose($f); 
    2041                                 if ($fileContent) 
    2042                                         $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); 
    2043                                 //else 
    2044                                 //      return "Error loading image attachment content"; 
    2045  
    2046                 } 
    2047 //////////////////////////////////////////////////////////////////////////////////////////////////// 
     2085                // Build CID images  
     2086                $this->buildEmbeddedImages($mail,$msg_uid,$forwarding_attachments);  
     2087 
    20482088                //      Build Uploading Attachments!!! 
    20492089                if ((count($attachments)) && ($params['is_local_forward']!="1")) //Caso seja forward normal... 
     
    20802120                { 
    20812121                        // Bug fixed for array_search function 
     2122                        $name_cid_files = array();  
    20822123                        if(count($name_cid_files) > 0) { 
    20832124                                $name_cid_files[count($name_cid_files)] = $name_cid_files[0]; 
     
    21422183                } 
    21432184        } 
    2144  
    2145     function add_recipients_cert($full_address) 
     2185        function buildEmbeddedImages(&$mail,$msg_uid,&$forwarding_attachments)  
     2186        {  
     2187                //      Build CID for embedded Images!!!  
     2188                $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU';  
     2189                $cid_imgs = '';  
     2190                preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER);  
     2191                $cid_array = array();  
     2192                foreach($cid_imgs[6] as $j => $val){  
     2193                        if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) )  
     2194                        {  
     2195                                $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36);  
     2196                        }  
     2197                        $cid = $cid_array[$cid_imgs[4][$j].$val];   
     2198                        $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body);  
     2199 
     2200                        if ($msg_uid != $cid_imgs[4][$j]) // The image is not in the same mail?  
     2201                        {  
     2202                                $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64');  
     2203                                //prototype: get_forwarding_attachment ( folder, msg number, part, encoding)  
     2204                                $fileName = "image_".($j).".jpg";  
     2205                                $fileCode = "base64";  
     2206                                $fileType = "image/jpg";  
     2207                                $file_attached[0] = $cid_imgs[2][$j];  
     2208                                $file_attached[1] = $cid_imgs[4][$j];  
     2209                                $file_attached[2] = $fileName;  
     2210                                $file_attached[3] = $cid_imgs[6][$j];  
     2211                                $file_attached[4] = 'base64';  
     2212                                $file_attached[5] = strlen($fileContent); //Size of file  
     2213                                $return_forward[] = $file_attached;  
     2214 
     2215                                $attachment_ = unserialize(rawurldecode($forwarding_attachments[$cid_imgs[6][$j]-2]));  
     2216                                if ($file_attached[3] == $attachment_[3])  
     2217                                        unset($forwarding_attachments[$cid_imgs[6][$j]-2]);      
     2218                        }  
     2219                        else  
     2220                        {  
     2221                                $attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2];  
     2222                                $file_description = unserialize(rawurldecode($attach_img));  
     2223                                if (is_array($file_description))  
     2224                                        foreach($file_description as $i => $descriptor){                                  
     2225                                                $file_description[$i]  = eregi_replace('\'*\'','',$descriptor);  
     2226                                        }  
     2227                                $fileContent = $this->get_forwarding_attachment($file_description[0], $msg_uid, $file_description[3], 'base64');  
     2228                                $fileName = $file_description[2];  
     2229                                $fileCode = $file_description[4];  
     2230                                $fileType = $this->get_file_type($file_description[2]);  
     2231                                unset($forwarding_attachments[$cid_imgs[6][$j]-2]);  
     2232                                if (!empty($file_description))  
     2233                                {  
     2234                                        $file_description[5] = strlen($fileContent); //Size of file  
     2235                                        $return_forward[] = $file_description;  
     2236                                }  
     2237                        }  
     2238                        $tempDir = ini_get("session.save_path");  
     2239                        $file = "cidimage_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].$cid_imgs[6][$j].".dat";                                         
     2240                        $f = fopen($tempDir.'/'.$file,"w");  
     2241                        fputs($f,$fileContent);  
     2242                        fclose($f);  
     2243                        if ($fileContent)  
     2244                                $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType);  
     2245                        //else  
     2246                        //      return "Error loading image attachment content";                                                  
     2247 
     2248                }  
     2249                return $return_forward;  
     2250        }  
     2251        function add_recipients_cert($full_address) 
    21462252        { 
    21472253                $result = ""; 
     
    25122618                $mail->Body = $body; 
    25132619 
    2514                 //      Build CID for embedded Images!!! 
    2515                 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU'; 
    2516                 $cid_imgs = ''; 
    2517                 $name_cid_files = array(); 
    2518                 preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); 
    2519                 $cid_array = array(); 
    2520                 foreach($cid_imgs[6] as $j => $val){ 
    2521                                 if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) ) 
    2522                         { 
    2523                 $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); 
    2524                         } 
    2525                         $cid = $cid_array[$cid_imgs[4][$j].$val]; 
    2526                         $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 
    2527  
    2528                                 if ($msg_uid != $cid_imgs[4][$j]) // The image isn't in the same mail? 
    2529                                 { 
    2530                                         $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); 
    2531                                         //prototype: get_forwarding_attachment ( folder, msg number, part, encoding) 
    2532                                         $fileName = "image_".($j).".jpg"; 
    2533                                         $fileCode = "base64"; 
    2534                                         $fileType = "image/jpg"; 
    2535                                         $file_attached[0] = $cid_imgs[2][$j]; 
    2536                                         $file_attached[1] = $cid_imgs[4][$j]; 
    2537                                         $file_attached[2] = $fileName; 
    2538                                         $file_attached[3] = $cid_imgs[6][$j]; 
    2539                                         $file_attached[4] = 'base64'; 
    2540                                         $file_attached[5] = strlen($fileContent); //Size of file 
    2541                                         $return_forward[] = $file_attached; 
    2542                                 } 
    2543                                 else 
    2544                                 { 
    2545                                         $attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2]; 
    2546                                         $file_description = unserialize(rawurldecode($attach_img)); 
    2547                                         foreach($file_description as $i => $descriptor){ 
    2548                                                 $file_description[$i]  = eregi_replace('\'*\'','',$descriptor); 
    2549                                         } 
    2550                                         $fileContent = $this->get_forwarding_attachment($file_description[0], $msg_uid, $file_description[3], 'base64'); 
    2551                                         $fileName = $file_description[2]; 
    2552                                         $fileCode = $file_description[4]; 
    2553                                         $fileType = $this->get_file_type($file_description[2]); 
    2554                                         unset($forwarding_attachments[$cid_imgs[6][$j]-2]); 
    2555                                         if (!empty($file_description)) 
    2556                                         { 
    2557                                                 $file_description[5] = strlen($fileContent); //Size of file 
    2558                                                 $return_forward[] = $file_description; 
    2559                                         } 
    2560                                 } 
    2561                                 $tempDir = ini_get("session.save_path"); 
    2562                                 $file = "cidimage_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].$cid_imgs[6][$j].".dat"; 
    2563                                 $f = fopen($tempDir.'/'.$file,"w"); 
    2564                                 fputs($f,$fileContent); 
    2565                                 fclose($f); 
    2566                                 if ($fileContent) 
    2567                                         $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); 
    2568                                 //else 
    2569                                 //      return "Error loading image attachment content"; 
    2570  
    2571                 } 
     2620                $return_forward = $this->buildEmbeddedImages($mail,$msg_uid,$forwarding_attachments);  
    25722621 
    25732622        //      Build Forwarding Attachments!!! 
     
    31593208                $criteria =  'BEFORE "'.$before_date.'"'; 
    31603209                $mbox_stream = $this->open_mbox('INBOX'.$this->imap_delimiter.$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']); 
     3210                // Free others requests  
     3211                session_write_close();  
    31613212                $messages = imap_search($mbox_stream, $criteria, SE_UID); 
    31623213                if (is_array($messages)){ 
     
    32013252 
    32023253        function search_msg($params = ''){ 
    3203             $retorno = ""; 
    32043254            $mbox_stream = ""; 
    32053255            if(strpos($params['condition'],"#")===false) { //local messages 
     
    32803330                                foreach($search_criteria as $new_search) 
    32813331                                { 
     3332                                    $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream);  
     3333                                    $elem['boxname'] = mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" );  
     3334                                    $elem['uid'] = $new_search;  
     3335                                    $retorno[] = $elem;  
     3336 
     3337                                    /* NOTE: This code was lost on 2.2 merge  
    32823338                                    if ($search_result_number != '65536' && $sum == $search_result_number) 
    32833339                                    { 
     
    32903346                                        $retorno .= $m_token; 
    32913347                                        $sum ++; 
    3292                                     } 
     3348                                    } 
     3349                                     */ 
    32933350                                } 
    32943351                            } 
     
    33003357                        { 
    33013358                            foreach($search_criteria as $new_search) 
    3302                             { 
    3303                                 if ($search_result_number != '65536' && $sum == $search_result_number) 
     3359                            { 
     3360                                    $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream);  
     3361                                    $elem['boxname'] = mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" );  
     3362                                    $elem['uid'] = $new_search;  
     3363                                    $retorno[] = $elem;  
     3364                                //  NOTE: This code was lost on 2.2 merge  
     3365                                /*if ($search_result_number != '65536' && $sum == $search_result_number) 
    33043366                                { 
    33053367                                    return $retorno ? $sum . "=sumResults=" . $retorno : "none"; 
    33063368                                } 
    33073369                                $retorno .= trim("##".mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--" . $new_search."##"."\n"); 
    3308                                 $sum++; 
     3370                                $sum++;*/ 
    33093371                            } 
    33103372                        } 
     
    33273389        } 
    33283390 
    3329         function get_msg($uid_msg,$name_box, $mbox_stream ) 
     3391        function get_msg_detail($uid_msg,$name_box, $mbox_stream ) 
    33303392        { 
    33313393                $header = $this->get_header($uid_msg); 
    3332                 include_once("class.imap_attachment.inc.php"); 
     3394                require_once("class.imap_attachment.inc.php"); 
    33333395                $imap_attachment = new imap_attachment(); 
    33343396                $attachments =  $imap_attachment->get_attachment_headerinfo($mbox_stream, $uid_msg); 
     
    33473409                if($header->from[0]->personal != "") 
    33483410                        $from = $header->from[0]->personal; 
    3349                 $ret_msg = $this->decode_string($from) . "--" . $subject . "--". gmdate("d/m/Y",$header ->udate)."--". $this->size_msg($header->Size) ."--". $flag; 
     3411                $ret_msg['from'] = $this->decode_string($from);  
     3412                $ret_msg['subject'] = $subject;  
     3413                $ret_msg['udate'] = $header ->udate;  
     3414                $ret_msg['size'] = $header->Size;  
     3415                $ret_msg['flag'] = $flag;  
    33503416                return $ret_msg; 
    33513417        } 
    3352  
    3353         function size_msg($size){ 
    3354                 $var = floor($size/1024); 
    3355                 if($var >= 1){ 
    3356                         return $var." kb"; 
    3357                 }else{ 
    3358                         return $size ." b"; 
    3359                 } 
    3360         } 
    3361  
    33623418        function ob_array($the_object) 
    33633419        { 
Note: See TracChangeset for help on using the changeset viewer.