<?php

class UBB_MAIL extends UBB
{
	var $allow1 = array('EMPTY', 'STRING');
	var $allow2 = 'MAIL';
	
	var $info = array('Name'=>'MAIL', 'Version'=>'1.0', 'Info'=>'Create a link to a e-mailaddress that is spambotsafe');
	
	var $ext_types = array('MAIL' => '[a-zA-Z0-9_\.]+\@[a-zA-Z0-9_]+\.[a-zA-Z0-9]+');
	
	function process($value1, $value2)
	{
		$ret = "<a href='mailto:";
		$safe_address = "";
		
		for($i=0; $i<strlen($value2); $i++)
		{
			$char = substr($value2, $i, 1);
			
			$convert = (rand(0, 5)<=2);
			if ((ord($char)>=ord('0') && ord($char)<=ord('9'))
				or ($char == '@'))
				$convert = true;
			
			//convert if char is @, chances are ok, or it is a number (which gives problems)
			if ($convert)
				$safe_address.="&#".ord($char);
			else
				$safe_address.=$char;
		}
		
		$ret.="$safe_address'>";
		if ($value1 == '')
			$ret.=$safe_address;
		else
			$ret.=$value1;
		$ret.="</a>";
		
		return $ret;
	}
}

?>