From 9c9d5ac47e766451f7c3e2a874c2d902764a8aa5 Mon Sep 17 00:00:00 2001 From: gridnev Date: Wed, 19 Feb 2020 11:37:51 +0300 Subject: [PATCH 1/6] Update Dependencies --- .travis.yml | 3 ++- composer.json | 2 +- phpunit.xml.dist | 2 +- tests/Emails/EditableEmailTest.php | 3 ++- tests/Emails/EmailTest.php | 3 ++- tests/ServiceCollectorTest.php | 3 ++- tests/Services/AppsGoogleComTest.php | 3 ++- tests/Services/GmailComTest.php | 3 ++- tests/Services/MultiDomainTest.php | 3 ++- tests/Services/OutlookComTest.php | 3 ++- tests/Services/Www33MailComTest.php | 3 ++- tests/Services/YahooComTest.php | 3 ++- tests/TransparentEmailFactoryTest.php | 3 ++- tests/TransparentEmailTest.php | 3 ++- 14 files changed, 26 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 89fa431..e1ef244 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,8 @@ install: php: - 7.0 - 7.1 - - nightly + - 7.2 + - 7.3 script: - ./vendor/bin/phpunit diff --git a/composer.json b/composer.json index d588f37..b683a16 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "php": "^7.0.0" }, "require-dev": { - "phpunit/phpunit": "^5.5.4", + "phpunit/phpunit": "6.5.14", "satooshi/php-coveralls": "^1.0.1", "codacy/coverage": "^1.0.3" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 8a7d274..3ece69a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,7 +4,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.5/phpunit.xsd" bootstrap="./vendor/autoload.php" - colors="auto" + colors="true" > diff --git a/tests/Emails/EditableEmailTest.php b/tests/Emails/EditableEmailTest.php index cd2f60b..5889861 100644 --- a/tests/Emails/EditableEmailTest.php +++ b/tests/Emails/EditableEmailTest.php @@ -5,8 +5,9 @@ namespace bkrukowski\TransparentEmail\Tests\Emails; use bkrukowski\TransparentEmail\Emails\EditableEmail; use bkrukowski\TransparentEmail\Emails\Email; use bkrukowski\TransparentEmail\Emails\EmailInterface; +use PHPUnit\Framework\TestCase; -class EditableEmailTest extends \PHPUnit_Framework_TestCase +class EditableEmailTest extends TestCase { /** * @dataProvider providerRemoveFromLocalPart diff --git a/tests/Emails/EmailTest.php b/tests/Emails/EmailTest.php index b03b08b..c559de7 100644 --- a/tests/Emails/EmailTest.php +++ b/tests/Emails/EmailTest.php @@ -6,8 +6,9 @@ namespace bkrukowski\TransparentEmail\Tests\Emails; use bkrukowski\TransparentEmail\Emails\Email; use bkrukowski\TransparentEmail\Emails\InvalidEmailException; +use PHPUnit\Framework\TestCase; -class EmailTest extends \PHPUnit_Framework_TestCase +class EmailTest extends TestCase { /** * @dataProvider providerConstructor diff --git a/tests/ServiceCollectorTest.php b/tests/ServiceCollectorTest.php index 38f77f5..88eb430 100644 --- a/tests/ServiceCollectorTest.php +++ b/tests/ServiceCollectorTest.php @@ -6,8 +6,9 @@ namespace bkrukowski\TransparentEmail\Tests; use bkrukowski\TransparentEmail\ServiceCollector; use bkrukowski\TransparentEmail\Services\ServiceInterface; +use PHPUnit\Framework\TestCase; -class ServiceCollectorTest extends \PHPUnit_Framework_TestCase +class ServiceCollectorTest extends TestCase { public function testAddService() { diff --git a/tests/Services/AppsGoogleComTest.php b/tests/Services/AppsGoogleComTest.php index 2ba0f4b..5598ad7 100644 --- a/tests/Services/AppsGoogleComTest.php +++ b/tests/Services/AppsGoogleComTest.php @@ -6,8 +6,9 @@ namespace bkrukowski\TransparentEmail\Tests\Services; use bkrukowski\TransparentEmail\Emails\Email; use bkrukowski\TransparentEmail\Services\AppsGoogleCom; +use PHPUnit\Framework\TestCase; -class AppsGoogleComTest extends \PHPUnit_Framework_TestCase +class AppsGoogleComTest extends TestCase { /** * @dataProvider providerIsSupported diff --git a/tests/Services/GmailComTest.php b/tests/Services/GmailComTest.php index d5a7bad..196b1dc 100644 --- a/tests/Services/GmailComTest.php +++ b/tests/Services/GmailComTest.php @@ -6,8 +6,9 @@ namespace bkrukowski\TransparentEmail\Tests\Services; use bkrukowski\TransparentEmail\Emails\Email; use bkrukowski\TransparentEmail\Services\GmailCom; +use PHPUnit\Framework\TestCase; -class GmailComTest extends \PHPUnit_Framework_TestCase +class GmailComTest extends TestCase { /** * @dataProvider providerGetPrimaryEmail diff --git a/tests/Services/MultiDomainTest.php b/tests/Services/MultiDomainTest.php index 3e6947f..2897b70 100644 --- a/tests/Services/MultiDomainTest.php +++ b/tests/Services/MultiDomainTest.php @@ -6,8 +6,9 @@ namespace bkrukowski\TransparentEmail\Tests\Services; use bkrukowski\TransparentEmail\Emails\Email; use bkrukowski\TransparentEmail\Services\MultiDomain; +use PHPUnit\Framework\TestCase; -class MultiDomainTest extends \PHPUnit_Framework_TestCase +class MultiDomainTest extends TestCase { /** * @dataProvider providerIsSupported diff --git a/tests/Services/OutlookComTest.php b/tests/Services/OutlookComTest.php index c8451f5..d4f715c 100644 --- a/tests/Services/OutlookComTest.php +++ b/tests/Services/OutlookComTest.php @@ -6,8 +6,9 @@ namespace bkrukowski\TransparentEmail\Tests\Services; use bkrukowski\TransparentEmail\Emails\Email; use bkrukowski\TransparentEmail\Services\OutlookCom; +use PHPUnit\Framework\TestCase; -class OutlookComTest extends \PHPUnit_Framework_TestCase +class OutlookComTest extends TestCase { /** * @dataProvider providerIsSupported diff --git a/tests/Services/Www33MailComTest.php b/tests/Services/Www33MailComTest.php index 891bc19..b449c35 100644 --- a/tests/Services/Www33MailComTest.php +++ b/tests/Services/Www33MailComTest.php @@ -6,8 +6,9 @@ namespace bkrukowski\TransparentEmail\Tests\Services; use bkrukowski\TransparentEmail\Emails\Email; use bkrukowski\TransparentEmail\Services\Www33MailCom; +use PHPUnit\Framework\TestCase; -class Www33MailComTest extends \PHPUnit_Framework_TestCase +class Www33MailComTest extends TestCase { /** * @dataProvider providerIsSupported diff --git a/tests/Services/YahooComTest.php b/tests/Services/YahooComTest.php index 2763e5b..872beda 100644 --- a/tests/Services/YahooComTest.php +++ b/tests/Services/YahooComTest.php @@ -6,8 +6,9 @@ namespace bkrukowski\TransparentEmail\Tests\Services; use bkrukowski\TransparentEmail\Emails\Email; use bkrukowski\TransparentEmail\Services\YahooCom; +use PHPUnit\Framework\TestCase; -class YahooComTest extends \PHPUnit_Framework_TestCase +class YahooComTest extends TestCase { /** * @dataProvider providerIsSupported diff --git a/tests/TransparentEmailFactoryTest.php b/tests/TransparentEmailFactoryTest.php index d84b919..26cfe6c 100644 --- a/tests/TransparentEmailFactoryTest.php +++ b/tests/TransparentEmailFactoryTest.php @@ -7,8 +7,9 @@ namespace bkrukowski\TransparentEmail\Tests; use bkrukowski\TransparentEmail\Emails\Email; use bkrukowski\TransparentEmail\Emails\EmailInterface; use bkrukowski\TransparentEmail\TransparentEmailFactory; +use PHPUnit\Framework\TestCase; -class TransparentEmailFactoryTest extends \PHPUnit_Framework_TestCase +class TransparentEmailFactoryTest extends TestCase { /** * @dataProvider providerExpectedEmail diff --git a/tests/TransparentEmailTest.php b/tests/TransparentEmailTest.php index 6cc840f..e12b24b 100644 --- a/tests/TransparentEmailTest.php +++ b/tests/TransparentEmailTest.php @@ -11,8 +11,9 @@ use bkrukowski\TransparentEmail\ServiceCollectorInterface; use bkrukowski\TransparentEmail\Services\TlenPl; use bkrukowski\TransparentEmail\TransparentEmail; use bkrukowski\TransparentEmail\TransparentEmailFactory; +use PHPUnit\Framework\TestCase; -class TransparentEmailTest extends \PHPUnit_Framework_TestCase +class TransparentEmailTest extends TestCase { /** * @dataProvider providerGetPrimaryEmail From c83a423cd853780ecbcf11a7d1edebcb5d34a662 Mon Sep 17 00:00:00 2001 From: gridnev Date: Wed, 19 Feb 2020 12:41:06 +0300 Subject: [PATCH 2/6] Update outlook service domains --- src/Services/OutlookCom.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/OutlookCom.php b/src/Services/OutlookCom.php index 32e6ea2..b4021cf 100644 --- a/src/Services/OutlookCom.php +++ b/src/Services/OutlookCom.php @@ -18,6 +18,6 @@ class OutlookCom implements ServiceInterface public function isSupported(EmailInterface $email) : bool { - return in_array($email->getDomain(), ['outlook.com', 'hotmail.com'], true); + return in_array($email->getDomain(), ['outlook.com', 'hotmail.com', 'live.com', 'msn.com'], true); } } \ No newline at end of file From df33d7edbc7d5367dc30c7e6cd92542aceaa3453 Mon Sep 17 00:00:00 2001 From: gridnev Date: Wed, 19 Feb 2020 12:17:36 +0300 Subject: [PATCH 3/6] Add Mail.ru service support --- src/Services/MailRu.php | 23 ++++++++++++++ src/TransparentEmailFactory.php | 2 ++ tests/Services/MailRuTest.php | 53 +++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 src/Services/MailRu.php create mode 100644 tests/Services/MailRuTest.php diff --git a/src/Services/MailRu.php b/src/Services/MailRu.php new file mode 100644 index 0000000..26950ed --- /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/TransparentEmailFactory.php b/src/TransparentEmailFactory.php index fff5cd7..8e6232c 100644 --- a/src/TransparentEmailFactory.php +++ b/src/TransparentEmailFactory.php @@ -6,6 +6,7 @@ namespace bkrukowski\TransparentEmail; use bkrukowski\TransparentEmail\Services\AppsGoogleCom; use bkrukowski\TransparentEmail\Services\GmailCom; +use bkrukowski\TransparentEmail\Services\MailRu; use bkrukowski\TransparentEmail\Services\OutlookCom; use bkrukowski\TransparentEmail\Services\TlenPl; use bkrukowski\TransparentEmail\Services\Www33MailCom; @@ -38,6 +39,7 @@ class TransparentEmailFactory Www33MailCom::class, TlenPl::class, AppsGoogleCom::class, + MailRu::class ]; } } \ No newline at end of file diff --git a/tests/Services/MailRuTest.php b/tests/Services/MailRuTest.php new file mode 100644 index 0000000..13dd81c --- /dev/null +++ b/tests/Services/MailRuTest.php @@ -0,0 +1,53 @@ +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 From dc658473718ef10e67c65698725924a1dfb86be4 Mon Sep 17 00:00:00 2001 From: gridnev Date: Wed, 19 Feb 2020 12:22:35 +0300 Subject: [PATCH 4/6] Add Yandex.ru service support --- src/Emails/EditableEmail.php | 8 +++++ src/Services/YandexRu.php | 41 +++++++++++++++++++++ src/TransparentEmailFactory.php | 6 ++-- tests/Services/YandexRuTest.php | 63 +++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 src/Services/YandexRu.php create mode 100644 tests/Services/YandexRuTest.php diff --git a/src/Emails/EditableEmail.php b/src/Emails/EditableEmail.php index cb223bd..e013cdd 100644 --- a/src/Emails/EditableEmail.php +++ b/src/Emails/EditableEmail.php @@ -25,6 +25,14 @@ class EditableEmail implements EmailInterface return $copy; } + public function replaceInLocalPart(string $toReplace, string $replacement) : EditableEmail + { + $copy = clone $this; + $copy->localPart = str_replace($toReplace, $replacement, $this->localPart); + + return $copy; + } + public function removeSuffixAlias(string $delimiter) : EditableEmail { $copy = clone $this; diff --git a/src/Services/YandexRu.php b/src/Services/YandexRu.php new file mode 100644 index 0000000..7d36cd7 --- /dev/null +++ b/src/Services/YandexRu.php @@ -0,0 +1,41 @@ +removeSuffixAlias('+') + ->replaceInLocalPart('.', '-') + ->lowerCaseLocalPartIf(true) + ->setDomain($this->mapDomain($email->getDomain())); + } + + public function isSupported(EmailInterface $email) : bool + { + return in_array($email->getDomain(), ['ya.ru', 'yandex.com', 'yandex.ru', 'yandex.by', 'yandex.kz', 'yandex.ua']); + } + + protected function getDomainMapping() : array + { + return [ + 'ya.ru' => 'yandex.ru', + 'yandex.com' => 'yandex.ru', + 'yandex.by' => 'yandex.ru', + 'yandex.kz' => 'yandex.ru', + 'yandex.ua' => 'yandex.ru' + ]; + } + + private function mapDomain(string $domain) : string + { + return $this->getDomainMapping()[$domain] ?? $domain; + } +} \ No newline at end of file diff --git a/src/TransparentEmailFactory.php b/src/TransparentEmailFactory.php index 8e6232c..34e68f5 100644 --- a/src/TransparentEmailFactory.php +++ b/src/TransparentEmailFactory.php @@ -11,6 +11,7 @@ use bkrukowski\TransparentEmail\Services\OutlookCom; use bkrukowski\TransparentEmail\Services\TlenPl; use bkrukowski\TransparentEmail\Services\Www33MailCom; use bkrukowski\TransparentEmail\Services\YahooCom; +use bkrukowski\TransparentEmail\Services\YandexRu; class TransparentEmailFactory { @@ -39,7 +40,8 @@ class TransparentEmailFactory Www33MailCom::class, TlenPl::class, AppsGoogleCom::class, - MailRu::class + MailRu::class, + YandexRu::class ]; } -} \ No newline at end of file +} diff --git a/tests/Services/YandexRuTest.php b/tests/Services/YandexRuTest.php new file mode 100644 index 0000000..797f7fd --- /dev/null +++ b/tests/Services/YandexRuTest.php @@ -0,0 +1,63 @@ +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'], + ['Jane.Doe@ya.ru', 'jane-doe@yandex.ru'], + ['foobar@yandex.com', 'foobar@yandex.ru'], + ['foobar@yandex.by', 'foobar@yandex.ru'], + ['foobar@yandex.kz', 'foobar@yandex.ru'], + ['foobar@yandex.ua', 'foobar@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.com', true], + ['yandex.by', true], + ['yandex.kz', true], + ['yandex.ua', true], + ['yandex.RU', true], + ['yan.dex.ru', false], + ['YANDEX.RU', true], + ]; + } +} \ No newline at end of file From 2e4cd9ff470fb7b2d4aaa4020ec5139c68f88da1 Mon Sep 17 00:00:00 2001 From: gridnev Date: Wed, 19 Feb 2020 12:34:15 +0300 Subject: [PATCH 5/6] Add Icloud.com service support --- src/Services/IcloudCom.php | 21 ++++++++++++++ src/TransparentEmailFactory.php | 4 ++- tests/Services/IcloudComTest.php | 49 ++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/Services/IcloudCom.php create mode 100644 tests/Services/IcloudComTest.php diff --git a/src/Services/IcloudCom.php b/src/Services/IcloudCom.php new file mode 100644 index 0000000..55f575d --- /dev/null +++ b/src/Services/IcloudCom.php @@ -0,0 +1,21 @@ +removeSuffixAlias('+') + ->lowerCaseLocalPartIf(true); + } + + public function isSupported(EmailInterface $email) : bool + { + return in_array($email->getDomain(), ['icloud.com']); + } +} \ No newline at end of file diff --git a/src/TransparentEmailFactory.php b/src/TransparentEmailFactory.php index 34e68f5..24c9930 100644 --- a/src/TransparentEmailFactory.php +++ b/src/TransparentEmailFactory.php @@ -7,6 +7,7 @@ namespace bkrukowski\TransparentEmail; use bkrukowski\TransparentEmail\Services\AppsGoogleCom; use bkrukowski\TransparentEmail\Services\GmailCom; use bkrukowski\TransparentEmail\Services\MailRu; +use bkrukowski\TransparentEmail\Services\IcloudCom; use bkrukowski\TransparentEmail\Services\OutlookCom; use bkrukowski\TransparentEmail\Services\TlenPl; use bkrukowski\TransparentEmail\Services\Www33MailCom; @@ -41,7 +42,8 @@ class TransparentEmailFactory TlenPl::class, AppsGoogleCom::class, MailRu::class, - YandexRu::class + YandexRu::class, + IcloudCom::class ]; } } diff --git a/tests/Services/IcloudComTest.php b/tests/Services/IcloudComTest.php new file mode 100644 index 0000000..f89ebde --- /dev/null +++ b/tests/Services/IcloudComTest.php @@ -0,0 +1,49 @@ +assertEquals($outputEmail, (new IcloudCom())->getPrimaryEmail(new Email($inputEmail))); + } + + public function providerGetPrimaryEmail() : array + { + return [ + ['foobar@ICLOUD.COM', 'foobar@icloud.com'], + ['foobar+alias@icloud.com', 'foobar@icloud.com'], + ]; + } + + /** + * @dataProvider providerIsSupported + * + * @param string $domain + * @param bool $result + */ + public function testIsSupported(string $domain, bool $result) + { + $this->assertSame($result, (new IcloudCom())->isSupported(new Email('Jane.Doe@' . $domain))); + } + + public function providerIsSupported() : array + { + return [ + ['icloud.com', true], + ['ICLOUD.COM', true], + ['i.cloud.com', false], + ]; + } +} \ No newline at end of file From e1c198a57123b341cc79cd4b36e4b6f625d57986 Mon Sep 17 00:00:00 2001 From: gridnev Date: Wed, 19 Feb 2020 12:09:32 +0300 Subject: [PATCH 6/6] Update Readme file --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 700b80a..5c684ed 100644 --- a/README.md +++ b/README.md @@ -55,4 +55,17 @@ Yahoo uses the following pattern[*](https://help.yahoo.com/kb/SLN16026.html): * *keyword* - one from a list of keywords defined by the user. Therefore we do not know what is the real email, so in this case result will be `baseName@yahoo.com`, -which actually does not exist. \ No newline at end of file +which actually does not exist. + +## Yandex.ru +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 +Mail.ru service uses following aliases: +* `janedoe+alias@mail.ru` will be redirected to `janedoe@mail.ru` +* `janeDoe@MAIL.RU` will be redirected to `janedoe@mail.ru` + +## Icloud.com +Icloud.com service uses following aliases: +* `janedoe+alias@icloud.com` will be redirected to `janedoe@icloud.com` +* `janeDoe@ICLOUD.COM` will be redirected to `janedoe@icloud.com` \ No newline at end of file