Bridge
4 days ago
Release
2 years ago
AuthorizedEmailsController.php
2 months ago
AuthorizedSenderDomainController.php
5 months ago
Bridge.php
4 months ago
CongratulatoryMssEmailController.php
4 months ago
SubscribersCountReporter.php
3 years ago
Validator.php
3 years ago
index.php
3 years ago
Validator.php
64 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Services; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\WP\Functions as WPFunctions; |
| 9 | |
| 10 | /** |
| 11 | * This class contains validation methods that were extracted from the \MailPoet\Models\ModelValidator class. |
| 12 | * It is used only in a few places and there is a chance in the future we can remove it. |
| 13 | */ |
| 14 | class Validator { |
| 15 | const EMAIL_MIN_LENGTH = 6; |
| 16 | const EMAIL_MAX_LENGTH = 150; |
| 17 | const ROLE_EMAILS = [ |
| 18 | 'abuse', |
| 19 | 'compliance', |
| 20 | 'devnull', |
| 21 | 'dns', |
| 22 | 'ftp', |
| 23 | 'hostmaster', |
| 24 | 'inoc', |
| 25 | 'ispfeedback', |
| 26 | 'ispsupport', |
| 27 | 'list-request', |
| 28 | 'list', |
| 29 | 'maildaemon', |
| 30 | 'noc', |
| 31 | 'no-reply', |
| 32 | 'noreply', |
| 33 | 'nospam', |
| 34 | 'null', |
| 35 | 'phish', |
| 36 | 'phishing', |
| 37 | 'postmaster', |
| 38 | 'privacy', |
| 39 | 'registrar', |
| 40 | 'root', |
| 41 | 'security', |
| 42 | 'spam', |
| 43 | 'sysadmin', |
| 44 | 'undisclosed-recipients', |
| 45 | 'unsubscribe', |
| 46 | 'usenet', |
| 47 | 'uucp', |
| 48 | 'webmaster', |
| 49 | 'www', |
| 50 | ]; |
| 51 | |
| 52 | public function validateEmail($email): bool { |
| 53 | $permittedLength = (strlen($email) >= self::EMAIL_MIN_LENGTH && strlen($email) <= self::EMAIL_MAX_LENGTH); |
| 54 | $validEmail = WPFunctions::get()->isEmail($email) !== false && filter_var($email, FILTER_VALIDATE_EMAIL) !== false; |
| 55 | return ($permittedLength && $validEmail); |
| 56 | } |
| 57 | |
| 58 | public function validateNonRoleEmail($email): bool { |
| 59 | if (!$this->validateEmail($email)) return false; |
| 60 | $firstPart = strtolower(substr($email, 0, (int)strpos($email, '@'))); |
| 61 | return array_search($firstPart, self::ROLE_EMAILS) === false; |
| 62 | } |
| 63 | } |
| 64 |