$v) { if (!self::isValidEmail($v)) { unset($all[$k]); } } /* If at least one is found return the value */ if (count($all)) { if ($return_emails) { return implode(',', $all); } return true; } elseif (!$return_emails) { return false; } } else { /* Make sure people don't try to enter multiple addresses */ $address = str_replace(strstr($address, ','), '', $address); $address = str_replace(strstr($address, ';'), '', $address); $address = trim($address); /* Valid address? */ if (self::isValidEmail($address)) { if ($return_emails) { return $address; } return true; } else { return false; } } //-- We shouldn't get here return false; } // END hesk_validateEmail() /** * @param $email * @return bool */ static function isValidEmail($email) { /* Check for header injection attempts */ if (preg_match("/\r|\n|%0a|%0d/i", $email)) { return false; } /* Does it contain an @? */ $atIndex = strrpos($email, "@"); if ($atIndex === false) { return false; } /* Get local and domain parts */ $domain = substr($email, $atIndex + 1); $local = substr($email, 0, $atIndex); $localLen = strlen($local); $domainLen = strlen($domain); /* Check local part length */ if ($localLen < 1 || $localLen > 64) { return false; } /* Check domain part length */ if ($domainLen < 1 || $domainLen > 254) { return false; } /* Local part mustn't start or end with a dot */ if ($local[0] == '.' || $local[$localLen - 1] == '.') { return false; } /* Local part mustn't have two consecutive dots*/ if (strpos($local, '..') !== false) { return false; } /* Check domain part characters */ if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { return false; } /* Domain part mustn't have two consecutive dots */ if (strpos($domain, '..') !== false) { return false; } /* Character not valid in local part unless local part is quoted */ if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\", "", $local))) /* " */ { if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\", "", $local))) /* " */ { return false; } } /* All tests passed, email seems to be OK */ return true; } // END hesk_isValidEmail() }