mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-09-10 01:56:30 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 709f21f927 | |||
| e68c26e065 | |||
| 8036f2bd05 | |||
| 0043eab0c5 | |||
| 0578b32b30 | |||
| 54859fabea | |||
| 135444003f | |||
| 9dde0df1e3 | |||
| 8790f59415 | |||
| 114b663f20 | |||
| a0e0fadfce | |||
| 74c0f07434 | |||
| ad1a0e9773 | |||
| aeb6851388 | |||
| a23fcc1315 |
@@ -6,6 +6,9 @@ php:
|
|||||||
- 5.5
|
- 5.5
|
||||||
- 5.6
|
- 5.6
|
||||||
- 7.0
|
- 7.0
|
||||||
|
- 7.1
|
||||||
|
- 7.2
|
||||||
|
- 7.3
|
||||||
- hhvm
|
- hhvm
|
||||||
|
|
||||||
env:
|
env:
|
||||||
|
|||||||
@@ -18,6 +18,13 @@ class DNSCheckValidation implements EmailValidation
|
|||||||
* @var InvalidEmail
|
* @var InvalidEmail
|
||||||
*/
|
*/
|
||||||
private $error;
|
private $error;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
if (!extension_loaded('intl')) {
|
||||||
|
throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function isValid($email, EmailLexer $emailLexer)
|
public function isValid($email, EmailLexer $emailLexer)
|
||||||
{
|
{
|
||||||
@@ -44,7 +51,11 @@ class DNSCheckValidation implements EmailValidation
|
|||||||
|
|
||||||
protected function checkDNS($host)
|
protected function checkDNS($host)
|
||||||
{
|
{
|
||||||
$host = rtrim($host, '.') . '.';
|
$variant = INTL_IDNA_VARIANT_2003;
|
||||||
|
if ( defined('INTL_IDNA_VARIANT_UTS46') ) {
|
||||||
|
$variant = INTL_IDNA_VARIANT_UTS46;
|
||||||
|
}
|
||||||
|
$host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.') . '.';
|
||||||
|
|
||||||
$Aresult = true;
|
$Aresult = true;
|
||||||
$MXresult = checkdnsrr($host, 'MX');
|
$MXresult = checkdnsrr($host, 'MX');
|
||||||
|
|||||||
@@ -62,7 +62,8 @@ class MultipleValidationWithAnd implements EmailValidation
|
|||||||
$errors = [];
|
$errors = [];
|
||||||
foreach ($this->validations as $validation) {
|
foreach ($this->validations as $validation) {
|
||||||
$emailLexer->reset();
|
$emailLexer->reset();
|
||||||
$result = $result && $validation->isValid($email, $emailLexer);
|
$validationResult = $validation->isValid($email, $emailLexer);
|
||||||
|
$result = $result && $validationResult;
|
||||||
$this->warnings = array_merge($this->warnings, $validation->getWarnings());
|
$this->warnings = array_merge($this->warnings, $validation->getWarnings());
|
||||||
$errors = $this->addNewError($validation->getError(), $errors);
|
$errors = $this->addNewError($validation->getError(), $errors);
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ class SpoofCheckValidation implements EmailValidation
|
|||||||
* @var InvalidEmail
|
* @var InvalidEmail
|
||||||
*/
|
*/
|
||||||
private $error;
|
private $error;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
if (!class_exists(Spoofchecker::class)) {
|
if (!extension_loaded('intl')) {
|
||||||
throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__));
|
throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
# EmailValidator
|
# EmailValidator
|
||||||
[](https://travis-ci.org/egulias/EmailValidator) [](https://coveralls.io/r/egulias/EmailValidator?branch=master) [](https://scrutinizer-ci.com/g/egulias/EmailValidator/?branch=master) [](https://insight.sensiolabs.com/projects/22ba6692-9c02-42e5-a65d-1c5696bfffc6)
|
[](https://travis-ci.org/egulias/EmailValidator) [](https://coveralls.io/r/egulias/EmailValidator?branch=master) [](https://scrutinizer-ci.com/g/egulias/EmailValidator/?branch=master) [](https://insight.sensiolabs.com/projects/22ba6692-9c02-42e5-a65d-1c5696bfffc6)
|
||||||
=============================
|
=============================
|
||||||
With the help of [PHPStorm](https://www.jetbrains.com/phpstorm/)
|
## Suported RFCs ##
|
||||||
|
This library aims to support:
|
||||||
|
|
||||||
|
RFC 5321, 5322, 6530, 6531, 6532.
|
||||||
|
|
||||||
## Requirements ##
|
## Requirements ##
|
||||||
|
|
||||||
* [Composer](https://getcomposer.org) is required for installation
|
* [Composer](https://getcomposer.org) is required for installation
|
||||||
* [Spoofchecking](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/SpoofCheckValidation.php) validation requires that your PHP system have the [PHP Internationalization Libraries](http://php.net/manual/en/book.intl.php) (also known as PHP Intl)
|
* [Spoofchecking](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/SpoofCheckValidation.php) and [DNSCheckValidation](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/DNSCheckValidation.php) validation requires that your PHP system has the [PHP Internationalization Libraries](https://php.net/manual/en/book.intl.php) (also known as PHP Intl)
|
||||||
|
|
||||||
## Installation ##
|
## Installation ##
|
||||||
|
|
||||||
@@ -62,7 +65,7 @@ $validator->isValid("example@example.com", $multipleValidations); //true
|
|||||||
|
|
||||||
### How to extend ###
|
### How to extend ###
|
||||||
|
|
||||||
It's easy! You just need to extend [EmailValidation](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/EmailValidation.php) and you can use your own validation.
|
It's easy! You just need to implement [EmailValidation](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/EmailValidation.php) and you can use your own validation.
|
||||||
|
|
||||||
|
|
||||||
## Other Contributors ##
|
## Other Contributors ##
|
||||||
@@ -70,9 +73,9 @@ It's easy! You just need to extend [EmailValidation](https://github.com/egulias/
|
|||||||
|
|
||||||
As this is a port from another library and work, here are other people related to the previous one:
|
As this is a port from another library and work, here are other people related to the previous one:
|
||||||
|
|
||||||
* Ricard Clau [@ricardclau](http://github.com/ricardclau): Performance against PHP built-in filter_var
|
* Ricard Clau [@ricardclau](https://github.com/ricardclau): Performance against PHP built-in filter_var
|
||||||
* Josepf Bielawski [@stloyd](http://github.com/stloyd): For its first re-work of Dominic's lib
|
* Josepf Bielawski [@stloyd](https://github.com/stloyd): For its first re-work of Dominic's lib
|
||||||
* Dominic Sayers [@dominicsayers](http://github.com/dominicsayers): The original isemail function
|
* Dominic Sayers [@dominicsayers](https://github.com/dominicsayers): The original isemail function
|
||||||
|
|
||||||
## License ##
|
## License ##
|
||||||
Released under the MIT License attached with this code.
|
Released under the MIT License attached with this code.
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ class DNSCheckValidationTest extends TestCase
|
|||||||
['"Abc@def"@example.com'],
|
['"Abc@def"@example.com'],
|
||||||
['"Fred\ Bloggs"@example.com'],
|
['"Fred\ Bloggs"@example.com'],
|
||||||
['"Joe.\\Blow"@example.com'],
|
['"Joe.\\Blow"@example.com'],
|
||||||
|
|
||||||
|
// unicide
|
||||||
|
['ñandu.cl'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+44
-5
@@ -2,15 +2,18 @@
|
|||||||
|
|
||||||
namespace Egulias\Tests\EmailValidator\Validation;
|
namespace Egulias\Tests\EmailValidator\Validation;
|
||||||
|
|
||||||
|
use Egulias\EmailValidator\EmailValidator;
|
||||||
use Egulias\EmailValidator\Exception\CommaInDomain;
|
use Egulias\EmailValidator\Exception\CommaInDomain;
|
||||||
use Egulias\EmailValidator\Exception\NoDomainPart;
|
use Egulias\EmailValidator\Exception\NoDomainPart;
|
||||||
use Egulias\EmailValidator\Validation\MultipleErrors;
|
use Egulias\EmailValidator\Validation\MultipleErrors;
|
||||||
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
|
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
|
||||||
|
use Egulias\EmailValidator\Validation\NoRFCWarningsValidation;
|
||||||
|
use Egulias\EmailValidator\Validation\RFCValidation;
|
||||||
use Egulias\EmailValidator\Warning\AddressLiteral;
|
use Egulias\EmailValidator\Warning\AddressLiteral;
|
||||||
use Egulias\EmailValidator\Warning\DomainLiteral;
|
use Egulias\EmailValidator\Warning\DomainLiteral;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class MultipleValidationWitAndTest extends TestCase
|
class MultipleValidationWithAndTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testUsesAndLogicalOperation()
|
public function testUsesAndLogicalOperation()
|
||||||
{
|
{
|
||||||
@@ -81,16 +84,40 @@ class MultipleValidationWitAndTest extends TestCase
|
|||||||
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
|
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
|
||||||
|
|
||||||
$validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
|
$validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
|
||||||
$validation1->expects($this->any())->method("isValid")->willReturn(true);
|
$validation1->expects($this->once())->method("isValid")->willReturn(false);
|
||||||
|
$validation1->expects($this->once())->method("getWarnings")->willReturn([]);
|
||||||
|
$validation1->expects($this->once())->method("getError")->willReturn($error1);
|
||||||
|
|
||||||
|
$validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
|
||||||
|
$validation2->expects($this->once())->method("isValid")->willReturn(false);
|
||||||
|
$validation2->expects($this->once())->method("getWarnings")->willReturn([]);
|
||||||
|
$validation2->expects($this->once())->method("getError")->willReturn($error2);
|
||||||
|
|
||||||
|
$multipleValidation = new MultipleValidationWithAnd([$validation1, $validation2]);
|
||||||
|
$multipleValidation->isValid("example@example.com", $lexer);
|
||||||
|
$this->assertEquals($expectedResult, $multipleValidation->getError());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testStopsAfterFirstError()
|
||||||
|
{
|
||||||
|
$error1 = new CommaInDomain();
|
||||||
|
$error2 = new NoDomainPart();
|
||||||
|
|
||||||
|
$expectedResult = new MultipleErrors([$error1]);
|
||||||
|
|
||||||
|
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
|
||||||
|
|
||||||
|
$validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
|
||||||
|
$validation1->expects($this->any())->method("isValid")->willReturn(false);
|
||||||
$validation1->expects($this->once())->method("getWarnings")->willReturn([]);
|
$validation1->expects($this->once())->method("getWarnings")->willReturn([]);
|
||||||
$validation1->expects($this->once())->method("getError")->willReturn($error1);
|
$validation1->expects($this->once())->method("getError")->willReturn($error1);
|
||||||
|
|
||||||
$validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
|
$validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
|
||||||
$validation2->expects($this->any())->method("isValid")->willReturn(false);
|
$validation2->expects($this->any())->method("isValid")->willReturn(false);
|
||||||
$validation2->expects($this->once())->method("getWarnings")->willReturn([]);
|
$validation2->expects($this->never())->method("getWarnings")->willReturn([]);
|
||||||
$validation2->expects($this->once())->method("getError")->willReturn($error2);
|
$validation2->expects($this->never())->method("getError")->willReturn($error2);
|
||||||
|
|
||||||
$multipleValidation = new MultipleValidationWithAnd([$validation1, $validation2]);
|
$multipleValidation = new MultipleValidationWithAnd([$validation1, $validation2], MultipleValidationWithAnd::STOP_ON_ERROR);
|
||||||
$multipleValidation->isValid("example@example.com", $lexer);
|
$multipleValidation->isValid("example@example.com", $lexer);
|
||||||
$this->assertEquals($expectedResult, $multipleValidation->getError());
|
$this->assertEquals($expectedResult, $multipleValidation->getError());
|
||||||
}
|
}
|
||||||
@@ -117,4 +144,16 @@ class MultipleValidationWitAndTest extends TestCase
|
|||||||
$multipleValidation->isValid("example@example.com", $lexer);
|
$multipleValidation->isValid("example@example.com", $lexer);
|
||||||
$this->assertEquals($expectedResult, $multipleValidation->getError());
|
$this->assertEquals($expectedResult, $multipleValidation->getError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testBreakoutOnInvalidEmail()
|
||||||
|
{
|
||||||
|
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
|
||||||
|
|
||||||
|
$validationNotCalled = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
|
||||||
|
$validationNotCalled->expects($this->never())->method("isValid");
|
||||||
|
$validationNotCalled->expects($this->never())->method("getWarnings");
|
||||||
|
$validationNotCalled->expects($this->never())->method("getError");
|
||||||
|
$multipleValidation = new MultipleValidationWithAnd([new RFCValidation(), $validationNotCalled], MultipleValidationWithAnd::STOP_ON_ERROR);
|
||||||
|
$this->assertFalse($multipleValidation->isValid("invalid-email", $lexer));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -220,13 +220,13 @@ class RFCValidationTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->assertTrue($this->validator->isValid($email, $this->lexer));
|
$this->assertTrue($this->validator->isValid($email, $this->lexer));
|
||||||
$warnings = $this->validator->getWarnings();
|
$warnings = $this->validator->getWarnings();
|
||||||
$this->assertTrue(
|
$this->assertCount(
|
||||||
count($warnings) === count($expectedWarnings),
|
count($warnings), $expectedWarnings,
|
||||||
"Expected: " . implode(",", $expectedWarnings) . " and got " . implode(",", $warnings)
|
"Expected: " . implode(",", $expectedWarnings) . " and got " . implode(",", $warnings)
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($warnings as $warning) {
|
foreach ($warnings as $warning) {
|
||||||
$this->assertTrue(isset($expectedWarnings[$warning->code()]));
|
$this->assertArrayHasKey($warning->code(), $expectedWarnings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -25,7 +25,7 @@
|
|||||||
},
|
},
|
||||||
"require-dev" : {
|
"require-dev" : {
|
||||||
"satooshi/php-coveralls": "^1.0.1",
|
"satooshi/php-coveralls": "^1.0.1",
|
||||||
"phpunit/phpunit": "^4.8.35",
|
"phpunit/phpunit": "^4.8.35||^5.7||^6.0",
|
||||||
"dominicsayers/isemail": "dev-master"
|
"dominicsayers/isemail": "dev-master"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
@@ -35,5 +35,10 @@
|
|||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Egulias\\EmailValidator\\": "EmailValidator"
|
"Egulias\\EmailValidator\\": "EmailValidator"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"Egulias\\Tests\\": "test"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
-1813
File diff suppressed because it is too large
Load Diff
@@ -1,23 +1,23 @@
|
|||||||
Email length
|
Email length
|
||||||
------------
|
------------
|
||||||
http://tools.ietf.org/html/rfc5321#section-4.1.2
|
https://tools.ietf.org/html/rfc5321#section-4.1.2
|
||||||
Forward-path = Path
|
Forward-path = Path
|
||||||
|
|
||||||
Path = "<" [ A-d-l ":" ] Mailbox ">"
|
Path = "<" [ A-d-l ":" ] Mailbox ">"
|
||||||
|
|
||||||
http://tools.ietf.org/html/rfc5321#section-4.5.3.1.3
|
https://tools.ietf.org/html/rfc5321#section-4.5.3.1.3
|
||||||
http://tools.ietf.org/html/rfc1035#section-2.3.4
|
https://tools.ietf.org/html/rfc1035#section-2.3.4
|
||||||
|
|
||||||
DNS
|
DNS
|
||||||
---
|
---
|
||||||
|
|
||||||
http://tools.ietf.org/html/rfc5321#section-2.3.5
|
https://tools.ietf.org/html/rfc5321#section-2.3.5
|
||||||
Names that can
|
Names that can
|
||||||
be resolved to MX RRs or address (i.e., A or AAAA) RRs (as discussed
|
be resolved to MX RRs or address (i.e., A or AAAA) RRs (as discussed
|
||||||
in Section 5) are permitted, as are CNAME RRs whose targets can be
|
in Section 5) are permitted, as are CNAME RRs whose targets can be
|
||||||
resolved, in turn, to MX or address RRs.
|
resolved, in turn, to MX or address RRs.
|
||||||
|
|
||||||
http://tools.ietf.org/html/rfc5321#section-5.1
|
https://tools.ietf.org/html/rfc5321#section-5.1
|
||||||
The lookup first attempts to locate an MX record associated with the
|
The lookup first attempts to locate an MX record associated with the
|
||||||
name. If a CNAME record is found, the resulting name is processed as
|
name. If a CNAME record is found, the resulting name is processed as
|
||||||
if it were the initial name. ... If an empty list of MXs is returned,
|
if it were the initial name. ... If an empty list of MXs is returned,
|
||||||
@@ -37,7 +37,7 @@ status to these addresses on the basis that they are more likely
|
|||||||
to be typos than genuine addresses (unless we've already
|
to be typos than genuine addresses (unless we've already
|
||||||
established that the domain does have an MX record)
|
established that the domain does have an MX record)
|
||||||
|
|
||||||
http://tools.ietf.org/html/rfc5321#section-2.3.5
|
https://tools.ietf.org/html/rfc5321#section-2.3.5
|
||||||
In the case
|
In the case
|
||||||
of a top-level domain used by itself in an email address, a single
|
of a top-level domain used by itself in an email address, a single
|
||||||
string is used without any dots. This makes the requirement,
|
string is used without any dots. This makes the requirement,
|
||||||
@@ -57,7 +57,7 @@ an ambiguity. The most authoritative statement on TLD formats that
|
|||||||
the author can find is in a (rejected!) erratum to RFC 1123
|
the author can find is in a (rejected!) erratum to RFC 1123
|
||||||
submitted by John Klensin, the author of RFC 5321:
|
submitted by John Klensin, the author of RFC 5321:
|
||||||
|
|
||||||
http://www.rfc-editor.org/errata_search.php?rfc=1123&eid=1353
|
https://www.rfc-editor.org/errata_search.php?rfc=1123&eid=1353
|
||||||
However, a valid host name can never have the dotted-decimal
|
However, a valid host name can never have the dotted-decimal
|
||||||
form #.#.#.#, since this change does not permit the highest-level
|
form #.#.#.#, since this change does not permit the highest-level
|
||||||
component label to start with a digit even if it is not all-numeric.
|
component label to start with a digit even if it is not all-numeric.
|
||||||
@@ -66,4 +66,4 @@ Comments
|
|||||||
--------
|
--------
|
||||||
Comments at the start of the domain are deprecated in the text
|
Comments at the start of the domain are deprecated in the text
|
||||||
Comments at the start of a subdomain are obs-domain
|
Comments at the start of a subdomain are obs-domain
|
||||||
(http://tools.ietf.org/html/rfc5322#section-3.4.1)
|
(https://tools.ietf.org/html/rfc5322#section-3.4.1)
|
||||||
|
|||||||
Reference in New Issue
Block a user