mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-08-28 11:07:55 +00:00
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Validation\Error;
|
||||
|
||||
use Egulias\EmailValidator\Exception\InvalidEmail;
|
||||
|
||||
class SpoofEmail extends InvalidEmail
|
||||
{
|
||||
const CODE = 998;
|
||||
const REASON = "The email contains mixed UTF8 chars that makes it suspicious";
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Validation;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Validation\Error\SpoofEmail;
|
||||
use \Spoofchecker;
|
||||
|
||||
class SpoofCheckValidation implements EmailValidation
|
||||
{
|
||||
/**
|
||||
* @var InvalidEmail
|
||||
*/
|
||||
private $error;
|
||||
|
||||
public function isValid($email, EmailLexer $emailLexer)
|
||||
{
|
||||
$checker = new Spoofchecker();
|
||||
$checker->setChecks(Spoofchecker::SINGLE_SCRIPT);
|
||||
|
||||
if ($checker->isSuspicious($email)) {
|
||||
$this->error = new SpoofEmail();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function getWarnings()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\Tests\EmailValidator\Validation;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Validation\SpoofCheckValidation;
|
||||
|
||||
class SpoofCheckValidationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider validUTF8EmailsProvider
|
||||
*/
|
||||
public function testUTF8EmailAreValid($email)
|
||||
{
|
||||
$validation = new SpoofCheckValidation();
|
||||
|
||||
$this->assertTrue($validation->isValid($email, new EmailLexer()));
|
||||
}
|
||||
|
||||
public function testEmailWithSpoofsIsInvalid()
|
||||
{
|
||||
$validation = new SpoofCheckValidation();
|
||||
|
||||
$this->assertFalse($validation->isValid("Кириллица"."latin漢字"."ひらがな"."カタカナ", new EmailLexer()));
|
||||
}
|
||||
|
||||
public function validUTF8EmailsProvider()
|
||||
{
|
||||
return [
|
||||
// Cyrillic
|
||||
['Кириллица@Кириллица'],
|
||||
// Latin + Han + Hiragana + Katakana
|
||||
["latin漢字"."ひらがな"."カタカナ"."@example.com"],
|
||||
// Latin + Han + Hangul
|
||||
["latin"."漢字"."조선말"."@example.com"],
|
||||
// Latin + Han + Bopomofo
|
||||
["latin"."漢字"."ㄅㄆㄇㄈ"."@example.com"]
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user