mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-08-31 20:50:01 +00:00
Compare commits
75 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5642614492 | |||
| b8bb147f46 | |||
| cbfe3ee6f7 | |||
| 4b59310c1a | |||
| f463fbe542 | |||
| afc6adc0b9 | |||
| 58e44fb064 | |||
| 04c6cdf987 | |||
| cc9defe645 | |||
| 50aaa0b18f | |||
| de448a30fa | |||
| a7b385301d | |||
| f6447f8b99 | |||
| d4001715b2 | |||
| 4b7fcf6796 | |||
| 2a1145ffbf | |||
| af864423f5 | |||
| 12f16f70aa | |||
| 0afaa6a3b6 | |||
| 5631c3fe2e | |||
| c383717824 | |||
| aabed98198 | |||
| 3b0fd01aa3 | |||
| 4efe697504 | |||
| 7a4c5714f5 | |||
| 0a26375a7a | |||
| 773fe5f4a3 | |||
| 4a209951ee | |||
| a8b0bab5aa | |||
| cc0b91f311 | |||
| 8092ecaeff | |||
| f19defb373 | |||
| 9a518fb1bd | |||
| 9b184605e8 | |||
| 7a4842c60f | |||
| 687ab6a66e | |||
| 116d4054fa | |||
| af9417f765 | |||
| ab0bcfb424 | |||
| 833b3e7924 | |||
| fec1609458 | |||
| add559b99c | |||
| 19e390d863 | |||
| 5320c26b38 | |||
| 3b6ab3bcd5 | |||
| 7a64ea18af | |||
| 9103f4f99b | |||
| 3f623e9006 | |||
| 833eb65135 | |||
| e61481fefb | |||
| 518f80a0ff | |||
| 2ec7babda6 | |||
| 05367768d6 | |||
| 5c3a79217c | |||
| 749b423775 | |||
| 49494c3189 | |||
| 8b62522238 | |||
| 82fb2d6ce1 | |||
| 2933b7bbd1 | |||
| f5c48f62d3 | |||
| 43650e8566 | |||
| 3d94cc6487 | |||
| 65c8c3d7bb | |||
| 57f8ae443b | |||
| 18df863858 | |||
| 953cbdbbcf | |||
| 41cb75ec00 | |||
| 8927160d8d | |||
| 887605ad1b | |||
| 43e1825cd8 | |||
| 2f44d7b1e1 | |||
| 355cb7e604 | |||
| d6fcd2d7ca | |||
| 9be8eb420a | |||
| 20066b1c1e |
+21
-6
@@ -1,3 +1,5 @@
|
||||
sudo: false
|
||||
|
||||
language: php
|
||||
|
||||
php:
|
||||
@@ -5,16 +7,29 @@ php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- hhvm
|
||||
|
||||
before_script:
|
||||
- wget http://getcomposer.org/composer.phar
|
||||
- php composer.phar install --dev --no-interaction
|
||||
env:
|
||||
global:
|
||||
- deps=high
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- php: 5.3
|
||||
env: deps=low
|
||||
- php: 5.4
|
||||
env: deps=no
|
||||
- php: 5.5
|
||||
env: deps=no
|
||||
|
||||
install:
|
||||
- if [ "$deps" = "no" ]; then composer install; fi
|
||||
- if [ "$deps" = "low" ]; then composer update --prefer-lowest; fi
|
||||
- if [ "$deps" = "high" ]; then composer update; fi
|
||||
|
||||
script:
|
||||
- mkdir -p build/logs
|
||||
- phpunit --coverage-clover build/logs/clover.xml
|
||||
|
||||
after_script:
|
||||
- php vendor/bin/coveralls
|
||||
|
||||
|
||||
@@ -1,51 +1,59 @@
|
||||
EmailValidator [](https://travis-ci.org/egulias/EmailValidator) [](https://coveralls.io/r/egulias/EmailValidator?branch=master) [](https://insight.sensiolabs.com/projects/b18d473e-bd5a-4d88-a7b2-7aeaee0ebd7b)[](https://scrutinizer-ci.com/g/egulias/EmailValidator/?branch=master)
|
||||
=============================
|
||||
|
||||
##Installation##
|
||||
Install via composer. Add to your current compooser.json ```require``` key: ```"egulias/email-validator":"1.0.x-dev" ```
|
||||
|
||||
##Usage##
|
||||
|
||||
Simple example:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
|
||||
$validator = new EmailValidator;
|
||||
if ($validator->isValid($email)) {
|
||||
echo $email . ' is a valid email address';
|
||||
}
|
||||
```
|
||||
|
||||
More advanced example (returns detailed diagnostic error codes):
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use egulias\EmailValidator\EmailValidator;
|
||||
|
||||
$validator = new EmailValidator;
|
||||
$email = 'dominic@sayers.cc';
|
||||
$result = $validator->isValid($email);
|
||||
|
||||
if ($result) {
|
||||
echo $email . ' is a valid email address';
|
||||
} else if ($validator->hasWarnings()) {
|
||||
echo 'Warning! ' . $email . ' has unusual/deprecated features (result code ' . var_export($validator->getWarnings(), true) . ')';
|
||||
} else {
|
||||
echo $email . ' is not a valid email address (result code ' . $validator->getError() . ')';
|
||||
}
|
||||
```
|
||||
|
||||
##Contributors##
|
||||
As this is a port from another library and work, here are other people related to the previous:
|
||||
|
||||
* Ricard Clau [@ricardclau](http://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
|
||||
* Dominic Sayers [@dominicsayers](http://github.com/dominicsayers): The original isemail function
|
||||
|
||||
##Licence##
|
||||
Released under the MIT Licence attached with this code.
|
||||
|
||||
#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)
|
||||
=============================
|
||||
With the help of
|
||||
|
||||

|
||||
##Installation##
|
||||
|
||||
Run the command below to install via Composer
|
||||
|
||||
```shell
|
||||
composer require egulias/email-validator "~1.2"
|
||||
```
|
||||
|
||||
##Usage##
|
||||
|
||||
Simple example:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
|
||||
$validator = new EmailValidator;
|
||||
if ($validator->isValid($email)) {
|
||||
echo $email . ' is a valid email address';
|
||||
}
|
||||
```
|
||||
|
||||
More advanced example (returns detailed diagnostic error codes):
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
|
||||
$validator = new EmailValidator;
|
||||
$email = 'dominic@sayers.cc';
|
||||
$result = $validator->isValid($email);
|
||||
|
||||
if ($result) {
|
||||
echo $email . ' is a valid email address';
|
||||
} else if ($validator->hasWarnings()) {
|
||||
echo 'Warning! ' . $email . ' has unusual/deprecated features (result code ' . var_export($validator->getWarnings(), true) . ')';
|
||||
} else {
|
||||
echo $email . ' is not a valid email address (result code ' . $validator->getError() . ')';
|
||||
}
|
||||
```
|
||||
|
||||
##Contributors##
|
||||
As this is a port from another library and work, here are other people related to the previous:
|
||||
|
||||
* Ricard Clau [@ricardclau](http://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
|
||||
* Dominic Sayers [@dominicsayers](http://github.com/dominicsayers): The original isemail function
|
||||
|
||||
##License##
|
||||
Released under the MIT License attached with this code.
|
||||
|
||||
|
||||
+4
-4
@@ -3,22 +3,22 @@
|
||||
"description": "A library for validating emails",
|
||||
"homepage": "https://github.com/egulias/EmailValidator",
|
||||
"type": "Library",
|
||||
"keywords": ["email", "validation", "validator"],
|
||||
"keywords": ["email", "validation", "validator", "emailvalidation", "emailvalidator"],
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{"name": "Eduardo Gulias Davis"}
|
||||
],
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
"dev-master": "2.0.x-dev"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": ">= 5.3.3",
|
||||
"doctrine/lexer": "~1.0"
|
||||
"doctrine/lexer": "^1.0.1"
|
||||
},
|
||||
"require-dev" : {
|
||||
"satooshi/php-coveralls": "dev-master"
|
||||
"phpunit/phpunit": "^4.8.24"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
|
||||
Generated
+887
-398
File diff suppressed because it is too large
Load Diff
@@ -1,89 +1,89 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
||||
<title>The BNF from RFC 5321 defining parts of a valid SMTP address</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<pre style="font-size:11px;">
|
||||
Mailbox = Local-part "@" ( Domain / address-literal )
|
||||
|
||||
Local-part = Dot-string / Quoted-string
|
||||
; MAY be case-sensitive
|
||||
|
||||
|
||||
Dot-string = Atom *("." Atom)
|
||||
|
||||
Atom = 1*atext
|
||||
|
||||
Quoted-string = DQUOTE *QcontentSMTP DQUOTE
|
||||
|
||||
QcontentSMTP = qtextSMTP / quoted-pairSMTP
|
||||
|
||||
quoted-pairSMTP = %d92 %d32-126
|
||||
; i.e., backslash followed by any ASCII
|
||||
; graphic (including itself) or SPace
|
||||
|
||||
qtextSMTP = %d32-33 / %d35-91 / %d93-126
|
||||
; i.e., within a quoted string, any
|
||||
; ASCII graphic or space is permitted
|
||||
; without blackslash-quoting except
|
||||
; double-quote and the backslash itself.
|
||||
|
||||
Domain = sub-domain *("." sub-domain)
|
||||
|
||||
sub-domain = Let-dig [Ldh-str]
|
||||
|
||||
Let-dig = ALPHA / DIGIT
|
||||
|
||||
Ldh-str = *( ALPHA / DIGIT / "-" ) Let-dig
|
||||
|
||||
address-literal = "[" ( IPv4-address-literal /
|
||||
IPv6-address-literal /
|
||||
General-address-literal ) "]"
|
||||
; See Section 4.1.3
|
||||
|
||||
IPv4-address-literal = Snum 3("." Snum)
|
||||
|
||||
IPv6-address-literal = "IPv6:" IPv6-addr
|
||||
|
||||
General-address-literal = Standardized-tag ":" 1*dcontent
|
||||
|
||||
Standardized-tag = Ldh-str
|
||||
; Standardized-tag MUST be specified in a
|
||||
; Standards-Track RFC and registered with IANA
|
||||
|
||||
dcontent = %d33-90 / ; Printable US-ASCII
|
||||
%d94-126 ; excl. "[", "\", "]"
|
||||
|
||||
Snum = 1*3DIGIT
|
||||
; representing a decimal integer
|
||||
; value in the range 0 through 255
|
||||
|
||||
IPv6-addr = IPv6-full / IPv6-comp / IPv6v4-full / IPv6v4-comp
|
||||
|
||||
IPv6-hex = 1*4HEXDIG
|
||||
|
||||
IPv6-full = IPv6-hex 7(":" IPv6-hex)
|
||||
|
||||
IPv6-comp = [IPv6-hex *5(":" IPv6-hex)] "::"
|
||||
[IPv6-hex *5(":" IPv6-hex)]
|
||||
; The "::" represents at least 2 16-bit groups of
|
||||
; zeros. No more than 6 groups in addition to the
|
||||
; "::" may be present.
|
||||
|
||||
IPv6v4-full = IPv6-hex 5(":" IPv6-hex) ":" IPv4-address-literal
|
||||
|
||||
IPv6v4-comp = [IPv6-hex *3(":" IPv6-hex)] "::"
|
||||
[IPv6-hex *3(":" IPv6-hex) ":"]
|
||||
IPv4-address-literal
|
||||
; The "::" represents at least 2 16-bit groups of
|
||||
; zeros. No more than 4 groups in addition to the
|
||||
; "::" and IPv4-address-literal may be present.
|
||||
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
||||
<title>The BNF from RFC 5321 defining parts of a valid SMTP address</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<pre style="font-size:11px;">
|
||||
Mailbox = Local-part "@" ( Domain / address-literal )
|
||||
|
||||
Local-part = Dot-string / Quoted-string
|
||||
; MAY be case-sensitive
|
||||
|
||||
|
||||
Dot-string = Atom *("." Atom)
|
||||
|
||||
Atom = 1*atext
|
||||
|
||||
Quoted-string = DQUOTE *QcontentSMTP DQUOTE
|
||||
|
||||
QcontentSMTP = qtextSMTP / quoted-pairSMTP
|
||||
|
||||
quoted-pairSMTP = %d92 %d32-126
|
||||
; i.e., backslash followed by any ASCII
|
||||
; graphic (including itself) or SPace
|
||||
|
||||
qtextSMTP = %d32-33 / %d35-91 / %d93-126
|
||||
; i.e., within a quoted string, any
|
||||
; ASCII graphic or space is permitted
|
||||
; without blackslash-quoting except
|
||||
; double-quote and the backslash itself.
|
||||
|
||||
Domain = sub-domain *("." sub-domain)
|
||||
|
||||
sub-domain = Let-dig [Ldh-str]
|
||||
|
||||
Let-dig = ALPHA / DIGIT
|
||||
|
||||
Ldh-str = *( ALPHA / DIGIT / "-" ) Let-dig
|
||||
|
||||
address-literal = "[" ( IPv4-address-literal /
|
||||
IPv6-address-literal /
|
||||
General-address-literal ) "]"
|
||||
; See Section 4.1.3
|
||||
|
||||
IPv4-address-literal = Snum 3("." Snum)
|
||||
|
||||
IPv6-address-literal = "IPv6:" IPv6-addr
|
||||
|
||||
General-address-literal = Standardized-tag ":" 1*dcontent
|
||||
|
||||
Standardized-tag = Ldh-str
|
||||
; Standardized-tag MUST be specified in a
|
||||
; Standards-Track RFC and registered with IANA
|
||||
|
||||
dcontent = %d33-90 / ; Printable US-ASCII
|
||||
%d94-126 ; excl. "[", "\", "]"
|
||||
|
||||
Snum = 1*3DIGIT
|
||||
; representing a decimal integer
|
||||
; value in the range 0 through 255
|
||||
|
||||
IPv6-addr = IPv6-full / IPv6-comp / IPv6v4-full / IPv6v4-comp
|
||||
|
||||
IPv6-hex = 1*4HEXDIG
|
||||
|
||||
IPv6-full = IPv6-hex 7(":" IPv6-hex)
|
||||
|
||||
IPv6-comp = [IPv6-hex *5(":" IPv6-hex)] "::"
|
||||
[IPv6-hex *5(":" IPv6-hex)]
|
||||
; The "::" represents at least 2 16-bit groups of
|
||||
; zeros. No more than 6 groups in addition to the
|
||||
; "::" may be present.
|
||||
|
||||
IPv6v4-full = IPv6-hex 5(":" IPv6-hex) ":" IPv4-address-literal
|
||||
|
||||
IPv6v4-comp = [IPv6-hex *3(":" IPv6-hex)] "::"
|
||||
[IPv6-hex *3(":" IPv6-hex) ":"]
|
||||
IPv4-address-literal
|
||||
; The "::" represents at least 2 16-bit groups of
|
||||
; zeros. No more than 4 groups in addition to the
|
||||
; "::" and IPv4-address-literal may be present.
|
||||
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
+141
-141
@@ -1,141 +1,141 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
||||
<title>The BNF from RFC 5322 defining parts of a valid internet message address</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<pre style="font-size:11px;">
|
||||
addr-spec = local-part "@" domain
|
||||
|
||||
local-part = dot-atom / quoted-string / obs-local-part
|
||||
|
||||
dot-atom = [CFWS] dot-atom-text [CFWS]
|
||||
|
||||
CFWS = (1*([FWS] comment) [FWS]) / FWS
|
||||
|
||||
FWS = ([*WSP CRLF] 1*WSP) / obs-FWS
|
||||
; Folding white space
|
||||
|
||||
WSP = SP / HTAB ; white space
|
||||
|
||||
obs-FWS = 1*([CRLF] WSP) ; As amended in erratum #1908
|
||||
|
||||
ctext = %d33-39 / ; Printable US-ASCII
|
||||
%d42-91 / ; characters not including
|
||||
%d93-126 / ; "(", ")", or "\"
|
||||
obs-ctext
|
||||
|
||||
obs-ctext = obs-NO-WS-CTL
|
||||
ccontent = ctext / quoted-pair / comment
|
||||
|
||||
comment = "(" *([FWS] ccontent) [FWS] ")"
|
||||
|
||||
dot-atom-text = 1*atext *("." 1*atext)
|
||||
|
||||
atext = ALPHA / DIGIT / ; Printable US-ASCII
|
||||
"!" / "#" / ; characters not including
|
||||
"$" / "%" / ; specials. Used for atoms.
|
||||
"&" / "'" /
|
||||
"*" / "+" /
|
||||
"-" / "/" /
|
||||
"=" / "?" /
|
||||
"^" / "_" /
|
||||
"`" / "{" /
|
||||
"|" / "}" /
|
||||
"~"
|
||||
|
||||
specials = "(" / ")" / ; Special characters that do
|
||||
"<" / ">" / ; not appear in atext
|
||||
"[" / "]" /
|
||||
":" / ";" /
|
||||
"@" / "\" /
|
||||
"," / "." /
|
||||
DQUOTE
|
||||
|
||||
quoted-string = [CFWS]
|
||||
DQUOTE *([FWS] qcontent) [FWS] DQUOTE
|
||||
[CFWS]
|
||||
|
||||
qcontent = qtext / quoted-pair
|
||||
|
||||
qtext = %d33 / ; Printable US-ASCII
|
||||
%d35-91 / ; characters not including
|
||||
%d93-126 / ; "\" or the quote character
|
||||
obs-qtext
|
||||
|
||||
obs-qtext = obs-NO-WS-CTL
|
||||
|
||||
obs-NO-WS-CTL = %d1-8 / ; US-ASCII control
|
||||
%d11 / ; characters that do not
|
||||
%d12 / ; include the carriage
|
||||
%d14-31 / ; return, line feed, and
|
||||
%d127 ; white space characters
|
||||
|
||||
quoted-pair = ("\" (VCHAR / WSP)) / obs-qp
|
||||
|
||||
VCHAR = %x21-7E ; visible (printing) characters
|
||||
|
||||
obs-qp = "\" (%d0 / obs-NO-WS-CTL / LF / CR)
|
||||
|
||||
obs-local-part = word *("." word)
|
||||
|
||||
word = atom / quoted-string
|
||||
|
||||
atom = [CFWS] 1*atext [CFWS]
|
||||
|
||||
domain = dot-atom / domain-literal / obs-domain
|
||||
|
||||
domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS]
|
||||
|
||||
dtext = %d33-90 / ; Printable US-ASCII
|
||||
%d94-126 / ; characters not including
|
||||
obs-dtext ; "[", "]", or "\"
|
||||
|
||||
obs-dtext = obs-NO-WS-CTL / quoted-pair
|
||||
|
||||
obs-domain = atom *("." atom)
|
||||
|
||||
NB For SMTP mail, the domain-literal is restricted by RFC5321 as follows:
|
||||
|
||||
Mailbox = Local-part "@" ( Domain / address-literal )
|
||||
|
||||
address-literal = "[" ( IPv4-address-literal /
|
||||
IPv6-address-literal /
|
||||
General-address-literal ) "]"
|
||||
|
||||
IPv4-address-literal = Snum 3("." Snum)
|
||||
|
||||
IPv6-address-literal = "IPv6:" IPv6-addr
|
||||
|
||||
Snum = 1*3DIGIT
|
||||
; representing a decimal integer
|
||||
; value in the range 0 through 255
|
||||
|
||||
IPv6-addr = IPv6-full / IPv6-comp / IPv6v4-full / IPv6v4-comp
|
||||
|
||||
IPv6-hex = 1*4HEXDIG
|
||||
|
||||
IPv6-full = IPv6-hex 7(":" IPv6-hex)
|
||||
|
||||
IPv6-comp = [IPv6-hex *5(":" IPv6-hex)] "::"
|
||||
[IPv6-hex *5(":" IPv6-hex)]
|
||||
; The "::" represents at least 2 16-bit groups of
|
||||
; zeros. No more than 6 groups in addition to the
|
||||
; "::" may be present.
|
||||
|
||||
IPv6v4-full = IPv6-hex 5(":" IPv6-hex) ":" IPv4-address-literal
|
||||
|
||||
IPv6v4-comp = [IPv6-hex *3(":" IPv6-hex)] "::"
|
||||
[IPv6-hex *3(":" IPv6-hex) ":"]
|
||||
IPv4-address-literal
|
||||
; The "::" represents at least 2 16-bit groups of
|
||||
; zeros. No more than 4 groups in addition to the
|
||||
; "::" and IPv4-address-literal may be present.
|
||||
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
||||
<title>The BNF from RFC 5322 defining parts of a valid internet message address</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<pre style="font-size:11px;">
|
||||
addr-spec = local-part "@" domain
|
||||
|
||||
local-part = dot-atom / quoted-string / obs-local-part
|
||||
|
||||
dot-atom = [CFWS] dot-atom-text [CFWS]
|
||||
|
||||
CFWS = (1*([FWS] comment) [FWS]) / FWS
|
||||
|
||||
FWS = ([*WSP CRLF] 1*WSP) / obs-FWS
|
||||
; Folding white space
|
||||
|
||||
WSP = SP / HTAB ; white space
|
||||
|
||||
obs-FWS = 1*([CRLF] WSP) ; As amended in erratum #1908
|
||||
|
||||
ctext = %d33-39 / ; Printable US-ASCII
|
||||
%d42-91 / ; characters not including
|
||||
%d93-126 / ; "(", ")", or "\"
|
||||
obs-ctext
|
||||
|
||||
obs-ctext = obs-NO-WS-CTL
|
||||
ccontent = ctext / quoted-pair / comment
|
||||
|
||||
comment = "(" *([FWS] ccontent) [FWS] ")"
|
||||
|
||||
dot-atom-text = 1*atext *("." 1*atext)
|
||||
|
||||
atext = ALPHA / DIGIT / ; Printable US-ASCII
|
||||
"!" / "#" / ; characters not including
|
||||
"$" / "%" / ; specials. Used for atoms.
|
||||
"&" / "'" /
|
||||
"*" / "+" /
|
||||
"-" / "/" /
|
||||
"=" / "?" /
|
||||
"^" / "_" /
|
||||
"`" / "{" /
|
||||
"|" / "}" /
|
||||
"~"
|
||||
|
||||
specials = "(" / ")" / ; Special characters that do
|
||||
"<" / ">" / ; not appear in atext
|
||||
"[" / "]" /
|
||||
":" / ";" /
|
||||
"@" / "\" /
|
||||
"," / "." /
|
||||
DQUOTE
|
||||
|
||||
quoted-string = [CFWS]
|
||||
DQUOTE *([FWS] qcontent) [FWS] DQUOTE
|
||||
[CFWS]
|
||||
|
||||
qcontent = qtext / quoted-pair
|
||||
|
||||
qtext = %d33 / ; Printable US-ASCII
|
||||
%d35-91 / ; characters not including
|
||||
%d93-126 / ; "\" or the quote character
|
||||
obs-qtext
|
||||
|
||||
obs-qtext = obs-NO-WS-CTL
|
||||
|
||||
obs-NO-WS-CTL = %d1-8 / ; US-ASCII control
|
||||
%d11 / ; characters that do not
|
||||
%d12 / ; include the carriage
|
||||
%d14-31 / ; return, line feed, and
|
||||
%d127 ; white space characters
|
||||
|
||||
quoted-pair = ("\" (VCHAR / WSP)) / obs-qp
|
||||
|
||||
VCHAR = %x21-7E ; visible (printing) characters
|
||||
|
||||
obs-qp = "\" (%d0 / obs-NO-WS-CTL / LF / CR)
|
||||
|
||||
obs-local-part = word *("." word)
|
||||
|
||||
word = atom / quoted-string
|
||||
|
||||
atom = [CFWS] 1*atext [CFWS]
|
||||
|
||||
domain = dot-atom / domain-literal / obs-domain
|
||||
|
||||
domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS]
|
||||
|
||||
dtext = %d33-90 / ; Printable US-ASCII
|
||||
%d94-126 / ; characters not including
|
||||
obs-dtext ; "[", "]", or "\"
|
||||
|
||||
obs-dtext = obs-NO-WS-CTL / quoted-pair
|
||||
|
||||
obs-domain = atom *("." atom)
|
||||
|
||||
NB For SMTP mail, the domain-literal is restricted by RFC5321 as follows:
|
||||
|
||||
Mailbox = Local-part "@" ( Domain / address-literal )
|
||||
|
||||
address-literal = "[" ( IPv4-address-literal /
|
||||
IPv6-address-literal /
|
||||
General-address-literal ) "]"
|
||||
|
||||
IPv4-address-literal = Snum 3("." Snum)
|
||||
|
||||
IPv6-address-literal = "IPv6:" IPv6-addr
|
||||
|
||||
Snum = 1*3DIGIT
|
||||
; representing a decimal integer
|
||||
; value in the range 0 through 255
|
||||
|
||||
IPv6-addr = IPv6-full / IPv6-comp / IPv6v4-full / IPv6v4-comp
|
||||
|
||||
IPv6-hex = 1*4HEXDIG
|
||||
|
||||
IPv6-full = IPv6-hex 7(":" IPv6-hex)
|
||||
|
||||
IPv6-comp = [IPv6-hex *5(":" IPv6-hex)] "::"
|
||||
[IPv6-hex *5(":" IPv6-hex)]
|
||||
; The "::" represents at least 2 16-bit groups of
|
||||
; zeros. No more than 6 groups in addition to the
|
||||
; "::" may be present.
|
||||
|
||||
IPv6v4-full = IPv6-hex 5(":" IPv6-hex) ":" IPv4-address-literal
|
||||
|
||||
IPv6v4-comp = [IPv6-hex *3(":" IPv6-hex)] "::"
|
||||
[IPv6-hex *3(":" IPv6-hex) ":"]
|
||||
IPv4-address-literal
|
||||
; The "::" represents at least 2 16-bit groups of
|
||||
; zeros. No more than 4 groups in addition to the
|
||||
; "::" and IPv4-address-literal may be present.
|
||||
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -31,10 +31,13 @@ class EmailLexer extends AbstractLexer
|
||||
const S_SEMICOLON = 275;
|
||||
const S_OPENQBRACKET = 276;
|
||||
const S_CLOSEQBRACKET = 277;
|
||||
const S_SLASH = 278;
|
||||
const S_EMPTY = null;
|
||||
const GENERIC = 300;
|
||||
const CRLF = 301;
|
||||
const INVALID = 302;
|
||||
const ASCII_INVALID_FROM = 127;
|
||||
const ASCII_INVALID_TO = 199;
|
||||
|
||||
/**
|
||||
* US-ASCII visible characters not valid for atext (@link http://tools.ietf.org/html/rfc5322#section-3.2.3)
|
||||
@@ -52,6 +55,7 @@ class EmailLexer extends AbstractLexer
|
||||
';' => self::S_SEMICOLON,
|
||||
'@' => self::S_AT,
|
||||
'\\' => self::S_BACKSLASH,
|
||||
'/' => self::S_SLASH,
|
||||
',' => self::S_COMMA,
|
||||
'.' => self::S_DOT,
|
||||
'"' => self::S_DQUOTE,
|
||||
@@ -63,18 +67,31 @@ class EmailLexer extends AbstractLexer
|
||||
"\n" => self::S_LF,
|
||||
"\r\n" => self::CRLF,
|
||||
'IPv6' => self::S_IPV6TAG,
|
||||
'<' => self::S_LOWERTHAN,
|
||||
'>' => self::S_GREATERTHAN,
|
||||
'{' => self::S_OPENQBRACKET,
|
||||
'}' => self::S_CLOSEQBRACKET,
|
||||
'' => self::S_EMPTY
|
||||
'' => self::S_EMPTY,
|
||||
'\0' => self::C_NUL,
|
||||
);
|
||||
|
||||
protected $hasInvalidTokens = false;
|
||||
|
||||
protected $previous;
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$this->hasInvalidTokens = false;
|
||||
parent::reset();
|
||||
}
|
||||
|
||||
public function hasInvalidTokens()
|
||||
{
|
||||
return $this->hasInvalidTokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
* @throws \UnexpectedValueException
|
||||
* @return boolean
|
||||
*/
|
||||
public function find($type)
|
||||
{
|
||||
@@ -100,7 +117,7 @@ class EmailLexer extends AbstractLexer
|
||||
/**
|
||||
* moveNext
|
||||
*
|
||||
* @return mixed
|
||||
* @return boolean
|
||||
*/
|
||||
public function moveNext()
|
||||
{
|
||||
@@ -112,17 +129,17 @@ class EmailLexer extends AbstractLexer
|
||||
/**
|
||||
* Lexical catchable patterns.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getCatchablePatterns()
|
||||
{
|
||||
return array(
|
||||
'[a-zA-Z_]+[46]?',
|
||||
'[a-zA-Z_]+[46]?', //ASCII and domain literal
|
||||
'[^\x00-\x7F]', //UTF-8
|
||||
'[0-9]+',
|
||||
'\r\n',
|
||||
'::',
|
||||
'\s+',
|
||||
'[\x10-\x1F]+',
|
||||
'\s+?',
|
||||
'.',
|
||||
);
|
||||
}
|
||||
@@ -130,11 +147,11 @@ class EmailLexer extends AbstractLexer
|
||||
/**
|
||||
* Lexical non-catchable patterns.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getNonCatchablePatterns()
|
||||
{
|
||||
return array('[\x7f-\xff]+');
|
||||
return array('[\xA0-\xff]+');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,14 +163,59 @@ class EmailLexer extends AbstractLexer
|
||||
*/
|
||||
protected function getType(&$value)
|
||||
{
|
||||
if (isset($this->charValue[$value])) {
|
||||
if ($this->isNullType($value)) {
|
||||
return self::C_NUL;
|
||||
}
|
||||
|
||||
if ($this->isValid($value)) {
|
||||
return $this->charValue[$value];
|
||||
}
|
||||
|
||||
if (preg_match('/[\x10-\x1F]+/', $value)) {
|
||||
if ($this->isUTF8Invalid($value)) {
|
||||
$this->hasInvalidTokens = true;
|
||||
return self::INVALID;
|
||||
}
|
||||
|
||||
return self::GENERIC;
|
||||
}
|
||||
|
||||
protected function isValid($value)
|
||||
{
|
||||
if (isset($this->charValue[$value])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
protected function isNullType($value)
|
||||
{
|
||||
if ($value === "\0") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
protected function isUTF8Invalid($value)
|
||||
{
|
||||
if (preg_match('/\p{Cc}+/u', $value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function getModifiers()
|
||||
{
|
||||
return 'iu';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,10 @@ class EmailParser
|
||||
$this->domainPartParser = new DomainPart($this->lexer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
* @return array
|
||||
*/
|
||||
public function parse($str)
|
||||
{
|
||||
$this->lexer->setInput($str);
|
||||
@@ -36,11 +40,16 @@ class EmailParser
|
||||
throw new \InvalidArgumentException('ERR_NOLOCALPART');
|
||||
}
|
||||
|
||||
|
||||
$this->localPartParser->parse($str);
|
||||
$this->domainPartParser->parse($str);
|
||||
|
||||
$this->setParts($str);
|
||||
|
||||
if ($this->lexer->hasInvalidTokens()) {
|
||||
throw new \InvalidArgumentException('ERR_INVALID_ATEXT');
|
||||
}
|
||||
|
||||
return array('local' => $this->localPart, 'domain' => $this->domainPart);
|
||||
}
|
||||
|
||||
@@ -78,6 +87,10 @@ class EmailParser
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $localPart
|
||||
* @param string $parsedDomainPart
|
||||
*/
|
||||
protected function addLongEmailWarning($localPart, $parsedDomainPart)
|
||||
{
|
||||
if (strlen($localPart . '@' . $parsedDomainPart) > self::EMAIL_MAX_LENGTH) {
|
||||
|
||||
@@ -2,56 +2,57 @@
|
||||
|
||||
namespace Egulias\EmailValidator;
|
||||
|
||||
use Egulias\EmailValidator\Parser\LocalPart;
|
||||
|
||||
/**
|
||||
* EmailValidator
|
||||
*
|
||||
* @author Eduardo Gulias Davis <me@egulias.com>
|
||||
*/
|
||||
class EmailValidator
|
||||
class EmailValidator implements EmailValidatorInterface
|
||||
{
|
||||
/**
|
||||
* Critical validation errors used to indicate that
|
||||
* an email address is invalid:
|
||||
*/
|
||||
const ERR_CONSECUTIVEATS = 128;
|
||||
const ERR_EXPECTING_DTEXT = 129;
|
||||
const ERR_NOLOCALPART = 130;
|
||||
const ERR_NODOMAIN = 131;
|
||||
const ERR_CONSECUTIVEDOTS = 132;
|
||||
const ERR_ATEXT_AFTER_CFWS = 133;
|
||||
const ERR_ATEXT_AFTER_QS = 134;
|
||||
const ERR_ATEXT_AFTER_DOMLIT = 135;
|
||||
const ERR_EXPECTING_QPAIR = 136;
|
||||
const ERR_EXPECTING_ATEXT = 137;
|
||||
const ERR_EXPECTING_QTEXT = 138;
|
||||
const ERR_EXPECTING_CTEXT = 139;
|
||||
const ERR_BACKSLASHEND = 140;
|
||||
const ERR_DOT_START = 141;
|
||||
const ERR_DOT_END = 142;
|
||||
const ERR_DOMAINHYPHENSTART = 143;
|
||||
const ERR_DOMAINHYPHENEND = 144;
|
||||
const ERR_UNCLOSEDQUOTEDSTR = 145;
|
||||
const ERR_UNCLOSEDCOMMENT = 146;
|
||||
const ERR_UNCLOSEDDOMLIT = 147;
|
||||
const ERR_FWS_CRLF_X2 = 148;
|
||||
const ERR_FWS_CRLF_END = 149;
|
||||
const ERR_CR_NO_LF = 150;
|
||||
const ERR_DEPREC_REACHED = 151;
|
||||
const ERR_UNOPENEDCOMMENT = 152;
|
||||
const ERR_ATEXT_AFTER_QS = 134; // not in use
|
||||
const ERR_ATEXT_AFTER_DOMLIT = 135; // not in use
|
||||
const ERR_EXPECTING_QTEXT = 138; // not in use
|
||||
const ERR_BACKSLASHEND = 140; // not in use
|
||||
const ERR_DOMAINHYPHENSTART = 143; // not in use
|
||||
const ERR_UNCLOSEDDOMLIT = 147; // not in use
|
||||
|
||||
/**
|
||||
* Informational validation warnings regarding unusual or
|
||||
* deprecated features found in an email address:
|
||||
*/
|
||||
// Address is valid for SMTP (RFC-5321), but has unusual elements.
|
||||
const RFC5321_TLD = 9;
|
||||
const RFC5321_TLDNUMERIC = 10;
|
||||
const RFC5321_QUOTEDSTRING = 11;
|
||||
const RFC5321_ADDRESSLITERAL = 12;
|
||||
const RFC5321_IPV6DEPRECATED = 13;
|
||||
const CFWS_COMMENT = 17;
|
||||
const CFWS_FWS = 18;
|
||||
const DEPREC_LOCALPART = 33;
|
||||
const DEPREC_FWS = 34;
|
||||
const DEPREC_QTEXT = 35;
|
||||
const DEPREC_QP = 36;
|
||||
const DEPREC_COMMENT = 37;
|
||||
const DEPREC_CTEXT = 38;
|
||||
const DEPREC_CFWS_NEAR_AT = 49;
|
||||
const RFC5321_TLDNUMERIC = 10; // not in use
|
||||
// Address is only valid according to the broad
|
||||
// definition of RFC-5322. It is otherwise invalid.
|
||||
const RFC5322_LOCAL_TOOLONG = 64;
|
||||
const RFC5322_LABEL_TOOLONG = 63;
|
||||
const RFC5322_DOMAIN = 65;
|
||||
const RFC5322_TOOLONG = 66;
|
||||
const RFC5322_DOMAIN_TOOLONG = 255;
|
||||
const RFC5322_DOMAINLITERAL = 70;
|
||||
@@ -62,12 +63,48 @@ class EmailValidator
|
||||
const RFC5322_IPV6_MAXGRPS = 75;
|
||||
const RFC5322_IPV6_COLONSTRT = 76;
|
||||
const RFC5322_IPV6_COLONEND = 77;
|
||||
const RFC5322_DOMAIN = 65; // not in use
|
||||
// Address contains deprecated elements, but may
|
||||
// still be valid in restricted contexts.
|
||||
const DEPREC_QP = 36;
|
||||
const DEPREC_COMMENT = 37;
|
||||
const DEPREC_CFWS_NEAR_AT = 49;
|
||||
const DEPREC_LOCALPART = 33; // not in use
|
||||
const DEPREC_FWS = 34; // not in use
|
||||
const DEPREC_QTEXT = 35; // not in use
|
||||
const DEPREC_CTEXT = 38; // not in use
|
||||
// Address is valid within the message,
|
||||
// but cannot be used unmodified in the envelope.
|
||||
const CFWS_COMMENT = 17;
|
||||
const CFWS_FWS = 18;
|
||||
// Hostname DNS checks were unsuccessful.
|
||||
const DNSWARN_NO_MX_RECORD = 5;
|
||||
const DNSWARN_NO_RECORD = 6;
|
||||
|
||||
/**
|
||||
* @var EmailParser
|
||||
*/
|
||||
protected $parser;
|
||||
|
||||
/**
|
||||
* Contains any informational warnings regarding unusual/deprecated
|
||||
* features that were encountered during validation.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $warnings = array();
|
||||
|
||||
/**
|
||||
* If a critical validation problem is encountered, this will be
|
||||
* set to the value of one of this class's ERR_* constants.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $error;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $threshold = 255;
|
||||
|
||||
public function __construct()
|
||||
@@ -75,6 +112,9 @@ class EmailValidator
|
||||
$this->parser = new EmailParser(new EmailLexer());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValid($email, $checkDNS = false, $strict = false)
|
||||
{
|
||||
try {
|
||||
@@ -86,22 +126,18 @@ class EmailValidator
|
||||
return false;
|
||||
}
|
||||
|
||||
$dns = true;
|
||||
if ($checkDNS) {
|
||||
$dns = $this->checkDNS();
|
||||
}
|
||||
$dnsProblemExists = ($checkDNS ? !$this->checkDNS() : false);
|
||||
|
||||
if ($this->hasWarnings() && ((int) max($this->warnings) > $this->threshold)) {
|
||||
$this->error = self::ERR_DEPREC_REACHED;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return ($strict) ? (!$this->hasWarnings() && $dns) : true;
|
||||
return ($strict ? (!$this->hasWarnings() && !$dnsProblemExists) : true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasWarnings()
|
||||
{
|
||||
@@ -109,7 +145,7 @@ class EmailValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getWarnings()
|
||||
{
|
||||
@@ -117,7 +153,7 @@ class EmailValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
@@ -125,9 +161,7 @@ class EmailValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $threshold
|
||||
*
|
||||
* @return EmailValidator
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setThreshold($threshold)
|
||||
{
|
||||
@@ -137,33 +171,30 @@ class EmailValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getThreshold()
|
||||
{
|
||||
return $this->threshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool Whether or not an MX record exists for the
|
||||
* email address's host name.
|
||||
*/
|
||||
protected function checkDNS()
|
||||
{
|
||||
$checked = false;
|
||||
if (!function_exists('dns_get_record') && (
|
||||
in_array(self::DNSWARN_NO_RECORD, $this->warnings) &&
|
||||
in_array(self::DNSWARN_NO_MX_RECORD, $this->warnings)
|
||||
)) {
|
||||
return $checked;
|
||||
}
|
||||
$host = $this->parser->getParsedDomainPart();
|
||||
$host = rtrim($host, '.') . '.';
|
||||
|
||||
$result = checkdnsrr(trim($this->parser->getParsedDomainPart()), 'MX');
|
||||
$checked = true;
|
||||
$mxRecordExists = checkdnsrr($host, 'MX');
|
||||
|
||||
if (!$result) {
|
||||
if (!$mxRecordExists) {
|
||||
$this->warnings[] = self::DNSWARN_NO_RECORD;
|
||||
$checked = false;
|
||||
$this->addTLDWarnings();
|
||||
}
|
||||
|
||||
return $checked;
|
||||
return $mxRecordExists;
|
||||
}
|
||||
|
||||
protected function addTLDWarnings()
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator;
|
||||
|
||||
/**
|
||||
* EmailValidatorInterface
|
||||
*
|
||||
* @author Chris McCafferty <cilefen@gmail.com>
|
||||
*/
|
||||
interface EmailValidatorInterface
|
||||
{
|
||||
/**
|
||||
* Validates an email address against the following standards:
|
||||
*
|
||||
* RFC-5321: Simple Mail Transfer Protocol
|
||||
* RFC-5322: Internet Message Format
|
||||
* RFC-6530: Overview and Framework for Internationalized Email
|
||||
* RFC-6531: SMTP Extension for Internationalized Email
|
||||
* RFC-6532: Internationalized Email Headers
|
||||
* RFC-1123 section 2.1: Requirements for Internet Hosts -- Application and Support
|
||||
* RFC-4291 section 2.2: IP Version 6 Addressing Architecture
|
||||
*
|
||||
* @param string $email The email address to validate.
|
||||
* @param bool $checkDNS Whether or not the email address's hostname should
|
||||
* be confirmed with a DNS lookup. This only comes
|
||||
* into play if strict mode is also enabled.
|
||||
* @param bool $strict If this is true, and any informational warnings
|
||||
* were raised during validation, the email address
|
||||
* will be considered invalid. Additionally, if
|
||||
* $checkDNS is true and the DNS lookup failed,
|
||||
* the email address will be considered invalid.
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid($email, $checkDNS = false, $strict = false);
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasWarnings();
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getWarnings();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getError();
|
||||
|
||||
/**
|
||||
* @param int $threshold The acceptable number of deprecation warnings.
|
||||
*
|
||||
* @return EmailValidator
|
||||
*/
|
||||
public function setThreshold($threshold);
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getThreshold();
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
namespace Egulias\EmailValidator\Parser;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Parser\Parser;
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
|
||||
class DomainPart extends Parser
|
||||
@@ -23,6 +22,9 @@ class DomainPart extends Parser
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_EMPTY) {
|
||||
throw new \InvalidArgumentException('ERR_NODOMAIN');
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN) {
|
||||
throw new \InvalidArgumentException('ERR_DOMAINHYPHENEND');
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
|
||||
$this->warnings[] = EmailValidator::DEPREC_COMMENT;
|
||||
@@ -100,18 +102,34 @@ class DomainPart extends Parser
|
||||
protected function doParseDomainPart()
|
||||
{
|
||||
$domain = '';
|
||||
$openedParenthesis = 0;
|
||||
$openBrackets = false;
|
||||
do {
|
||||
$prev = $this->lexer->getPrevious();
|
||||
|
||||
$this->checkNotAllowedChars($this->lexer->token);
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
|
||||
$this->parseComments();
|
||||
$openedParenthesis += $this->getOpenedParenthesis();
|
||||
$this->lexer->moveNext();
|
||||
$tmpPrev = $this->lexer->getPrevious();
|
||||
if ($tmpPrev['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
|
||||
$openedParenthesis--;
|
||||
}
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
|
||||
if ($openedParenthesis === 0) {
|
||||
throw new \InvalidArgumentException('ERR_UNOPENEDCOMMENT');
|
||||
} else {
|
||||
$openedParenthesis--;
|
||||
}
|
||||
}
|
||||
|
||||
$this->checkConsecutiveDots();
|
||||
$this->checkDomainPartExceptions($prev);
|
||||
|
||||
if ($this->hasBrackets()) {
|
||||
if ($openBrackets = $this->hasBrackets($openBrackets)) {
|
||||
$this->parseDomainLiteral();
|
||||
}
|
||||
|
||||
@@ -128,6 +146,14 @@ class DomainPart extends Parser
|
||||
return $domain;
|
||||
}
|
||||
|
||||
private function checkNotAllowedChars($token)
|
||||
{
|
||||
$notAllowed = array(EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true);
|
||||
if (isset($notAllowed[$token['type']])) {
|
||||
throw new \InvalidArgumentException('ERR_DOMAIN_CHAR_NOT_ALLOWED');
|
||||
}
|
||||
}
|
||||
|
||||
protected function parseDomainLiteral()
|
||||
{
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_COLON)) {
|
||||
@@ -172,7 +198,7 @@ class DomainPart extends Parser
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_CR)) {
|
||||
throw new \InvalidArgumentException("ERR_CR_NO_LF");
|
||||
throw new \InvalidArgumentException('ERR_CR_NO_LF');
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH) {
|
||||
$this->warnings[] = EmailValidator::RFC5322_DOMLIT_OBSDTEXT;
|
||||
@@ -235,6 +261,17 @@ class DomainPart extends Parser
|
||||
|
||||
protected function checkDomainPartExceptions($prev)
|
||||
{
|
||||
$invalidDomainTokens = array(
|
||||
EmailLexer::S_DQUOTE => true,
|
||||
EmailLexer::S_SEMICOLON => true,
|
||||
EmailLexer::S_GREATERTHAN => true,
|
||||
EmailLexer::S_LOWERTHAN => true,
|
||||
);
|
||||
|
||||
if (isset($invalidDomainTokens[$this->lexer->token['type']])) {
|
||||
throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_COMMA) {
|
||||
throw new \InvalidArgumentException('ERR_COMMA_IN_DOMAIN');
|
||||
}
|
||||
@@ -257,8 +294,12 @@ class DomainPart extends Parser
|
||||
}
|
||||
}
|
||||
|
||||
protected function hasBrackets()
|
||||
protected function hasBrackets($openBrackets)
|
||||
{
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEBRACKET && !$openBrackets) {
|
||||
throw new \InvalidArgumentException('ERR_EXPECTING_OPENBRACKET');
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] !== EmailLexer::S_OPENBRACKET) {
|
||||
return false;
|
||||
}
|
||||
@@ -295,5 +336,4 @@ class DomainPart extends Parser
|
||||
throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,34 +5,39 @@ namespace Egulias\EmailValidator\Parser;
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
|
||||
|
||||
class LocalPart extends Parser
|
||||
{
|
||||
public function parse($localPart)
|
||||
{
|
||||
$parseDQuote = true;
|
||||
$closingQuote = false;
|
||||
$openedParenthesis = 0;
|
||||
|
||||
while ($this->lexer->token['type'] !== EmailLexer::S_AT && $this->lexer->token) {
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT && !$this->lexer->getPrevious()) {
|
||||
throw new \InvalidArgumentException('ERR_DOT_START');
|
||||
}
|
||||
|
||||
$closingQuote = $this->checkDQUOTE($closingQuote);
|
||||
if ($closingQuote && $parseDQuote) {
|
||||
$this->parseDoubleQuote();
|
||||
$parseDQuote = false;
|
||||
$parseDQuote = $this->parseDoubleQuote();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
|
||||
$this->parseComments();
|
||||
$openedParenthesis += $this->getOpenedParenthesis();
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
|
||||
if ($openedParenthesis === 0) {
|
||||
throw new \InvalidArgumentException('ERR_UNOPENEDCOMMENT');
|
||||
} else {
|
||||
$openedParenthesis--;
|
||||
}
|
||||
}
|
||||
|
||||
$this->checkConsecutiveDots();
|
||||
|
||||
if (
|
||||
$this->lexer->token['type'] === EmailLexer::S_DOT &&
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT &&
|
||||
$this->lexer->isNextToken(EmailLexer::S_AT)
|
||||
) {
|
||||
throw new \InvalidArgumentException('ERR_DOT_END');
|
||||
@@ -56,23 +61,51 @@ class LocalPart extends Parser
|
||||
|
||||
protected function parseDoubleQuote()
|
||||
{
|
||||
$special = array (
|
||||
$parseAgain = true;
|
||||
$special = array(
|
||||
EmailLexer::S_CR => true,
|
||||
EmailLexer::S_HTAB => true,
|
||||
EmailLexer::S_LF => true
|
||||
);
|
||||
|
||||
$invalid = array(
|
||||
EmailLexer::C_NUL => true,
|
||||
EmailLexer::S_HTAB => true,
|
||||
EmailLexer::S_CR => true,
|
||||
EmailLexer::S_LF => true
|
||||
);
|
||||
$setSpecialsWarning = true;
|
||||
|
||||
$this->lexer->moveNext();
|
||||
|
||||
while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && $this->lexer->token) {
|
||||
$parseAgain = false;
|
||||
if (isset($special[$this->lexer->token['type']]) && $setSpecialsWarning) {
|
||||
$this->warnings[] = EmailValidator::CFWS_FWS;
|
||||
$setSpecialsWarning = false;
|
||||
}
|
||||
$this->lexer->moveNext();
|
||||
}
|
||||
}
|
||||
|
||||
$this->lexer->moveNext();
|
||||
|
||||
if (!$this->escaped() && isset($invalid[$this->lexer->token['type']])) {
|
||||
throw new \InvalidArgumentException('ERR_EXPECTED_ATEXT');
|
||||
}
|
||||
}
|
||||
|
||||
$prev = $this->lexer->getPrevious();
|
||||
|
||||
if ($prev['type'] === EmailLexer::S_BACKSLASH) {
|
||||
if (!$this->checkDQUOTE(false)) {
|
||||
throw new \InvalidArgumentException('ERR_UNCLOSED_DQUOTE');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->lexer->isNextToken(EmailLexer::S_AT) && $prev['type'] !== EmailLexer::S_BACKSLASH) {
|
||||
throw new \InvalidArgumentException('ERR_EXPECED_AT');
|
||||
}
|
||||
|
||||
return $parseAgain;
|
||||
}
|
||||
|
||||
protected function isInvalidToken($token, $closingQuote)
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ abstract class Parser
|
||||
{
|
||||
protected $warnings = array();
|
||||
protected $lexer;
|
||||
protected $openedParenthesis = 0;
|
||||
|
||||
public function __construct(EmailLexer $lexer)
|
||||
{
|
||||
@@ -20,7 +21,13 @@ abstract class Parser
|
||||
return $this->warnings;
|
||||
}
|
||||
|
||||
abstract function parse($str);
|
||||
abstract public function parse($str);
|
||||
|
||||
/** @return int */
|
||||
public function getOpenedParenthesis()
|
||||
{
|
||||
return $this->openedParenthesis;
|
||||
}
|
||||
|
||||
/**
|
||||
* validateQuotedPair
|
||||
@@ -35,15 +42,15 @@ abstract class Parser
|
||||
$this->warnings[] = EmailValidator::DEPREC_QP;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the the comment
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function parseComments()
|
||||
{
|
||||
$this->openedParenthesis = 1;
|
||||
$this->isUnclosedComment();
|
||||
$this->warnings[] = EmailValidator::CFWS_COMMENT;
|
||||
while (!$this->lexer->isNextToken(EmailLexer::S_CLOSEPARENTHESIS)) {
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_OPENPARENTHESIS)) {
|
||||
$this->openedParenthesis++;
|
||||
}
|
||||
$this->warnEscaping();
|
||||
$this->lexer->moveNext();
|
||||
}
|
||||
@@ -75,11 +82,11 @@ abstract class Parser
|
||||
$this->checkCRLFInFWS();
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_CR) {
|
||||
throw new \InvalidArgumentException("ERR_CR_NO_LF");
|
||||
throw new \InvalidArgumentException('ERR_CR_NO_LF');
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] !== EmailLexer::S_AT) {
|
||||
throw new \InvalidArgumentException("ERR_ATEXT_AFTER_CFWS");
|
||||
throw new \InvalidArgumentException('ERR_ATEXT_AFTER_CFWS');
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_LF || $this->lexer->token['type'] === EmailLexer::C_NUL) {
|
||||
@@ -124,8 +131,7 @@ abstract class Parser
|
||||
|
||||
if ($previous['type'] === EmailLexer::S_BACKSLASH
|
||||
&&
|
||||
($this->lexer->token['type'] === EmailLexer::S_SP ||
|
||||
$this->lexer->token['type'] === EmailLexer::S_HTAB)
|
||||
$this->lexer->token['type'] !== EmailLexer::GENERIC
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
@@ -161,9 +167,10 @@ abstract class Parser
|
||||
return $hasClosingQuote;
|
||||
}
|
||||
$previous = $this->lexer->getPrevious();
|
||||
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] === EmailLexer::GENERIC) {
|
||||
if ($previous['type'] === EmailLexer::GENERIC && $this->lexer->isNextToken(EmailLexer::GENERIC)) {
|
||||
throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
|
||||
}
|
||||
|
||||
$this->warnings[] = EmailValidator::RFC5321_QUOTEDSTRING;
|
||||
try {
|
||||
$this->lexer->find(EmailLexer::S_DQUOTE);
|
||||
@@ -181,10 +188,10 @@ abstract class Parser
|
||||
return;
|
||||
}
|
||||
if ($this->lexer->isNextToken(EmailLexer::CRLF)) {
|
||||
throw new \InvalidArgumentException("ERR_FWS_CRLF_X2");
|
||||
throw new \InvalidArgumentException('ERR_FWS_CRLF_X2');
|
||||
}
|
||||
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
|
||||
throw new \InvalidArgumentException("ERR_FWS_CRLF_END");
|
||||
throw new \InvalidArgumentException('ERR_FWS_CRLF_END');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,73 @@ class EmailLexerTests extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($token, $lexer->token['type']);
|
||||
}
|
||||
|
||||
public function testLexerParsesMultipleSpaces()
|
||||
{
|
||||
$lexer = new EmailLexer();
|
||||
$lexer->setInput(' ');
|
||||
$lexer->moveNext();
|
||||
$lexer->moveNext();
|
||||
$this->assertEquals(EmailLexer::S_SP, $lexer->token['type']);
|
||||
$lexer->moveNext();
|
||||
$this->assertEquals(EmailLexer::S_SP, $lexer->token['type']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidUTF8CharsProvider
|
||||
*/
|
||||
public function testLexerParsesInvalidUTF8($char)
|
||||
{
|
||||
$lexer = new EmailLexer();
|
||||
$lexer->setInput($char);
|
||||
$lexer->moveNext();
|
||||
$lexer->moveNext();
|
||||
|
||||
$this->assertEquals(EmailLexer::INVALID, $lexer->token['type']);
|
||||
}
|
||||
|
||||
public function invalidUTF8CharsProvider()
|
||||
{
|
||||
$chars = array();
|
||||
for ($i = 0; $i < 0x100; ++$i) {
|
||||
$c = $this->utf8Chr($i);
|
||||
if (preg_match('/(?=\p{Cc})(?=[^\t\n\n\r])/u', $c) && !preg_match('/\x{0000}/u', $c)) {
|
||||
$chars[] = array($c);
|
||||
}
|
||||
}
|
||||
|
||||
return $chars;
|
||||
}
|
||||
|
||||
protected function utf8Chr($code_point)
|
||||
{
|
||||
|
||||
if ($code_point < 0 || 0x10FFFF < $code_point || (0xD800 <= $code_point && $code_point <= 0xDFFF)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($code_point < 0x80) {
|
||||
$hex[0] = $code_point;
|
||||
$ret = chr($hex[0]);
|
||||
} elseif ($code_point < 0x800) {
|
||||
$hex[0] = 0x1C0 | $code_point >> 6;
|
||||
$hex[1] = 0x80 | $code_point & 0x3F;
|
||||
$ret = chr($hex[0]).chr($hex[1]);
|
||||
} elseif ($code_point < 0x10000) {
|
||||
$hex[0] = 0xE0 | $code_point >> 12;
|
||||
$hex[1] = 0x80 | $code_point >> 6 & 0x3F;
|
||||
$hex[2] = 0x80 | $code_point & 0x3F;
|
||||
$ret = chr($hex[0]).chr($hex[1]).chr($hex[2]);
|
||||
} else {
|
||||
$hex[0] = 0xF0 | $code_point >> 18;
|
||||
$hex[1] = 0x80 | $code_point >> 12 & 0x3F;
|
||||
$hex[2] = 0x80 | $code_point >> 6 & 0x3F;
|
||||
$hex[3] = 0x80 | $code_point & 0x3F;
|
||||
$ret = chr($hex[0]).chr($hex[1]).chr($hex[2]).chr($hex[3]);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function testLexerForTab()
|
||||
{
|
||||
$lexer = new EmailLexer();
|
||||
@@ -36,6 +103,17 @@ class EmailLexerTests extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(EmailLexer::S_HTAB, $lexer->token['type']);
|
||||
}
|
||||
|
||||
public function testLexerForUTF8()
|
||||
{
|
||||
$lexer = new EmailLexer();
|
||||
$lexer->setInput("áÇ@bar.com");
|
||||
$lexer->moveNext();
|
||||
$lexer->moveNext();
|
||||
$this->assertEquals(EmailLexer::GENERIC, $lexer->token['type']);
|
||||
$lexer->moveNext();
|
||||
$this->assertEquals(EmailLexer::GENERIC, $lexer->token['type']);
|
||||
}
|
||||
|
||||
public function testLexerSearchToken()
|
||||
{
|
||||
$lexer = new EmailLexer();
|
||||
@@ -61,6 +139,7 @@ class EmailLexerTests extends \PHPUnit_Framework_TestCase
|
||||
array("\"", EmailLexer::S_DQUOTE),
|
||||
array("-", EmailLexer::S_HYPHEN),
|
||||
array("\\", EmailLexer::S_BACKSLASH),
|
||||
array("/", EmailLexer::S_SLASH),
|
||||
array("(", EmailLexer::S_OPENPARENTHESIS),
|
||||
array(")", EmailLexer::S_CLOSEPARENTHESIS),
|
||||
array('<', EmailLexer::S_LOWERTHAN),
|
||||
@@ -74,7 +153,9 @@ class EmailLexerTests extends \PHPUnit_Framework_TestCase
|
||||
array('{', EmailLexer::S_OPENQBRACKET),
|
||||
array('}', EmailLexer::S_CLOSEQBRACKET),
|
||||
array('', EmailLexer::S_EMPTY),
|
||||
array(chr(31), EmailLexer::INVALID)
|
||||
array(chr(31), EmailLexer::INVALID),
|
||||
array(chr(226), EmailLexer::GENERIC),
|
||||
array(chr(0), EmailLexer::C_NUL)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,9 +26,18 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($this->validator->isValid($email));
|
||||
}
|
||||
|
||||
public function testInvalidUTF8Email()
|
||||
{
|
||||
$validator = new EmailValidator;
|
||||
$email = "\x80\x81\x82@\x83\x84\x85.\x86\x87\x88";
|
||||
|
||||
$this->assertFalse($validator->isValid($email));
|
||||
}
|
||||
|
||||
public function getValidEmails()
|
||||
{
|
||||
return array(
|
||||
array('â@iana.org'),
|
||||
array('fabien@symfony.com'),
|
||||
array('example@example.co.uk'),
|
||||
array('fabien_potencier@example.fr'),
|
||||
@@ -43,6 +52,19 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
array('"user,name"@example.com'),
|
||||
array('"user name"@example.com'),
|
||||
array('"user@name"@example.com'),
|
||||
array('"\a"@iana.org'),
|
||||
array('"test\ test"@iana.org'),
|
||||
array('""@iana.org'),
|
||||
array('"\""@iana.org'),
|
||||
array('müller@möller.de'),
|
||||
array('test@email*'),
|
||||
array('test@email!'),
|
||||
array('test@email&'),
|
||||
array('test@email^'),
|
||||
array('test@email%'),
|
||||
array('test@email$'),
|
||||
array('test@email.com.au'),
|
||||
array('1500111@профи-инвест.рф'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -57,13 +79,17 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
public function getInvalidEmails()
|
||||
{
|
||||
return array(
|
||||
array('test@example.com test'),
|
||||
array('user name@example.com'),
|
||||
array('user name@example.com'),
|
||||
array('example.@example.co.uk'),
|
||||
array('example@example@example.co.uk'),
|
||||
array('(fabien_potencier@example.fr)'),
|
||||
array('(test_exampel@example.fr)'),
|
||||
array('example(example)example@example.co.uk'),
|
||||
array('.example@localhost'),
|
||||
array('ex\ample@localhost'),
|
||||
array('example@local\host'),
|
||||
array('example@localhost\\'),
|
||||
array('example@localhost.'),
|
||||
array('user name@example.com'),
|
||||
array('username@ example . com'),
|
||||
@@ -72,6 +98,36 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
array('username@example,com'),
|
||||
array('usern,ame@example.com'),
|
||||
array('user[na]me@example.com'),
|
||||
array('"""@iana.org'),
|
||||
array('"\"@iana.org'),
|
||||
array('"test"test@iana.org'),
|
||||
array('"test""test"@iana.org'),
|
||||
array('"test"."test"@iana.org'),
|
||||
array('"test".test@iana.org'),
|
||||
array('"test"' . chr(0) . '@iana.org'),
|
||||
array('"test\"@iana.org'),
|
||||
array(chr(226) . '@iana.org'),
|
||||
array('test@' . chr(226) . '.org'),
|
||||
array('\r\ntest@iana.org'),
|
||||
array('\r\n test@iana.org'),
|
||||
array('\r\n \r\ntest@iana.org'),
|
||||
array('\r\n \r\ntest@iana.org'),
|
||||
array('\r\n \r\n test@iana.org'),
|
||||
array('test@iana.org \r\n'),
|
||||
array('test@iana.org \r\n '),
|
||||
array('test@iana.org \r\n \r\n'),
|
||||
array('test@iana.org \r\n\r\n'),
|
||||
array('test@iana.org \r\n\r\n '),
|
||||
array('test@iana/icann.org'),
|
||||
array('test@foo;bar.com'),
|
||||
array('test;123@foobar.com'),
|
||||
array('test@example..com'),
|
||||
array('email.email@email."'),
|
||||
array('test@email>'),
|
||||
array('test@email<'),
|
||||
array('test@email{'),
|
||||
array('test@email.com]'),
|
||||
array('test@ema[il.com'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -101,6 +157,11 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
array(EmailValidator::ERR_DOT_END, 'example@localhost.'),
|
||||
array(EmailValidator::ERR_DOT_END, 'example.@example.co.uk'),
|
||||
array(EmailValidator::ERR_UNCLOSEDCOMMENT, '(example@localhost'),
|
||||
array(EmailValidator::ERR_UNOPENEDCOMMENT, 'comment)example@localhost'),
|
||||
array(EmailValidator::ERR_UNOPENEDCOMMENT, 'example(comment))@localhost'),
|
||||
array(EmailValidator::ERR_UNOPENEDCOMMENT, 'example@comment)localhost'),
|
||||
array(EmailValidator::ERR_UNOPENEDCOMMENT, 'example@localhost(comment))'),
|
||||
array(EmailValidator::ERR_UNOPENEDCOMMENT, 'example@(comment))example.com'),
|
||||
array(EmailValidator::ERR_UNCLOSEDQUOTEDSTR, '"example@localhost'),
|
||||
array(EmailValidator::ERR_EXPECTING_ATEXT, 'exa"mple@localhost'),
|
||||
//This was the original. But atext is not allowed after \n
|
||||
@@ -124,32 +185,63 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($warnings, $this->validator->getWarnings());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidEmailsWithWarnings
|
||||
*/
|
||||
public function testInvalidEmailsWithDnsCheckAndStrictMode($warnings, $email)
|
||||
{
|
||||
$this->assertFalse($this->validator->isValid($email, true, true));
|
||||
|
||||
$this->assertEquals($warnings, $this->validator->getWarnings());
|
||||
}
|
||||
|
||||
public function getInvalidEmailsWithWarnings()
|
||||
{
|
||||
return array(
|
||||
array(array( EmailValidator::DEPREC_CFWS_NEAR_AT,), 'example @example.co.uk'),
|
||||
array(array( EmailValidator::DEPREC_CFWS_NEAR_AT,), 'example@ example.co.uk'),
|
||||
array(array( EmailValidator::CFWS_COMMENT,), 'example@example(examplecomment).co.uk'),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::DEPREC_CFWS_NEAR_AT,
|
||||
EmailValidator::DNSWARN_NO_RECORD
|
||||
),
|
||||
'example @invalid.example.com'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::DEPREC_CFWS_NEAR_AT,
|
||||
EmailValidator::DNSWARN_NO_RECORD
|
||||
),
|
||||
'example@ invalid.example.com'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::CFWS_COMMENT,
|
||||
EmailValidator::DNSWARN_NO_RECORD
|
||||
),
|
||||
'example@invalid.example(examplecomment).com'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::CFWS_COMMENT,
|
||||
EmailValidator::DEPREC_CFWS_NEAR_AT,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'example(examplecomment)@example.co.uk'
|
||||
'example(examplecomment)@invalid.example.com'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5321_QUOTEDSTRING,
|
||||
EmailValidator::CFWS_FWS,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
"\"\t\"@example.co.uk"
|
||||
"\"\t\"@invalid.example.com"
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5321_QUOTEDSTRING,
|
||||
EmailValidator::CFWS_FWS,
|
||||
EmailValidator::DNSWARN_NO_RECORD
|
||||
),
|
||||
"\"\r\"@example.co.uk"
|
||||
"\"\r\"@invalid.example.com"
|
||||
),
|
||||
array(
|
||||
array(
|
||||
@@ -239,14 +331,16 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5321_QUOTEDSTRING,
|
||||
EmailValidator::DNSWARN_NO_RECORD
|
||||
),
|
||||
'"example"@example.co.uk'
|
||||
'"example"@invalid.example.com'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5322_LOCAL_TOOLONG,
|
||||
EmailValidator::DNSWARN_NO_RECORD
|
||||
),
|
||||
'too_long_localpart_too_long_localpart_too_long_localpart_too_long_localpart@example.co.uk'
|
||||
'too_long_localpart_too_long_localpart_too_long_localpart_too_long_localpart@invalid.example.com'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
@@ -275,6 +369,17 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'parttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpart'.
|
||||
'toolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpar'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'test@test'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function testInvalidEmailsWithStrict()
|
||||
{
|
||||
$this->assertFalse($this->validator->isValid('"test"@test', false, true));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user