com web/php: Adapts the validation to use filter_var: inc lude/email-validation.inc
| From: | Christoph Michael Becker | Date: | Thu, 17 Aug 2017 16:44:27 +0000 |
| Subject: | com web/php: Adapts the validation to use filter_var: inc lude/email-validation.inc | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-26326@lists.php.net to get a copy of this message | ||
Commit: 7be864b190c1953c51622893a27a43fc7645c0fa
Author: Andreas Heigl <andreas@heigl.org> Thu, 17 Aug 2017 18:44:27 +0200
Parents: c716ac3b05262660372bd0af199aec78c140f3ab
Branches: master
Link: http://git.php.net/?p=web/php.git;a=commitdiff;h=7be864b190c1953c51622893a27a43fc7645c0fa
Log:
Adapts the validation to use filter_var
Everything else is then simply refinement
Changed paths:
M include/email-validation.inc
Diff:
diff --git a/include/email-validation.inc b/include/email-validation.inc
index 05b964b..c5b1ca5 100644
--- a/include/email-validation.inc
+++ b/include/email-validation.inc
@@ -12,30 +12,25 @@ function clean_AntiSPAM($email)
// Try to check that this email address is valid
function is_emailable_address($email)
{
+ $email = filter_var($email, FILTER_VALIDATE_EMAIL);
// No email, no validation
- if (empty($email)) {
- return false;
- }
-
- $parts = explode('@', $email);
- // An email-address with more than one '@' can't be valid
- if (count($parts) != 2) {
+ if (! $email) {
return false;
}
+ $host = substr($email, strrpos($email, '@') + 1);
// addresses from our mailing-list servers
- $host_part_regex = "!(lists\.php\.net|chek[^\.*]\.com)!i";
- if (preg_match($host_part_regex, $email)) {
+ $host_regex = "!(lists\.php\.net|chek[^\.*]\.com)!i";
+ if (preg_match($host_regex, $host)) {
return false;
}
// When no MX-Entry can be found it's for sure not a valid email-address.
- if (getmxrr($parts[1], $return_values) === false) {
+ if (getmxrr($host, $return_values) === false) {
return false;
}
- $address_part_regex = ":^([-!#$%&'*+./0-9=?A-Z^_`a-z{|}~ ])+:i";
- return (bool) preg_match($address_part_regex, $parts[0]);
+ return true;
}
/**