diff --git a/include/email-validation.inc b/include/email-validation.inc index 4e4c4136a..7c6939321 100644 --- a/include/email-validation.inc +++ b/include/email-validation.inc @@ -1,187 +1,26 @@ =2 - && substr($line,$length-2,2)=="\r\n") - { - $line=substr($line,0,$length-2); - if($this->debug) - $this->OutputDebug("< $line"); - return($line); - } - } - } - - Function PutLine($connection,$line) - { - if($this->debug) - $this->OutputDebug("> $line"); - return(fputs($connection,"$line\r\n")); - } - - Function ValidateEmailAddress($email) - { - return(eregi($this->email_regular_expression,$email)!=0); - } - - Function ValidateEmailHost($email,$hosts=0) - { - if(!$this->ValidateEmailAddress($email)) - return(0); - $user=strtok($email,"@"); - $domain=strtok(""); - if(GetMXRR($domain,&$hosts,&$weights)) - { - $mxhosts=array(); - for($host=0;$hostGetLine($connection))) - { - if(!strcmp(strtok($line," "),$code)) - return(1); - if(strcmp(strtok($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("Connecting to host \"".$hosts[$host]."\"..."); - if(($connection=($this->timeout ? fsockopen($hosts[$host],25,&$errno,&$error,$this->timeout) : fsockopen($hosts[$host],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); - } else { // Jesus M. Castagnetto - if($this->debug) - $this->OutputDebug("Unable to validate the address with this host."); - fclose($connection); - if($this->debug) - $this->OutputDebug("Disconnected."); - return false; - } - } - else - { - if($this->debug) - $this->OutputDebug("Failed."); - return false; // JMC - } - - } - return(-1); - } -}; - - -// checks that is an *outside* host, and removes the -// SPAM protection, before passing the address to the validation class +// checks that is an *outside* host, and tries to remove anti-SPAM bits function clean_AntiSPAM ($email) { $remove_spam = "[-_]?(NO|I[-_]?HATE|DELETE|REMOVE)[-_]?(THIS)?(ME|SPAM)?[-_]?"; return eregi_replace($remove_spam,"",trim($email)); } -function is_emailable_address( $email, $debug=0 ) { +function is_emailable_address( $email) { $hosts_regex="lists\.php\.net|chek.*\.com"; $excluded_hosts = ereg($hosts_regex,$email); + $email_regex="^([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~ ])+@([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~ ]+\\.)+[a-zA-Z]{2,4}\$"; if (!$excluded_hosts && $email != "") { - $validator = new email_validation_class; - $validator->timeout=10; - $validator->debug=$debug; - return $validator->ValidateEmailBox($email); + return eregi($email_regex, $email); } else { return false; } } - -// test of the validation function -// remove this part once all changes seem to work -/* -$test_add = array ( - "wrong-email-address@lists.php.net","jcastagnetto@yahoo.com", - "some-wrong@asdas.com", "jcastagnetto-NO-SPAM@yahoo.com", - "jcastagnetto@NoSpam-yahoo.com", "jmcastagnetto@chek2.com", - "jcastagnetto-i-hate-spam@NOSPAMyahoo.com", - "asasasd324324@php.net", "jcastagnetto-delete-this-@yahoo.com", - "wrong-address-with@@@@-remove_me-and-some-i-hate_SPAM-stuff"); - -while (list(,$v) = each($test_add)) { - echo "The address: $v (".clean_AntiSpam($v).") is"; - if (!is_emailable_address(clean_AntiSPAM($v))) - echo " not"; - echo " valid\n"; -} -*/ ?>