Add direct validation function for noda mail checker

This commit is contained in:
Joshua Ramon Enslin 2024-07-28 03:47:35 +02:00
parent f18e4c3edc
commit cc0997f412
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -107,4 +107,26 @@ final class NodaMailChecker {
return self::validateMailDomainAccessibilityCached($mysqli, $domain);
}
/**
* Validates mail address, throwing an exception if the mail address is not valid.
*
* @param MDMysqli $mysqli DB connection.
* @param string $mail_address Address.
*
* @return string
*/
public static function validateMail(MDMysqli $mysqli, string $mail_address):string {
if (empty($mail_address)) return $mail_address;
$mail_address = MD_STD_IN::sanitize_email($mail_address);
if (self::validateMailByDomainAccessibilityCached($mysqli, $mail_address) === false) {
throw new MDInvalidEmail("The host name of the entered mail address is invalid");
}
return $mail_address;
}
}