diff --git a/src/Gordianus.php b/src/Gordianus.php index 29a43b1..5d6807b 100644 --- a/src/Gordianus.php +++ b/src/Gordianus.php @@ -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) { diff --git a/src/Services/GmailCOM.php b/src/Services/GmailCOM.php index a1c496f..a933ea1 100644 --- a/src/Services/GmailCOM.php +++ b/src/Services/GmailCOM.php @@ -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'; } } \ No newline at end of file diff --git a/src/Services/MultiDomain.php b/src/Services/MultiDomain.php index 4ac1233..3f71076 100644 --- a/src/Services/MultiDomain.php +++ b/src/Services/MultiDomain.php @@ -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; diff --git a/src/Services/WWW33MailCOM.php b/src/Services/WWW33MailCOM.php index 32b9110..fa40b72 100644 --- a/src/Services/WWW33MailCOM.php +++ b/src/Services/WWW33MailCOM.php @@ -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)); } } \ No newline at end of file diff --git a/tests/GordianusTest.php b/tests/GordianusTest.php index f4fd7e8..1fb79a8 100644 --- a/tests/GordianusTest.php +++ b/tests/GordianusTest.php @@ -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'], ]; } } \ No newline at end of file diff --git a/tests/Services/GmailCOMTest.php b/tests/Services/GmailCOMTest.php index f220938..36ea4bf 100644 --- a/tests/Services/GmailCOMTest.php +++ b/tests/Services/GmailCOMTest.php @@ -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] diff --git a/tests/Services/WWW33MailCOMTest.php b/tests/Services/WWW33MailCOMTest.php index 4fe82d9..cbda8ab 100644 --- a/tests/Services/WWW33MailCOMTest.php +++ b/tests/Services/WWW33MailCOMTest.php @@ -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'], ]; } } \ No newline at end of file