Hi Maciej! On 12.09.2017 at 08:38, Maciej Sobaczewski wrote:
> Hi Christoph, > > I just noticed it and wondering whether usage of filter_var() is safe > here. Either I forgot about something or not all of the PHP.net mirrors > are running 5.4+ so far... Hmm, isn't filter_var/FILTER_VALIDATE_EMAIL supposed to be be available as of 5.2.0? (see <https://3v4l.org/sGKnm>) Cheers, Christoph > Cheers, > Maciej. > > W dniu 17.08.2017 o 18:44, Christoph Michael Becker pisze: >> Commit: 7be864b190c1953c51622893a27a43fc7645c0fa >> Author: Andreas Heigl <[email protected]> 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; >> } >> >> /** >> > -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
