aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-01-19 20:35:43 +0000
committerMario <mario@mariovavti.com>2024-01-19 20:35:43 +0000
commit00d403e729a1139a2c4f8b1fcbbcf75c69858023 (patch)
treef57bb086bfbc5ce211010e353e6aae708bbe84e2 /include
parentd83e2daf36da64b8222b37ff63a278f189a1b59f (diff)
parent403539919a9a5b1e3e2ac9725a3b8b17403b2935 (diff)
downloadvolse-hubzilla-00d403e729a1139a2c4f8b1fcbbcf75c69858023.tar.gz
volse-hubzilla-00d403e729a1139a2c4f8b1fcbbcf75c69858023.tar.bz2
volse-hubzilla-00d403e729a1139a2c4f8b1fcbbcf75c69858023.zip
Merge branch 'improve-validate-email' into 'dev'
Improve validate_email function See merge request hubzilla/core!2088
Diffstat (limited to 'include')
-rw-r--r--include/network.php27
1 files changed, 17 insertions, 10 deletions
diff --git a/include/network.php b/include/network.php
index f5c5303b3..c5411e702 100644
--- a/include/network.php
+++ b/include/network.php
@@ -591,23 +591,30 @@ function validate_url(&$url) {
}
/**
- * @brief Checks that email is an actual resolvable internet address.
+ * @brief Checks that email is valid, and that the domain resolves.
*
- * @param string $addr
- * @return boolean
+ * Note: This does not try to check that the actual email address will resolve,
+ * only the domain!
+ *
+ * @param string $addr The email address to validate.
+ * @return boolean True if email is valid, false otherwise.
*/
-function validate_email($addr) {
+function validate_email(string $addr): bool {
if(get_config('system', 'disable_email_validation'))
return true;
- if(! strpos($addr, '@'))
- return false;
-
- $h = substr($addr, strpos($addr, '@') + 1);
+ $matches = array();
+ $result = preg_match(
+ '/^[A-Z0-9._%-]+@([A-Z0-9.-]+\.[A-Z0-9-]{2,})$/i',
+ punify($addr),
+ $matches);
- if(($h) && z_dns_check($h, true)) {
- return true;
+ if($result) {
+ $domain = $matches[1];
+ if(($domain) && z_dns_check($domain, true)) {
+ return true;
+ }
}
return false;