diff --git a/README.md b/README.md index d376251..937d409 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,11 @@ which actually does not exist. In official [documentation](https://yandex.com/support/mail/web/preferences/about-sender/additional-addresses.html) you can find some use-cases about aliases usage. ## Mail.ru -There's no official documentation about aliases here, but you can create them with 2 ways: +There's no official documentation about aliases here, but you can create them with these ways: * `janedoe+alias@mail.ru` will be redirected to `janedoe@mail.ru` -* `janeDoe@MAIL.RU` will be redirected to `janedoe@mail.ru` \ No newline at end of file +* `janeDoe@MAIL.RU` will be redirected to `janedoe@mail.ru` + +Also, it's possible to create aliases in the settings of Mail.ru, for example, like these ones: +* `janeDoe@list.ru` will be redirected to `janedoe@mail.ru` +* `janeDoe@inbox.ru` will be redirected to `janedoe@mail.ru` +* `janeDoe@bk.ru` will be redirected to `janedoe@mail.ru` diff --git a/composer.json b/composer.json index d6c11af..b683a16 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "gridnevalex/transparent-email", + "name": "bkrukowski/transparent-email", "description": "Remove aliases from email and get primary email account", "type": "library", "require": { diff --git a/src/Services/MailRU.php b/src/Services/MailRU.php deleted file mode 100644 index 8cdf217..0000000 --- a/src/Services/MailRU.php +++ /dev/null @@ -1,23 +0,0 @@ -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/MailRu.php b/src/Services/MailRu.php new file mode 100644 index 0000000..5d9233e --- /dev/null +++ b/src/Services/MailRu.php @@ -0,0 +1,38 @@ +removeSuffixAlias('+') + ->lowerCaseLocalPartIf(true) + ->setDomain($this->mapDomain($email->getDomain())); + } + + public function isSupported(EmailInterface $email) : bool + { + return in_array($email->getDomain(), ['mail.ru', 'list.ru', 'inbox.ru', 'bk.ru']); + } + + protected function getDomainMapping() : array + { + return [ + 'list.ru' => 'mail.ru', + 'inbox.ru' => 'mail.ru', + 'bk.ru' => 'mail.ru', + ]; + } + + private function mapDomain(string $domain) : string + { + return $this->getDomainMapping()[$domain] ?? $domain; + } +} \ No newline at end of file diff --git a/src/Services/YandexRu.php b/src/Services/YandexRu.php index b883cab..e2d4dce 100644 --- a/src/Services/YandexRu.php +++ b/src/Services/YandexRu.php @@ -20,13 +20,14 @@ class YandexRu implements ServiceInterface public function isSupported(EmailInterface $email) : bool { - return in_array($email->getDomain(), ['ya.ru', 'yandex.ru']); + return in_array($email->getDomain(), ['ya.ru', 'yandex.com', 'yandex.ru']); } protected function getDomainMapping() : array { return [ 'ya.ru' => 'yandex.ru', + 'yandex.com' => 'yandex.ru' ]; } diff --git a/src/TransparentEmailFactory.php b/src/TransparentEmailFactory.php index dbf5de3..932455a 100644 --- a/src/TransparentEmailFactory.php +++ b/src/TransparentEmailFactory.php @@ -6,7 +6,7 @@ namespace bkrukowski\TransparentEmail; use bkrukowski\TransparentEmail\Services\AppsGoogleCom; use bkrukowski\TransparentEmail\Services\GmailCom; -use bkrukowski\TransparentEmail\Services\MailRU; +use bkrukowski\TransparentEmail\Services\MailRu; use bkrukowski\TransparentEmail\Services\OutlookCom; use bkrukowski\TransparentEmail\Services\TlenPl; use bkrukowski\TransparentEmail\Services\Www33MailCom; @@ -41,7 +41,7 @@ class TransparentEmailFactory TlenPl::class, AppsGoogleCom::class, YandexRu::class, - MailRU::class, + MailRu::class, ]; } } \ No newline at end of file diff --git a/tests/Services/MailRUTest.php b/tests/Services/MailRuTest.php similarity index 71% rename from tests/Services/MailRUTest.php rename to tests/Services/MailRuTest.php index fd7eee9..fb7252a 100644 --- a/tests/Services/MailRUTest.php +++ b/tests/Services/MailRuTest.php @@ -5,10 +5,10 @@ declare(strict_types=1); namespace bkrukowski\TransparentEmail\Tests\Services; use bkrukowski\TransparentEmail\Emails\Email; -use bkrukowski\TransparentEmail\Services\MailRU; +use bkrukowski\TransparentEmail\Services\MailRu; use PHPUnit\Framework\TestCase; -class MailRUTest extends TestCase +class MailRuTest extends TestCase { /** * @dataProvider providerGetPrimaryEmail @@ -18,7 +18,7 @@ class MailRUTest extends TestCase */ public function testGetPrimaryEmail(string $inputEmail, string $outputEmail) { - $this->assertEquals($outputEmail, (new MailRU())->getPrimaryEmail(new Email($inputEmail))); + $this->assertEquals($outputEmail, (new MailRu())->getPrimaryEmail(new Email($inputEmail))); } public function providerGetPrimaryEmail() : array @@ -27,6 +27,9 @@ class MailRUTest extends TestCase ['foobar@MAIL.RU', 'foobar@mail.ru'], ['fOObar@MaiL.Ru', 'foobar@mail.ru'], ['foobar+alias@mail.ru', 'foobar@mail.ru'], + ['foobar@list.ru', 'foobar@mail.ru'], + ['foobar@inbox.ru', 'foobar@mail.ru'], + ['foobar@bk.ru', 'foobar@mail.ru'], ]; } @@ -38,13 +41,16 @@ class MailRUTest extends TestCase */ public function testIsSupported(string $domain, bool $result) { - $this->assertSame($result, (new MailRU())->isSupported(new Email('Jane.Doe@' . $domain))); + $this->assertSame($result, (new MailRu())->isSupported(new Email('Jane.Doe@' . $domain))); } public function providerIsSupported() : array { return [ ['mail.ru', true], + ['list.ru', true], + ['inbox.ru', true], + ['bk.ru', true], ['mail.RU', true], ['MAIL.RU', true], ['ma.il.ru', false], diff --git a/tests/Services/YandexRuTest.php b/tests/Services/YandexRuTest.php index 1dadce0..9d74e34 100644 --- a/tests/Services/YandexRuTest.php +++ b/tests/Services/YandexRuTest.php @@ -29,6 +29,7 @@ class YandexRuTest extends TestCase ['foobar+alias@yandex.ru', 'foobar@yandex.ru'], ['JaneDoe@ya.ru', 'janedoe@yandex.ru'], ['Jane.Doe@ya.ru', 'jane-doe@yandex.ru'], + ['foobar@yandex.com', 'foobar@yandex.ru'], ]; } @@ -47,6 +48,7 @@ class YandexRuTest extends TestCase { return [ ['yandex.ru', true], + ['yandex.com', true], ['yandex.RU', true], ['yan.dex.ru', false], ['YANDEX.RU', true],