Add new aliases for yandex and mail systems

This commit is contained in:
gridnev 2020-02-17 17:00:23 +03:00
parent 52c7aabca1
commit b7a9a721ea
8 changed files with 62 additions and 33 deletions

View File

@ -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`
* `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`

View File

@ -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": {

View File

@ -1,23 +0,0 @@
<?php
declare(strict_types=1);
namespace bkrukowski\TransparentEmail\Services;
use bkrukowski\TransparentEmail\Emails\EditableEmail;
use bkrukowski\TransparentEmail\Emails\EmailInterface;
class MailRU implements ServiceInterface
{
public function getPrimaryEmail(EmailInterface $email) : EmailInterface
{
return (new EditableEmail($email))
->removeSuffixAlias('+')
->lowerCaseLocalPartIf(true);
}
public function isSupported(EmailInterface $email) : bool
{
return in_array($email->getDomain(), ['mail.ru']);
}
}

38
src/Services/MailRu.php Normal file
View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace bkrukowski\TransparentEmail\Services;
use bkrukowski\TransparentEmail\Emails\EditableEmail;
use bkrukowski\TransparentEmail\Emails\EmailInterface;
class MailRu implements ServiceInterface
{
public function getPrimaryEmail(EmailInterface $email) : EmailInterface
{
return (new EditableEmail($email))
->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;
}
}

View File

@ -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'
];
}

View File

@ -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,
];
}
}

View File

@ -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],

View File

@ -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],