Index: /trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 4781)
+++ /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 4784)
@@ -1218,5 +1218,5 @@
 										$content = str_replace(array('<', '>'), array(' #$<$# ', ' #$>$# '), $content);
                                         $content = htmlentities($content);
-                                        $content = $this -> replace_links($content);
+                                        $this->replace_links($content);
                                         $content = str_replace(array(' #$&lt;$# ', ' #$&gt;$# '), array('&lt;', '&gt;'), $content);
                                         $content = '<pre>' . $content . '</pre>';
@@ -1523,4 +1523,15 @@
 	
 	
+	function replace_links_callback($matches)  
+ 	{ 
+		if($matches[3]) 
+			$pref = $matches[3]; 
+ 	    else 
+			$pref = $matches[3] = 'http'; 
+ 	        
+ 	    return '<a href="'.$pref.'://'.$matches[4].$matches[5].'" target="_blank">'.$matches[4].$matches[5].'</a>'; 
+ 	} 
+	
+	
 	/**
 	* @license   http://www.gnu.org/copyleft/gpl.html GPL
@@ -1530,71 +1541,15 @@
 	function replace_links(&$body)
    	{
-		// Domains and IPs addresses found in the text and which is not a link yet should be replaced by one.
-		// See more informations in www.iana.org
-		$octets = array(
-			'first' => '(2[0-3][0-9]|1[0-9]{2}|[1-9][0-9]?)',
-			'middle' => '(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})',
-			'last' => '(25[0-4]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)'
-		);
-
-		$ip = "\b{$octets[ 'first' ]}\.({$octets[ 'middle' ]}\.){2}{$octets[ 'last' ]}\b";
-
-		$top_level_domains = '(\.(ac|ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|as|asia|at|au|aw|ax|az|'
-			. 'ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bl|bm|bn|bo|br|bs|bt|bv|bw|by|bz|'
-			. 'ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cu|cv|cx|cy|cz|'
-			. 'de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|'
-			. 'ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|'
-			. 'hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir|is|it|je|jm|jo|jobs|jp|'
-			. 'ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|'
-			. 'ma|mc|md|me|mf|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|'
-			. 'mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|'
-			. 'pa|pe|pf|pg|ph|pk|pl|pm|pn|pro|ps|pt|pw|py|qa|re|ro|rs|ru|rw|'
-			. 'sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|'
-			. 'tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|travel|tt|tv|tw|tz|'
-			. 'ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw))+\b';
-		
-		$path = '(?>\/[\w\d\/\.\'\(\)\-\+~?!&#@$%|:;,*=_]+)?';
-		$port = '(?>:\d{2,5})?';
-		$domain = '(?>[\w\d_\-]+)';
-		$subdomain = "(?>{$domain}\.)*";
-		$protocol = '(?>(http|ftp)(s)?:\/\/)?';
-		$url = "(?>{$protocol}((?>{$subdomain}{$domain}{$top_level_domains}|{$ip}){$port}{$path}))";
-
-		$pattern = "/(<\w[^>]+|[\/\"'@=])?{$url}/";
-		
-		ini_set( 'pcre.backtrack_limit', 300000 );
-		/*
-		// PHP 5.3
-		$replace = function( $matches )
-		{
-			if ( $matches[ 1 ] )
-				return $matches[ 0 ];
-
-			$url = ( $matches[ 2 ] ) ? $matches[ 2 ] : 'http';
-			$url .= "{$matches[ 3 ]}://{$matches[ 4 ]}";
-			return "<a href=\"{$url}\" target=\"_blank\">{$matches[ 4 ]}</a>";
-		};
-		$body = preg_replace_callback( $pattern, $replace, $body );
-		*/
-
-		// PHP 5.2.x - Remover assim que possível
-		$body = preg_replace_callback( $pattern,
-			create_function(
-				'$matches',
-				'if ( $matches[ 1 ] ) return $matches[ 0 ];'
-					. '$url = ( $matches[ 2 ] ) ? $matches[ 2 ] : "http";'
-					. '$url .= "{$matches[ 3 ]}://{$matches[ 4 ]}";'
-					. 'return "<a href=\"{$url}\" target=\"_blank\">{$matches[ 4 ]}</a>";'
-			), $body
-		);
-		ini_set( 'pcre.backtrack_limit', 100000 );
-
-		// E-mail address in the text should create a new e-mail on ExpressoMail
-		$pattern = '/( |<|&lt;|>)([A-Za-z0-9\.~?\/_=#\-]*@[A-Za-z0-9\.~?\/_=#\-]*)( |>|&gt;|<)/im';
-		$replacement = '$1<a href="mailto:$2">$2</a>$3';
-		$body = preg_replace( $pattern, $replacement, $body );
-
-		return $body;
-	}
+		// Trata urls do tipo aaaa.bbb.empresa  
+		// Usadas na intranet.  
+		$pattern = '/(?<=[\s|(<br>)|\n|\r|;])(((http|https|ftp|ftps)?:\/\/((?:[\w]\.?)+(?::[\d]+)?[:\/.\-~&=?%;@#,+\w]*))|((?:www?\.)(?:\w\.?)*(?::\d+)?[\:\/\w.\-~&=?%;@+]*))/i';     
+		$replacement = '<a href="://$4$5" target="_blank">$4$5</a>'; 
+ 	    $body = preg_replace_callback($pattern,array( &$this, 'replace_links_callback'), $body);
+		// E-mail address in the text should create a new e-mail on ExpressoMail  
+		$pattern = '/( |<|&lt;|>)([A-Za-z0-9\.~?\/_=#\-]*@[A-Za-z0-9\.~?\/_=#\-]*)( |>|&gt;|<)/im'; 
+		$replacement = '$1<a href="mailto:$2">$2</a>$3'; 
+		$body = preg_replace($pattern, $replacement, $body); 
+ 		             
+	} 
 
 	function get_signature($msg, $msg_number, $msg_folder)
