Changeset 2069


Ignore:
Timestamp:
02/25/10 11:34:37 (14 years ago)
Author:
rodsouza
Message:

Ticket #788 - Alterada busca de dominio e ip no e-mail. Aceita apenas dominio e ips validos.

File:
1 edited

Legend:

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

    r2060 r2069  
    11931193                $body = preg_replace( $pattern, $replacement, $body ); 
    11941194 
    1195                 // Url found in the text and which is not a link yet should be replaced by one. 
    1196                 $validTLD = 'AERO|ARPA|ASIA|BIZ|CAT|COM|COOP|EDU|GOV|INFO|INT|JOBS|MIL|MOBI' 
    1197                         .'|MUSEUM|NAME|NET|ORG|PRO|TEL|TRAVEL|BR|UK|US|AR|CU|CN|ID|IN|JP|MX|DE|FR|IT|KR|ES|RU'; 
    1198                 $pattern = '/(^| |[\w"]>|[ \(\[])'. // find begin of url 
    1199                         '((http(s)?:\/\/)?'. // Http or not 
    1200                         '((([0-9a-z_!~*\'().&=+$%-]+:)?[0-9a-z_!~*\'().&=+$%-]+@)?'. // can contain user@ 
    1201                         '(((1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])|'. //can be ipv4 
    1202                         '([0-9a-z_-]+\.)*'. //name of subdomain 
    1203                         '([0-9a-z][0-9a-z-]{0,61})?'. // name of domain 
    1204                         '\.('.$validTLD.'))'. // top level domain 
    1205                         '(:[0-9]{1,4})?'. // server port 
    1206                         '((\/[0-9a-z_!~*\'\(\).;?:@&=+$,%#-]+)*\/?)))/im'; //url params 
    1207                 $replacement = '$1<a href="http$4://$5" target="_blank">$2</a>'; 
    1208                 $body = preg_replace( $pattern, $replacement, $body ); 
     1195                // Domains and IPs addresses found in the text and which is not a link yet should be replaced by one. 
     1196                // See more informations in www.iana.org 
     1197                $octets = array( 
     1198                        'first' => '(2[0-3][0-9]|1[0-9]{2}|[1-9][0-9]?)', 
     1199                        'middle' => '(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})', 
     1200                        'last' => '(25[0-4]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)' 
     1201                ); 
     1202 
     1203                $ip = "\b{$octets[ 'first' ]}\.({$octets[ 'middle' ]}\.){2}{$octets[ 'last' ]}\b"; 
     1204 
     1205                $top_level_domains = '(\.(ac|ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|as|asia|at|au|aw|ax|az|' 
     1206                        . 'ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bl|bm|bn|bo|br|bs|bt|bv|bw|by|bz|' 
     1207                        . 'ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cu|cv|cx|cy|cz|' 
     1208                        . 'de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|' 
     1209                        . 'ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|' 
     1210                        . 'hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir|is|it|je|jm|jo|jobs|jp|' 
     1211                        . 'ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|' 
     1212                        . 'ma|mc|md|me|mf|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|' 
     1213                        . 'mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|' 
     1214                        . 'pa|pe|pf|pg|ph|pk|pl|pm|pn|pro|ps|pt|pw|py|qa|re|ro|rs|ru|rw|' 
     1215                        . 'sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|' 
     1216                        . 'tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|travel|tt|tv|tw|tz|' 
     1217                        . 'ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw))+\b'; 
     1218 
     1219                $path = '(?>\/[\w\d~?\/_=&#;\.\-\+:@$%]+)?'; 
     1220                $port = '(?>:\d{2,4})?'; 
     1221                $domain = '(?>[\w\d_\-]+)'; 
     1222                $subdomain = "(?>{$domain}\.)*"; 
     1223                $protocol = '(?>(http|ftp)(s)?:\/\/)?'; 
     1224                $url = "(?>{$protocol}((?>{$subdomain}{$domain}{$top_level_domains}|{$ip}){$port}{$path}))"; 
     1225 
     1226                $pattern = "/(@|=|(?>url\( *)?['\"])?{$url}/"; 
     1227                $pattern = "/(@|=|url\( *['\"]?|['\"])?{$url}/"; 
     1228                $pattern = "/(url\( *['\"]?|['\"@=])?{$url}/"; 
     1229 
     1230                $replace = function( $matches ) 
     1231                { 
     1232                        //echo "\n--------------------------------------\n"; 
     1233                        //print_r( $matches ); 
     1234                        //return ''; 
     1235                        if ( $matches[ 1 ] ) 
     1236                                return $matches[ 0 ]; 
     1237 
     1238                        //print_r( $matches ); 
     1239                        $url = ( $matches[ 2 ] ) ? $matches[ 2 ] : 'http'; 
     1240                        $url .= "{$matches[ 3 ]}://{$matches[ 4 ]}"; 
     1241                        return "<a href=\"{$url}\" target=\"_blank\">{$matches[ 4 ]}</a>"; 
     1242                }; 
     1243                $body = preg_replace_callback( $pattern, $replace, $body ); 
    12091244 
    12101245                // E-mail address in the text should create a new e-mail on ExpressoMail 
Note: See TracChangeset for help on using the changeset viewer.