The local-part of a mailbox MUST BE treated as case sensitive.
This commit is contained in:
bkrukowski 2016-09-10 01:39:01 +02:00
parent 73e7970c5c
commit 270cc2d831
7 changed files with 27 additions and 8 deletions

View File

@ -24,9 +24,12 @@ class Gordianus
private $services;
public function __construct(array $services = self::ALL_SERVICES)
private $caseSensitiveLocalPart;
public function __construct(array $services = self::ALL_SERVICES, bool $caseSensitiveLocalPart = false)
{
$this->services = $services;
$this->caseSensitiveLocalPart = $caseSensitiveLocalPart;
}
/**
@ -37,8 +40,10 @@ class Gordianus
public function getPrimaryEmail(string $email)
{
$this->validateEmailAddress($email);
$email = strtolower($email);
list(, $domain) = explode('@', $email);
if (!$this->caseSensitiveLocalPart) {
$email = strtolower($email);
}
$domain = strtolower(explode('@', $email)[1]);
$result = $email;
foreach ($this->services as $serviceClass) {

View File

@ -9,13 +9,13 @@ class GmailCOM implements ServiceInterface
{
public function getPrimaryEmail(string $email) : string
{
list($name, $domain) = explode('@', $email);
list($name, $domain) = explode('@', strtolower($email));
return explode('+', str_replace('.', '', $name))[0] . '@' . $domain;
}
public function isDomainSupported(string $domain) : bool
{
return $domain === 'gmail.com';
return strtolower($domain) === 'gmail.com';
}
}

View File

@ -9,12 +9,20 @@ abstract class MultiDomain implements ServiceInterface
{
public function getPrimaryEmail(string $email) : string
{
if (!$this->isCaseSensitive()) {
$email = strtolower($email);
}
return explode('@', $email)[0] . '@' . $this->getPrimaryDomain();
}
public function isDomainSupported(string $domain) : bool
{
return in_array($domain, $this->getDomainList());
return in_array(strtolower($domain), $this->getDomainList());
}
protected function isCaseSensitive() : bool
{
return false;
}
abstract protected function getPrimaryDomain() : string;

View File

@ -9,13 +9,13 @@ class WWW33MailCOM implements ServiceInterface
{
public function getPrimaryEmail(string $email) : string
{
list(, $domain) = explode('@', $email);
list(, $domain) = explode('@', strtolower($email));
return preg_replace('/\\.33mail\\.com$/', '', $domain) . '@' . $domain;
}
public function isDomainSupported(string $domain) : bool
{
return (bool) preg_match('/\\.33mail\\.com$/', $domain);
return (bool) preg_match('/\\.33mail\\.com$/', strtolower($domain));
}
}

View File

@ -46,6 +46,8 @@ class GordianusTest extends \PHPUnit_Framework_TestCase
return [
[new Gordianus([Gordianus::SERVICE_TLEN_PL]), 'john.doe+alias@gmail.com', 'john.doe+alias@gmail.com'],
[new Gordianus(), 'john.doe+alias@gmail.com', 'johndoe@gmail.com'],
[new Gordianus([]), 'John.Doe@example.com', 'john.doe@example.com'],
[new Gordianus([], true), 'John.Doe@example.com', 'John.Doe@example.com'],
];
}
}

View File

@ -21,6 +21,7 @@ class GmailCOMTest extends \PHPUnit_Framework_TestCase
{
return [
['foo.bar@gmail.com', 'foobar@gmail.com'],
['Foo.Bar@GMAIL.COM', 'foobar@gmail.com'],
['foobar+alias@gmail.com', 'foobar@gmail.com'],
['fo.ob.ar+alias@gmail.com', 'foobar@gmail.com'],
];
@ -41,6 +42,7 @@ class GmailCOMTest extends \PHPUnit_Framework_TestCase
{
return [
['gmail.com', true],
['gmail.COM', true],
['google.com', false],
['gmailcom', false],
['g.mail.com', false]

View File

@ -22,6 +22,7 @@ class WWW33MailCOMTest extends \PHPUnit_Framework_TestCase
return [
['foo.33mail.com', true],
['bar.33mail.com', true],
['bar.33Mail.Com', true],
['foo.34mail.com', false],
['foo33mail.com', false],
];
@ -43,6 +44,7 @@ class WWW33MailCOMTest extends \PHPUnit_Framework_TestCase
return [
['qwerty@name.33mail.com', 'name@name.33mail.com'],
['lorem@ipsum.33mail.com', 'ipsum@ipsum.33mail.com'],
['lorem@Ipsum.33mail.com', 'ipsum@ipsum.33mail.com'],
];
}
}