validations.php File Reference

Go to the source code of this file.

Functions


Function Documentation

tep_validate_email_inclus ( email  ) 

Definition at line 42 of file validations.php.

Referenced by tep_validate_email().

00042                                            {
00043   $valid_address = true;
00044 
00045   $mail_pat = '^(.+)@(.+)$';
00046   $valid_chars = "[^] \(\)<>@,;:\.\\\"\[]";
00047   $atom = "$valid_chars+";
00048   $quoted_user='(\"[^\"]*\")';
00049   $word = "($atom|$quoted_user)";
00050   $user_pat = "^$word(\.$word)*$";
00051   $ip_domain_pat='^\[([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\]$';
00052   $domain_pat = "^$atom(\.$atom)*$";
00053 
00054   if (preg_match('/'.$mail_pat.'/i', $email, $components)) {
00055     $user = $components[1];
00056     $domain = $components[2];
00057     // validate user
00058     if (preg_match('/'.$user_pat.'/i', $user)) {
00059       // validate domain
00060       if (preg_match('/'.$ip_domain_pat.'/i', $domain, $ip_components)) {
00061         // this is an IP address
00062         for ($i=1;$i<=4;$i++) {
00063           if ($ip_components[$i] > 255) {
00064             $valid_address = false;
00065             break;
00066           }
00067         }
00068       }
00069       else {
00070         // Domain is a name, not an IP
00071         if (preg_match('/'.$domain_pat.'/i', $domain)) {
00072           /* domain name seems valid, but now make sure that it ends in a valid TLD or ccTLD
00073               and that there's a hostname preceding the domain or country. */
00074           $domain_components = explode(".", $domain);
00075           // Make sure there's a host name preceding the domain.
00076           if (sizeof($domain_components) < 2) {
00077             $valid_address = false;
00078           } else {
00079             $top_level_domain = strtolower($domain_components[sizeof($domain_components)-1]);
00080             // Allow all 2-letter TLDs (ccTLDs)
00081             if (preg_match('/^[a-z][a-z]$/i', $top_level_domain) != 1) {
00082               $tld_pattern = '';
00083               // Get authorized TLDs from text file
00084               $tlds = file(DIR_WS_INCLUDES . 'tld.txt');
00085               while (list(,$line) = each($tlds)) {
00086                 // Get rid of comments
00087                 $words = explode('#', $line);
00088                 $tld = trim($words[0]);
00089                 // TLDs should be 3 letters or more
00090                 if (preg_match('/^[a-z]{3,}$/i', $tld) == 1) {
00091                   $tld_pattern .= '^' . $tld . '$|';
00092                 }
00093               }
00094               // Remove last '|'
00095               $tld_pattern = substr($tld_pattern, 0, -1);
00096               if (preg_match("/$tld_pattern/i", $top_level_domain) == 0) {
00097                   $valid_address = false;
00098               }
00099             }
00100           }
00101         }
00102         else {
00103           $valid_address = false;
00104         }
00105       }
00106     }
00107     else {
00108       $valid_address = false;
00109     }
00110   }
00111   else {
00112     $valid_address = false;
00113   }
00114   if ($valid_address && _cst_bool('ENTRY_EMAIL_ADDRESS_CHECK')) {
00115     if (!checkdnsrr($domain, "MX") && !checkdnsrr($domain, "A")) {
00116       $valid_address = false;
00117     }
00118   }
00119   return $valid_address;
00120 }