next_token; } for($character=0;$characternext_token=substr($string,$found+1); return(substr($string,0,$found)); } else { $this->next_token=""; return($string); } } Function OutputDebug($message) { $message.="\n"; if($this->html_debug) $message=str_replace("\n","
\n",HtmlEntities($message)); echo $message; flush(); } Function GetLine($connection) { for($line="";;) { if(feof($connection)) return(0); $line.=fgets($connection,100); $length=strlen($line); if($length>=2 && substr($line,$length-2,2)=="\r\n") { $line=substr($line,0,$length-2); if($this->debug) $this->OutputDebug("S $line"); return($line); } } } Function PutLine($connection,$line) { if($this->debug) $this->OutputDebug("C $line"); return(fputs($connection,"$line\r\n")); } Function ValidateEmailAddress($email) { return(eregi($this->email_regular_expression,$email)!=0); } Function ValidateEmailHost($email,&$hosts) { if(!$this->ValidateEmailAddress($email)) return(0); $user=$this->Tokenize($email,"@"); $domain=$this->Tokenize(""); $hosts=$weights=array(); $getmxrr=$this->getmxrr; if(function_exists($getmxrr) && $getmxrr($domain,$hosts,$weights)) { $mxhosts=array(); for($host=0;$hostexclude_address)==0 || strcmp(@gethostbyname($this->exclude_address),$ip))) $hosts[]=$domain; } return(count($hosts)!=0); } Function VerifyResultLines($connection,$code) { while(($line=$this->GetLine($connection))) { if(!strcmp($this->Tokenize($line," "),$code)) return(1); if(strcmp($this->Tokenize($line,"-"),$code)) return(0); } return(-1); } Function ValidateEmailBox($email) { if(!$this->ValidateEmailHost($email,$hosts)) return(0); if(!strcmp($localhost=$this->localhost,"") && !strcmp($localhost=getenv("SERVER_NAME"),"") && !strcmp($localhost=getenv("HOST"),"")) $localhost="localhost"; if(!strcmp($localuser=$this->localuser,"") && !strcmp($localuser=getenv("USERNAME"),"") && !strcmp($localuser=getenv("USER"),"")) $localuser="root"; for($host=0;$hostdebug) $this->OutputDebug("Resolving host name \"".$hosts[$host]."\"..."); if(!strcmp($ip=@gethostbyname($domain),$domain)) { $this->OutputDebug("Could not resolve host name \"".$hosts[$host]."\"."); continue; } } if(strlen($this->exclude_address) && !strcmp(@gethostbyname($this->exclude_address),$ip)) { $this->OutputDebug("Host address of \"".$hosts[$host]."\" is the exclude address"); continue; } if($this->debug) $this->OutputDebug("Connecting to host address \"".$ip."\"..."); if(($connection=($this->timeout ? @fsockopen($ip,25,$errno,$error,$this->timeout) : @fsockopen($ip,25)))) { if($this->debug) $this->OutputDebug("Connected."); if($this->VerifyResultLines($connection,"220")>0 && $this->PutLine($connection,"HELO $localhost") && $this->VerifyResultLines($connection,"250")>0 && $this->PutLine($connection,"MAIL FROM: <$localuser@$localhost>") && $this->VerifyResultLines($connection,"250")>0 && $this->PutLine($connection,"RCPT TO: <$email>") && ($result=$this->VerifyResultLines($connection,"250"))>=0) { if($this->debug) $this->OutputDebug("This host states that the address is ".($result ? "" : "not ")."valid."); fclose($connection); if($this->debug) $this->OutputDebug("Disconnected."); return($result); } if($this->debug) $this->OutputDebug("Unable to validate the address with this host."); fclose($connection); if($this->debug) $this->OutputDebug("Disconnected."); } else { if($this->debug) $this->OutputDebug("Failed."); } } return(-1); } }; ?>