Loading includes/common.inc +7 −1 Changes for includes/common.inc: 7 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -1278,6 +1278,10 @@ function fix_gpc_magic() { * * This uses the * @link http://php.net/manual/filter.filters.validate.php PHP e-mail validation filter. @endlink * However, a module may override this by implementing * hook_valid_email_address_alter(&$valid, $mail). * * @see hook_valid_email_address_alter() * * @param $mail * A string containing an e-mail address. Loading @@ -1286,7 +1290,9 @@ function fix_gpc_magic() { * TRUE if the address is in a valid format. */ function valid_email_address($mail) { return (bool)filter_var($mail, FILTER_VALIDATE_EMAIL); $valid = (bool) filter_var($mail, FILTER_VALIDATE_EMAIL); drupal_alter('valid_email_address', $valid, $mail); return $valid; } /** Loading modules/system/system.api.php +27 −0 Changes for modules/system/system.api.php: 27 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -4817,6 +4817,33 @@ function hook_filetransfer_info_alter(&$filetransfer_info) { } } /** * Alter core e-mail validation. * * This hook is called immediately after core e-mail validation takes place and * gives other modules a chance to override it. This is useful in cases where * you want to have stricter or looser validation standards than that provided * by Drupal core. * * @param $valid * Boolean value referencing the validation result. * * @param $mail * E-mail address being validated. * * @see valid_email_address() */ function hook_valid_email_address_alter(&$valid, $mail) { if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $mail)) { list($username, $domain) = explode('@', $mail); // Check DNS records. if (checkdnsrr($domain, 'MX')) { $valid = TRUE; } } $valid = FALSE; } /** * @} End of "addtogroup hooks". */ Loading modules/user/tests/user_email_validation_test.info 0 → 100644 +6 −0 Changes for modules/user/tests/user_email_validation_test.info: 6 added lines, 0 removed lines. Original line number Diff line number Diff line name = "User module e-mail validation tests" description = "Support module for user e-mail validation testing." package = Testing version = VERSION core = 7.x hidden = TRUE modules/user/tests/user_email_validation_test.module 0 → 100644 +17 −0 Changes for modules/user/tests/user_email_validation_test.module: 17 added lines, 0 removed lines. Original line number Diff line number Diff line <?php /** * @file * Dummy module implementing hook_valid_email_address_alter. */ /** * Implements hook_valid_email_address_alter(). */ function user_email_validation_test_valid_email_address_alter(&$valid, $mail) { $local = '.local'; // Invalidate all e-mails ending with .local. if (substr_compare($mail, $local, -strlen($local)) === 0) { $valid = FALSE; } } modules/user/user.test +11 −0 Changes for modules/user/user.test: 11 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -308,6 +308,17 @@ class UserValidationTestCase extends DrupalWebTestCase { $this->$test($result, $description . ' (' . $name . ')'); } } // Test altered e-mail validation. function testAlteredMailValidation() { // This e-mail is considered as valid. $mail = 'foo@example.local'; $this->assertNull(user_validate_mail($mail), 'E-mail address is valid.'); // Invalidate all emails ending with .local in alter hook. module_enable(array('user_email_validation_test')); $this->assertNotNull(user_validate_mail($mail), 'E-mail address is invalid.'); } } /** Loading Loading
includes/common.inc +7 −1 Changes for includes/common.inc: 7 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -1278,6 +1278,10 @@ function fix_gpc_magic() { * * This uses the * @link http://php.net/manual/filter.filters.validate.php PHP e-mail validation filter. @endlink * However, a module may override this by implementing * hook_valid_email_address_alter(&$valid, $mail). * * @see hook_valid_email_address_alter() * * @param $mail * A string containing an e-mail address. Loading @@ -1286,7 +1290,9 @@ function fix_gpc_magic() { * TRUE if the address is in a valid format. */ function valid_email_address($mail) { return (bool)filter_var($mail, FILTER_VALIDATE_EMAIL); $valid = (bool) filter_var($mail, FILTER_VALIDATE_EMAIL); drupal_alter('valid_email_address', $valid, $mail); return $valid; } /** Loading
modules/system/system.api.php +27 −0 Changes for modules/system/system.api.php: 27 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -4817,6 +4817,33 @@ function hook_filetransfer_info_alter(&$filetransfer_info) { } } /** * Alter core e-mail validation. * * This hook is called immediately after core e-mail validation takes place and * gives other modules a chance to override it. This is useful in cases where * you want to have stricter or looser validation standards than that provided * by Drupal core. * * @param $valid * Boolean value referencing the validation result. * * @param $mail * E-mail address being validated. * * @see valid_email_address() */ function hook_valid_email_address_alter(&$valid, $mail) { if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $mail)) { list($username, $domain) = explode('@', $mail); // Check DNS records. if (checkdnsrr($domain, 'MX')) { $valid = TRUE; } } $valid = FALSE; } /** * @} End of "addtogroup hooks". */ Loading
modules/user/tests/user_email_validation_test.info 0 → 100644 +6 −0 Changes for modules/user/tests/user_email_validation_test.info: 6 added lines, 0 removed lines. Original line number Diff line number Diff line name = "User module e-mail validation tests" description = "Support module for user e-mail validation testing." package = Testing version = VERSION core = 7.x hidden = TRUE
modules/user/tests/user_email_validation_test.module 0 → 100644 +17 −0 Changes for modules/user/tests/user_email_validation_test.module: 17 added lines, 0 removed lines. Original line number Diff line number Diff line <?php /** * @file * Dummy module implementing hook_valid_email_address_alter. */ /** * Implements hook_valid_email_address_alter(). */ function user_email_validation_test_valid_email_address_alter(&$valid, $mail) { $local = '.local'; // Invalidate all e-mails ending with .local. if (substr_compare($mail, $local, -strlen($local)) === 0) { $valid = FALSE; } }
modules/user/user.test +11 −0 Changes for modules/user/user.test: 11 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -308,6 +308,17 @@ class UserValidationTestCase extends DrupalWebTestCase { $this->$test($result, $description . ' (' . $name . ')'); } } // Test altered e-mail validation. function testAlteredMailValidation() { // This e-mail is considered as valid. $mail = 'foo@example.local'; $this->assertNull(user_validate_mail($mail), 'E-mail address is valid.'); // Invalidate all emails ending with .local in alter hook. module_enable(array('user_email_validation_test')); $this->assertNotNull(user_validate_mail($mail), 'E-mail address is invalid.'); } } /** Loading