Show
Ignore:
Timestamp:
10/02/09 16:21:40 (3 years ago)
Author:
gbastien
Message:

* Email address format now corresponds to newer standard RFC2822 (#624)
* Corrected typos and tab alignment

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/wifidog/classes/Mail.php

    r1321 r1424  
    411411         * Validates an email address 
    412412         * 
    413          * This function will make sure an e-mail is RFC822 compliant 
     413         * This function will make sure an e-mail is RFC2822 compliant 
    414414         * and is not black listed. 
     415         *  
     416         * The regex was taken from  http://www.regular-expressions.info/email.html 
     417         * Read also http://www.linuxjournal.com/article/9585 for more on email validation 
    415418         * 
    416419         * @param string $mail The email address to validate 
     
    427430 
    428431            // Test if the email address is valid 
    429             $regex = "/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i"; 
    430  
    431             if (preg_match_all($regex, $email, $_matches)) { 
    432                 // If the hostname is black listed, reject the email address 
    433                 $full_hostname = $_matches[2][0] . "." . $_matches[3][0]; 
    434  
    435                 if (!in_array(strtolower($full_hostname), self :: $_hosts_black_list)) { 
    436                     $_retVal = true; 
     432            // $regex = "/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i"; 
     433            // The full regex is  
     434            // /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i 
     435            // We will check it in two parts: domain and local 
     436                                                 
     437            $atIndex = strrpos($email, "@"); 
     438            if ($atIndex !== false) 
     439            { 
     440                $domain = substr($email, $atIndex+1); 
     441                $local = substr($email, 0, $atIndex); 
     442         
     443                // Verify local part 
     444                if (preg_match("/^[a-z0-9!#$%&'*+\\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\\/=?^_`{|}~-]+)*$/i",$local) && 
     445                    preg_match("/^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i",$domain) )  
     446                { 
     447 
     448                    if (!in_array(strtolower($domain), self :: $_hosts_black_list)) { 
     449                        if (checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")) { 
     450                            $_retVal = true; 
     451                        } 
     452                    } 
    437453                } 
    438454            }