mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-08-31 12:40:28 +00:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d42c8731f0 | |||
| 515346048d | |||
| 4fc3f5c419 | |||
| 7dc3b8de4c | |||
| 3bd9c8c802 | |||
| 8be1dae097 | |||
| dcf8f79c41 | |||
| e30356b45e | |||
| 229560066e | |||
| 1ed7ade52c | |||
| 793eb01a3f | |||
| 32b52d9e08 | |||
| b115554301 | |||
| c67e8e655f | |||
| 2647beedf3 | |||
| e25ccf7e74 | |||
| d379dc240b | |||
| 621d46003b | |||
| 87db43e4ff | |||
| c118cc7666 | |||
| b4a1a0e5a6 | |||
| 92c1ab0cc1 | |||
| 8775776563 | |||
| 87b8b8506e |
@@ -3,5 +3,4 @@
|
|||||||
/.* export-ignore
|
/.* export-ignore
|
||||||
/phpunit.xml.dist export-ignore
|
/phpunit.xml.dist export-ignore
|
||||||
/psalm.xml export-ignore
|
/psalm.xml export-ignore
|
||||||
/psalm.baseline.xml export-ignore
|
|
||||||
/README.md export-ignore
|
/README.md export-ignore
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "composer"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
@@ -3,7 +3,6 @@ name: static analysis
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
|
||||||
- '*.x'
|
- '*.x'
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
@@ -18,7 +17,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
name: build
|
name: unit-tests
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
|
||||||
- '*.x'
|
- '*.x'
|
||||||
pull_request:
|
pull_request:
|
||||||
schedule:
|
|
||||||
- cron: '0 0 * * *'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tests:
|
tests:
|
||||||
@@ -27,7 +24,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
@@ -38,7 +35,7 @@ jobs:
|
|||||||
coverage: xdebug
|
coverage: xdebug
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
uses: ramsey/composer-install@v2
|
uses: ramsey/composer-install@v3
|
||||||
with:
|
with:
|
||||||
dependency-versions: ${{ matrix.deps }}
|
dependency-versions: ${{ matrix.deps }}
|
||||||
|
|
||||||
@@ -47,15 +44,10 @@ jobs:
|
|||||||
|
|
||||||
- name: Execute tests
|
- name: Execute tests
|
||||||
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml --exclude-group flaky
|
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml --exclude-group flaky
|
||||||
- name: Coverage
|
|
||||||
if: ${{ matrix.php == '8.1' && matrix.deps == 'lowest' }}
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
|
|
||||||
run: bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r build/logs/clover.xml
|
|
||||||
|
|
||||||
- name: Store artifacts
|
- name: Store artifacts
|
||||||
uses: actions/upload-artifact@v3
|
if: ${{ matrix.php == '8.1' && matrix.deps == 'lowest' }}
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: logs
|
name: clover.xml
|
||||||
path: build/logs
|
path: build/logs
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
name: upload-coverage-to-codacy
|
||||||
|
on:
|
||||||
|
workflow_run:
|
||||||
|
workflows: ["unit-tests"]
|
||||||
|
types:
|
||||||
|
- completed
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
upload:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: >
|
||||||
|
github.event.workflow_run.event == 'pull_request' &&
|
||||||
|
github.event.workflow_run.conclusion == 'success'
|
||||||
|
strategy:
|
||||||
|
fail-fast: true
|
||||||
|
name: upload-coverage
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Setup logs directory
|
||||||
|
run: mkdir -p build/coverage
|
||||||
|
- name: Download clover.xml artifact
|
||||||
|
uses: dawidd6/action-download-artifact@v7
|
||||||
|
with:
|
||||||
|
workflow: tests.yml
|
||||||
|
name: clover.xml
|
||||||
|
path: build/coverage
|
||||||
|
|
||||||
|
- name: Upload Coverage to Codacy
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
|
||||||
|
|
||||||
|
run: bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r build/coverage/clover.xml
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
# EmailValidator Changelog
|
|
||||||
|
|
||||||
## New Features
|
|
||||||
|
|
||||||
* Access to local part and domain part from EmailParser
|
|
||||||
* Validations outside of the scope of the RFC will be considered "extra" validations, thus opening the door for adding new; will live in their own folder "extra" (as requested in #248, #195, #183).
|
|
||||||
|
|
||||||
## Breaking changes
|
|
||||||
|
|
||||||
* PHP version upgraded to match Symfony's (as of 12/2020).
|
|
||||||
* DNSCheckValidation now fails for missing MX records. While the RFC argues that the existence of only A records to be valid, starting in v3 they will be considered invalid.
|
|
||||||
* Emails domain part are now intenteded to be RFC 1035 compliant, rendering previous valid emails (e.g example@examp&) invalid.
|
|
||||||
|
|
||||||
## PHP versions upgrade policy
|
|
||||||
PHP version upgrade requirement will happen via MINOR (3.x) version upgrades of the library, following the adoption level by major frameworks.
|
|
||||||
|
|
||||||
## Changes
|
|
||||||
* #235
|
|
||||||
* #215
|
|
||||||
* #130
|
|
||||||
* #258
|
|
||||||
* #188
|
|
||||||
* #181
|
|
||||||
* #217
|
|
||||||
* #214
|
|
||||||
* #249
|
|
||||||
* #236
|
|
||||||
* #257
|
|
||||||
* #210
|
|
||||||
|
|
||||||
## Thanks
|
|
||||||
To contributors, be it with PRs, reporting issues or supporting otherwise.
|
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
# EmailValidator
|
# EmailValidator
|
||||||
|
|
||||||
[](https://github.com/egulias/EmailValidator/actions)
|
[](https://github.com/egulias/EmailValidator/actions/workflows/tests.yml)
|
||||||
[](https://app.codacy.com/gh/egulias/EmailValidator/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
[](https://app.codacy.com/gh/egulias/EmailValidator/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
||||||
[](https://app.codacy.com/gh/egulias/EmailValidator/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
[](https://app.codacy.com/gh/egulias/EmailValidator/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
||||||
|

|
||||||
|
|
||||||
A library for validating emails against several RFC.
|
A library for validating emails against several RFC.
|
||||||
|
|
||||||
@@ -19,23 +20,27 @@ This library aims to support RFCs:
|
|||||||
|
|
||||||
## Supported versions
|
## Supported versions
|
||||||
|
|
||||||
**Current major version with full support is v3**
|
|
||||||
|
|
||||||
| Version | Released | EOL | Only critical bug fixes | Full |
|
| Version | Released | EOL | Only critical bug fixes | Full |
|
||||||
|:-------:|:----------:|:---:|:-----------------------:|:----:|
|
|:-------:|:----------:|:---:|:-----------------------:|:----:|
|
||||||
| v4.x | 2023/01/07 | - | X | X |
|
|**v4.x** |**2023/01/07** | - | **X** |**X** |
|
||||||
| v3.x | 2020/12/29 | - | X | |
|
| v3.x | 2020/12/29 | YES | | |
|
||||||
| v2.1.x | 2016/05/16 | YES | | |
|
| v2.1.x | 2016/05/16 | YES | | |
|
||||||
| v1.2 | 2013/19/05 | YES | | |
|
| v1.2 | 2013/19/05 | YES | | |
|
||||||
|
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* PHP 8.1
|
* PHP 8.1
|
||||||
* [Composer](https://getcomposer.org) is required for installation
|
* [Composer](https://getcomposer.org) is required for installation
|
||||||
* [Spoofchecking](/src/Validation/Extra/SpoofCheckValidation.php) and [DNSCheckValidation](/src/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)
|
* [Spoofchecking](/src/Validation/Extra/SpoofCheckValidation.php) and
|
||||||
|
[DNSCheckValidation](/src/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)
|
||||||
|
|
||||||
**Note**: `PHP version upgrades will happen to accomodate to the pace of major frameworks. Minor versions bumps will go via minor versions of this library (i.e: PHP7.3 -> v3.x+1). Major versions will go with major versions of the library`
|
**Note**: `PHP version upgrades will happen to accomodate to the pace of major
|
||||||
|
frameworks. Minor versions bumps will go via minor versions of this library
|
||||||
|
(i.e: PHP7.3 -> v3.x+1). Major versions will go with major versions
|
||||||
|
of the library`
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -47,9 +52,12 @@ composer require egulias/email-validator
|
|||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
`EmailValidator` requires you to decide which (or combination of them) validation/s strategy/ies you'd like to follow for each [validation](#available-validations).
|
`EmailValidator` requires you to decide which (or combination of them)
|
||||||
|
validation/s strategy/ies you'd like to follow for each
|
||||||
|
[validation](#available-validations).
|
||||||
|
|
||||||
A basic example with the RFC validation
|
A basic example with the RFC validation
|
||||||
|
|
||||||
```php
|
```php
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
@@ -60,17 +68,22 @@ $validator = new EmailValidator();
|
|||||||
$validator->isValid("example@example.com", new RFCValidation()); //true
|
$validator->isValid("example@example.com", new RFCValidation()); //true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Available validations
|
### Available validations
|
||||||
|
|
||||||
1. [RFCValidation](/src/Validation/RFCValidation.php): Standard RFC-like email validation.
|
1. [RFCValidation](/src/Validation/RFCValidation.php): Standard RFC-like email validation.
|
||||||
2. [NoRFCWarningsValidation](/src/Validation/NoRFCWarningsValidation.php): RFC-like validation that will fail when warnings* are found.
|
2. [NoRFCWarningsValidation](/src/Validation/NoRFCWarningsValidation.php):
|
||||||
3. [DNSCheckValidation](/src/Validation/DNSCheckValidation.php): Will check if there are DNS records that signal that the server accepts emails. This does not entail that the email exists.
|
RFC-like validation that will fail when warnings* are found.
|
||||||
4. [MultipleValidationWithAnd](/src/Validation/MultipleValidationWithAnd.php): It is a validation that operates over other validations performing a logical and (&&) over the result of each validation.
|
3. [DNSCheckValidation](/src/Validation/DNSCheckValidation.php):
|
||||||
5. [MessageIDValidation](/src/Validation/MessageIDValidation.php): Follows [RFC2822 for message-id](https://tools.ietf.org/html/rfc2822#section-3.6.4) to validate that field, that has some differences in the domain part.
|
Will check if there are DNS records that signal that the server accepts emails. This does not entail that the email exists.
|
||||||
6. [Your own validation](#how-to-extend): You can extend the library behaviour by implementing your own validations.
|
4. [MultipleValidationWithAnd](/src/Validation/MultipleValidationWithAnd.php):
|
||||||
|
It is a validation that operates over other validations performing a logical and (&&) over the result of each validation.
|
||||||
|
5. [MessageIDValidation](/src/Validation/MessageIDValidation.php):
|
||||||
|
Follows [RFC2822 for message-id](https://tools.ietf.org/html/rfc2822#section-3.6.4) to validate that field, that has some differences in the domain part.
|
||||||
|
6. [Your own validation](#how-to-extend): You can extend the library behaviour
|
||||||
|
by implementing your own validations.
|
||||||
|
|
||||||
*warnings: Warnings are deviations from the RFC that in a broader interpretation are accepted.
|
*warnings: Warnings are deviations from the RFC that in a broader interpretation
|
||||||
|
are accepted.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
<?php
|
<?php
|
||||||
@@ -90,28 +103,37 @@ $validator->isValid("example@ietf.org", $multipleValidations); //true
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### Additional validations
|
#### Additional validations
|
||||||
|
|
||||||
Validations not present in the RFCs
|
Validations not present in the RFCs
|
||||||
|
|
||||||
1. [SpoofCheckValidation](/src/Validation/Extra/SpoofCheckValidation.php): Will check for multi-utf-8 chars that can signal an erroneous email name.
|
1. [SpoofCheckValidation](/src/Validation/Extra/SpoofCheckValidation.php):
|
||||||
|
Will check for multi-utf-8 chars that can signal an erroneous email name.
|
||||||
|
|
||||||
### How to extend
|
### How to extend
|
||||||
|
|
||||||
It's easy! You just need to implement [EmailValidation](/src/Validation/EmailValidation.php) and you can use your own validation.
|
It's easy! You just need to implement
|
||||||
|
[EmailValidation](/src/Validation/EmailValidation.php) and you can use your own
|
||||||
|
validation.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Please follow the [Contribution guide](CONTRIBUTING.md). Is short and simple and will help a lot.
|
Please follow the [Contribution guide](CONTRIBUTING.md).
|
||||||
|
Is short and simple and will help a lot.
|
||||||
|
|
||||||
## Other Contributors
|
## Other Contributors
|
||||||
|
|
||||||
(You can find current contributors [here](https://github.com/egulias/EmailValidator/graphs/contributors))
|
(You can find current contributors
|
||||||
|
[here](https://github.com/egulias/EmailValidator/graphs/contributors))
|
||||||
|
|
||||||
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](https://github.com/ricardclau): Performance against PHP built-in filter_var (v2 and earlier)
|
* Ricard Clau [@ricardclau](https://github.com/ricardclau):
|
||||||
* Josepf Bielawski [@stloyd](https://github.com/stloyd): For its first re-work of Dominic's lib
|
Performance against PHP built-in filter_var (v2 and earlier)
|
||||||
* Dominic Sayers [@dominicsayers](https://github.com/dominicsayers): The original isemail function
|
* Josepf Bielawski [@stloyd](https://github.com/stloyd):
|
||||||
|
For its first re-work of Dominic's lib
|
||||||
|
* Dominic Sayers [@dominicsayers](https://github.com/dominicsayers):
|
||||||
|
The original `isemail` function
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<files psalm-version="5.4.0@62db5d4f6a7ae0a20f7cc5a4952d730272fc0863">
|
|
||||||
<file src="src/Parser/DomainPart.php">
|
|
||||||
<RedundantConditionGivenDocblockType occurrences="1">
|
|
||||||
<code>null !== $this->lexer->token['type']</code>
|
|
||||||
</RedundantConditionGivenDocblockType>
|
|
||||||
</file>
|
|
||||||
</files>
|
|
||||||
@@ -3,7 +3,11 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns="https://getpsalm.org/schema/config"
|
xmlns="https://getpsalm.org/schema/config"
|
||||||
xsi:schemaLocation="https://getpsalm.org/schema/config ./vendor/vimeo/psalm/config.xsd"
|
xsi:schemaLocation="https://getpsalm.org/schema/config ./vendor/vimeo/psalm/config.xsd"
|
||||||
errorBaseline="psalm.baseline.xml"
|
errorLevel="1"
|
||||||
|
findUnusedCode="false"
|
||||||
|
findUnusedPsalmSuppress="true"
|
||||||
|
disableSuppressAll="true"
|
||||||
|
findUnusedVariablesAndParams="true"
|
||||||
>
|
>
|
||||||
<projectFiles>
|
<projectFiles>
|
||||||
<directory name="src" />
|
<directory name="src" />
|
||||||
@@ -11,13 +15,4 @@
|
|||||||
<directory name="vendor" />
|
<directory name="vendor" />
|
||||||
</ignoreFiles>
|
</ignoreFiles>
|
||||||
</projectFiles>
|
</projectFiles>
|
||||||
|
|
||||||
<issueHandlers>
|
|
||||||
<DeprecatedMethod>
|
|
||||||
<errorLevel type="suppress">
|
|
||||||
<!-- This issue needs to be resolved before upgrading to Lexer 3 -->
|
|
||||||
<referencedMethod name="Doctrine\Common\Lexer\Token::offsetGet"/>
|
|
||||||
</errorLevel>
|
|
||||||
</DeprecatedMethod>
|
|
||||||
</issueHandlers>
|
|
||||||
</psalm>
|
</psalm>
|
||||||
|
|||||||
+1
-2
@@ -61,7 +61,7 @@ class EmailLexer extends AbstractLexer
|
|||||||
/**
|
/**
|
||||||
* US-ASCII visible characters not valid for atext (@link http://tools.ietf.org/html/rfc5322#section-3.2.3)
|
* US-ASCII visible characters not valid for atext (@link http://tools.ietf.org/html/rfc5322#section-3.2.3)
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array<string, int>
|
||||||
*/
|
*/
|
||||||
protected $charValue = [
|
protected $charValue = [
|
||||||
'{' => self::S_OPENCURLYBRACES,
|
'{' => self::S_OPENCURLYBRACES,
|
||||||
@@ -177,7 +177,6 @@ class EmailLexer extends AbstractLexer
|
|||||||
* @throws \UnexpectedValueException
|
* @throws \UnexpectedValueException
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*
|
*
|
||||||
* @psalm-suppress InvalidScalarArgument
|
|
||||||
*/
|
*/
|
||||||
public function find($type): bool
|
public function find($type): bool
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,11 +8,12 @@ use Egulias\EmailValidator\Result\ValidEmail;
|
|||||||
use Egulias\EmailValidator\Warning\CFWSNearAt;
|
use Egulias\EmailValidator\Warning\CFWSNearAt;
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
use Egulias\EmailValidator\Result\InvalidEmail;
|
||||||
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT;
|
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT;
|
||||||
|
use Egulias\EmailValidator\Warning\Warning;
|
||||||
|
|
||||||
class LocalComment implements CommentStrategy
|
class LocalComment implements CommentStrategy
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array<int, Warning>
|
||||||
*/
|
*/
|
||||||
private $warnings = [];
|
private $warnings = [];
|
||||||
|
|
||||||
|
|||||||
@@ -307,6 +307,7 @@ class DomainPart extends PartParser
|
|||||||
{
|
{
|
||||||
if (preg_match('/[^\x00-\x7F]/', $label)) {
|
if (preg_match('/[^\x00-\x7F]/', $label)) {
|
||||||
idn_to_ascii($label, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46, $idnaInfo);
|
idn_to_ascii($label, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46, $idnaInfo);
|
||||||
|
/** @psalm-var array{errors: int, ...} $idnaInfo */
|
||||||
return (bool) ($idnaInfo['errors'] & IDNA_ERROR_LABEL_TOO_LONG);
|
return (bool) ($idnaInfo['errors'] & IDNA_ERROR_LABEL_TOO_LONG);
|
||||||
}
|
}
|
||||||
return strlen($label) > self::LABEL_MAX_LENGTH;
|
return strlen($label) > self::LABEL_MAX_LENGTH;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class LocalPart extends PartParser
|
|||||||
|
|
||||||
public function parse(): Result
|
public function parse(): Result
|
||||||
{
|
{
|
||||||
|
$this->lexer->clearRecorded();
|
||||||
$this->lexer->startRecording();
|
$this->lexer->startRecording();
|
||||||
|
|
||||||
while (!$this->lexer->current->isA(EmailLexer::S_AT) && !$this->lexer->current->isA(EmailLexer::S_EMPTY)) {
|
while (!$this->lexer->current->isA(EmailLexer::S_AT) && !$this->lexer->current->isA(EmailLexer::S_EMPTY)) {
|
||||||
|
|||||||
@@ -11,6 +11,6 @@ class NoDNSRecord implements Reason
|
|||||||
|
|
||||||
public function description() : string
|
public function description() : string
|
||||||
{
|
{
|
||||||
return 'No MX or A DSN record was found for this email';
|
return 'No MX or A DNS record was found for this email';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,22 +6,26 @@ interface Result
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Is validation result valid?
|
* Is validation result valid?
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function isValid() : bool;
|
public function isValid(): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is validation result invalid?
|
* Is validation result invalid?
|
||||||
* Usually the inverse of isValid()
|
* Usually the inverse of isValid()
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function isInvalid() : bool;
|
public function isInvalid(): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short description of the result, human readable.
|
* Short description of the result, human readable.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function description() : string;
|
public function description(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Code for user land to act upon.
|
* Code for user land to act upon.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function code() : int;
|
public function code(): int;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ class DNSGetRecordWrapper
|
|||||||
public function getRecords(string $host, int $type): DNSRecords
|
public function getRecords(string $host, int $type): DNSRecords
|
||||||
{
|
{
|
||||||
// A workaround to fix https://bugs.php.net/bug.php?id=73149
|
// A workaround to fix https://bugs.php.net/bug.php?id=73149
|
||||||
/** @psalm-suppress InvalidArgument */
|
|
||||||
set_error_handler(
|
set_error_handler(
|
||||||
static function (int $errorLevel, string $errorMessage): never {
|
static function (int $errorLevel, string $errorMessage): never {
|
||||||
throw new \RuntimeException("Unable to get DNS record for the host: $errorMessage");
|
throw new \RuntimeException("Unable to get DNS record for the host: $errorMessage");
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace Egulias\EmailValidator\Validation;
|
|||||||
class DNSRecords
|
class DNSRecords
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param array $records
|
* @param list<array<array-key, mixed>> $records
|
||||||
* @param bool $error
|
* @param bool $error
|
||||||
*/
|
*/
|
||||||
public function __construct(private readonly array $records, private readonly bool $error = false)
|
public function __construct(private readonly array $records, private readonly bool $error = false)
|
||||||
@@ -13,7 +13,7 @@ class DNSRecords
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return list<array<array-key, mixed>>
|
||||||
*/
|
*/
|
||||||
public function getRecords(): array
|
public function getRecords(): array
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ class SpoofCheckValidation implements EmailValidation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @psalm-suppress InvalidArgument
|
|
||||||
*/
|
|
||||||
public function isValid(string $email, EmailLexer $emailLexer) : bool
|
public function isValid(string $email, EmailLexer $emailLexer) : bool
|
||||||
{
|
{
|
||||||
$checker = new Spoofchecker();
|
$checker = new Spoofchecker();
|
||||||
|
|||||||
@@ -2,16 +2,26 @@
|
|||||||
|
|
||||||
namespace Egulias\EmailValidator\Warning;
|
namespace Egulias\EmailValidator\Warning;
|
||||||
|
|
||||||
|
use UnitEnum;
|
||||||
|
|
||||||
class QuotedPart extends Warning
|
class QuotedPart extends Warning
|
||||||
{
|
{
|
||||||
public const CODE = 36;
|
public const CODE = 36;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param scalar|null $prevToken
|
* @param UnitEnum|string|int|null $prevToken
|
||||||
* @param scalar|null $postToken
|
* @param UnitEnum|string|int|null $postToken
|
||||||
*/
|
*/
|
||||||
public function __construct($prevToken, $postToken)
|
public function __construct($prevToken, $postToken)
|
||||||
{
|
{
|
||||||
|
if ($prevToken instanceof UnitEnum) {
|
||||||
|
$prevToken = $prevToken->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($postToken instanceof UnitEnum) {
|
||||||
|
$postToken = $postToken->name;
|
||||||
|
}
|
||||||
|
|
||||||
$this->message = "Deprecated Quoted String found between $prevToken and $postToken";
|
$this->message = "Deprecated Quoted String found between $prevToken and $postToken";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ class QuotedString extends Warning
|
|||||||
public const CODE = 11;
|
public const CODE = 11;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param scalar $prevToken
|
* @param string|int $prevToken
|
||||||
* @param scalar $postToken
|
* @param string|int $postToken
|
||||||
*/
|
*/
|
||||||
public function __construct($prevToken, $postToken)
|
public function __construct($prevToken, $postToken)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,4 +28,18 @@ class EmailParserTest extends TestCase
|
|||||||
$this->assertEquals($local, $parser->getLocalPart());
|
$this->assertEquals($local, $parser->getLocalPart());
|
||||||
$this->assertEquals($domain, $parser->getDomainPart());
|
$this->assertEquals($domain, $parser->getDomainPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMultipleEmailAddresses()
|
||||||
|
{
|
||||||
|
$parser = new EmailParser(new EmailLexer());
|
||||||
|
$parser->parse('some-local-part@some-random-but-large-domain-part.example.com');
|
||||||
|
|
||||||
|
$this->assertSame('some-local-part', $parser->getLocalPart());
|
||||||
|
$this->assertSame('some-random-but-large-domain-part.example.com', $parser->getDomainPart());
|
||||||
|
|
||||||
|
$parser->parse('another-local-part@another.example.com');
|
||||||
|
|
||||||
|
$this->assertSame('another-local-part', $parser->getLocalPart());
|
||||||
|
$this->assertSame('another.example.com', $parser->getDomainPart());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,9 @@ class DNSCheckValidationTest extends TestCase
|
|||||||
['"Fred\ Bloggs"@ietf.org'],
|
['"Fred\ Bloggs"@ietf.org'],
|
||||||
['"Joe.\\Blow"@ietf.org'],
|
['"Joe.\\Blow"@ietf.org'],
|
||||||
|
|
||||||
// unicide
|
// unicode
|
||||||
['ñandu.cl'],
|
['info@ñandu.cl'],
|
||||||
|
['ñandu@ñandu.cl'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -150,6 +150,8 @@ class RFCValidationTest extends TestCase
|
|||||||
['\r\n \r\n test@iana.org'],
|
['\r\n \r\n test@iana.org'],
|
||||||
['test;123@foobar.com'],
|
['test;123@foobar.com'],
|
||||||
['examp║le@symfony.com'],
|
['examp║le@symfony.com'],
|
||||||
|
['example@invalid-.domain.com'],
|
||||||
|
['example@-invalid.com'],
|
||||||
['0'],
|
['0'],
|
||||||
[0],
|
[0],
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user