Merge pull request #536 from torrentpier/extended-email-validation

Extended email validation
This commit is contained in:
Roman Kelesidis 2023-02-19 16:46:59 +07:00 committed by GitHub
commit 9419ff6ebf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View file

@ -384,6 +384,7 @@ $bb_cfg['emailer'] = [
], ],
'ssl_type' => '', // SMTP ssl type (ssl or tls) 'ssl_type' => '', // SMTP ssl type (ssl or tls)
]; ];
$bb_cfg['extended_email_validation'] = true; // DNS & RFC checks for entered email addresses
$bb_cfg['board_email'] = "noreply@$domain_name"; // admin email address $bb_cfg['board_email'] = "noreply@$domain_name"; // admin email address
$bb_cfg['board_email_form'] = false; // can users send email to each other via board $bb_cfg['board_email_form'] = false; // can users send email to each other via board

View file

@ -9,6 +9,12 @@
namespace TorrentPier\Legacy; namespace TorrentPier\Legacy;
use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\DNSCheckValidation;
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
use Egulias\EmailValidator\Validation\RFCValidation;
use Egulias\EmailValidator\Validation\SpoofCheckValidation;
/** /**
* Class Validate * Class Validate
* @package TorrentPier\Legacy * @package TorrentPier\Legacy
@ -88,7 +94,7 @@ class Validate
*/ */
public static function email($email, $check_ban_and_taken = true) public static function email($email, $check_ban_and_taken = true)
{ {
global $lang, $userdata; global $lang, $userdata, $bb_cfg;
if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) { if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
return $lang['EMAIL_INVALID']; return $lang['EMAIL_INVALID'];
@ -97,6 +103,21 @@ class Validate
return $lang['EMAIL_TOO_LONG']; return $lang['EMAIL_TOO_LONG'];
} }
// Extended email validation
if ($bb_cfg['extended_email_validation']) {
$validator = new EmailValidator();
$multipleValidations = new MultipleValidationWithAnd([
new RFCValidation(), // Standard RFC-like email validation.
new DNSCheckValidation(), // Will check if there are DNS records that signal that the server accepts emails. This does not entail that the email exists.
new SpoofCheckValidation() // Will check for multi-utf-8 chars that can signal an erroneous email name.
]);
if (!$validator->isValid($email, $multipleValidations)) {
return $lang['EMAIL_INVALID'];
}
}
if ($check_ban_and_taken) { if ($check_ban_and_taken) {
$banned_emails = array(); $banned_emails = array();