diff --git a/README.md b/README.md index 700b80a..c9e40e8 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ To detect multi-accounts on your website. * [33mail.com](https://www.33mail.com) * [outlook.com](http://outlook.com) * [yahoo.com](http://mail.yahoo.com) +* [yandex.ru](https://yandex.ru/) +* [mail.ru](https://mail.ru/) ## Usage diff --git a/src/Services/MailRU.php b/src/Services/MailRU.php new file mode 100644 index 0000000..8cdf217 --- /dev/null +++ b/src/Services/MailRU.php @@ -0,0 +1,23 @@ +removeSuffixAlias('+') + ->lowerCaseLocalPartIf(true); + } + + public function isSupported(EmailInterface $email) : bool + { + return in_array($email->getDomain(), ['mail.ru']); + } +} \ No newline at end of file diff --git a/src/Services/YandexRu.php b/src/Services/YandexRu.php new file mode 100644 index 0000000..20ffcf3 --- /dev/null +++ b/src/Services/YandexRu.php @@ -0,0 +1,36 @@ +removeSuffixAlias('+') + ->lowerCaseLocalPartIf(true) + ->setDomain($this->mapDomain($email->getDomain())); + } + + public function isSupported(EmailInterface $email) : bool + { + return in_array($email->getDomain(), ['ya.ru', 'yandex.ru']); + } + + protected function getDomainMapping() : array + { + return [ + 'ya.ru' => 'yandex.ru', + ]; + } + + private function mapDomain(string $domain) : string + { + return $this->getDomainMapping()[$domain] ?? $domain; + } +} \ No newline at end of file diff --git a/tests/Emails/EditableEmailTest.php b/tests/Emails/EditableEmailTest.php index cd2f60b..c8c2735 100644 --- a/tests/Emails/EditableEmailTest.php +++ b/tests/Emails/EditableEmailTest.php @@ -28,6 +28,8 @@ class EditableEmailTest extends \PHPUnit_Framework_TestCase return [ [new Email('jane.doe.1990@gmail.com'), '.'], [new Email('janedoe1990@gmail.com'), '.'], + [new Email('jane.doe.1990@yandex.ru'), '.'], + [new Email('janedoe1990@yandex.ru'), '.'], ]; } @@ -53,6 +55,8 @@ class EditableEmailTest extends \PHPUnit_Framework_TestCase [new Email('John.Doe+alias@gmail.com', true), '+', 'John.Doe@gmail.com'], [new Email('JohnDoe-alias@gmail.com'), '-', 'johndoe@gmail.com'], [new Email('JohnDoe@gmail.com'), '-', 'johndoe@gmail.com'], + [new Email('JohnDoe+alias@yandex.ru'), '+', 'johndoe@yandex.ru'], + [new Email('JohnDoe+alias@mail.ru'), '+', 'johndoe@mail.ru'], ]; } @@ -77,6 +81,10 @@ class EditableEmailTest extends \PHPUnit_Framework_TestCase [new Email('jane.doe@foo.bar'), 'gmail.com'], [new Email('jane.doe@foo.bar'), 'foo.bar'], [new Email('jane.doe@gmail.com'), 'foo.bar'], + [new Email('jane.doe@yandex.ru'), 'yandex.ru'], + [new Email('jane.doe@mail.ru'), 'mail.ru'], + [new Email('jane.doe@yandex.ru'), 'foo.bar'], + [new Email('jane.doe@mail.ru'), 'foo.bar'], ]; } @@ -101,6 +109,8 @@ class EditableEmailTest extends \PHPUnit_Framework_TestCase [new Email('jane.doe@foo.bar'), 'jane'], [new Email('jane.doe@foo.bar'), 'john'], [new Email('jane.doe@gmail.com'), 'jane.doe'], + [new Email('jane.doe@yandex.ru'), 'jane.doe'], + [new Email('jane.doe@mail.ru'), 'jane.doe'], ]; } diff --git a/tests/Services/MailRUTest.php b/tests/Services/MailRUTest.php new file mode 100644 index 0000000..7025088 --- /dev/null +++ b/tests/Services/MailRUTest.php @@ -0,0 +1,52 @@ +assertEquals($outputEmail, (new MailRU())->getPrimaryEmail(new Email($inputEmail))); + } + + public function providerGetPrimaryEmail() : array + { + return [ + ['foobar@MAIL.RU', 'foobar@mail.ru'], + ['fOObar@MaiL.Ru', 'foobar@mail.ru'], + ['foobar+alias@mail.ru', 'foobar@mail.ru'], + ]; + } + + /** + * @dataProvider providerIsSupported + * + * @param string $domain + * @param bool $result + */ + public function testIsSupported(string $domain, bool $result) + { + $this->assertSame($result, (new MailRU())->isSupported(new Email('Jane.Doe@' . $domain))); + } + + public function providerIsSupported() : array + { + return [ + ['mail.ru', true], + ['mail.RU', true], + ['MAIL.RU', true], + ['ma.il.ru', false], + ]; + } +} \ No newline at end of file diff --git a/tests/Services/YandexRuTest.php b/tests/Services/YandexRuTest.php new file mode 100644 index 0000000..74745f1 --- /dev/null +++ b/tests/Services/YandexRuTest.php @@ -0,0 +1,53 @@ +assertEquals($outputEmail, (new YandexRu())->getPrimaryEmail(new Email($inputEmail))); + } + + public function providerGetPrimaryEmail() : array + { + return [ + ['foobar@YANDEX.RU', 'foobar@yandex.ru'], + ['fOObar@YAndEX.ru', 'foobar@yandex.ru'], + ['foobar+alias@yandex.ru', 'foobar@yandex.ru'], + ['JaneDoe@ya.ru', 'janedoe@yandex.ru'], + ]; + } + + /** + * @dataProvider providerIsSupported + * + * @param string $domain + * @param bool $result + */ + public function testIsSupported(string $domain, bool $result) + { + $this->assertSame($result, (new YandexRu())->isSupported(new Email('Jane.Doe@' . $domain))); + } + + public function providerIsSupported() : array + { + return [ + ['yandex.ru', true], + ['yandex.RU', true], + ['yan.dex.ru', false], + ['YANDEX.RU', true], + ]; + } +} \ No newline at end of file