Support for apps.google.com

This commit is contained in:
bkrukowski 2016-09-16 01:13:48 +02:00
parent 457a2da2f3
commit 94119d07e3
5 changed files with 63 additions and 2 deletions

View File

@ -0,0 +1,23 @@
<?php
namespace bkrukowski\TransparentEmail\Services;
/**
* @internal
*/
class AppsGoogleCom extends GmailCom
{
public function isDomainSupported(string $domain) : bool
{
getmxrr($domain, $mxhosts);
$regex1 = '#\\.googlemail\\.com$#';
$regex2 = '#\\.google\\.com$#';
foreach ($mxhosts as $host) {
if (preg_match($regex1, $host) || preg_match($regex2, $host)) {
return true;
}
}
return false;
}
}

View File

@ -11,11 +11,19 @@ class GmailCom implements ServiceInterface
{ {
list($name, $domain) = explode('@', strtolower($email)); list($name, $domain) = explode('@', strtolower($email));
return explode('+', str_replace('.', '', $name))[0] . '@' . $domain; return explode('+', str_replace('.', '', $name))[0] . '@' . $this->mapDomain($domain);
} }
public function isDomainSupported(string $domain) : bool public function isDomainSupported(string $domain) : bool
{ {
return in_array(strtolower($domain), ['gmail.com', 'googlemail.com']); return in_array(strtolower($domain), ['gmail.com', 'googlemail.com']);
} }
private function mapDomain(string $domain) : string
{
$mapping = [
'googlemail.com' => 'gmail.com',
];
return $mapping[$domain] ?? $domain;
}
} }

View File

@ -2,6 +2,7 @@
namespace bkrukowski\TransparentEmail; namespace bkrukowski\TransparentEmail;
use bkrukowski\TransparentEmail\Services\AppsGoogleCom;
use bkrukowski\TransparentEmail\Services\GmailCom; use bkrukowski\TransparentEmail\Services\GmailCom;
use bkrukowski\TransparentEmail\Services\OutlookCom; use bkrukowski\TransparentEmail\Services\OutlookCom;
use bkrukowski\TransparentEmail\Services\ServiceInterface; use bkrukowski\TransparentEmail\Services\ServiceInterface;
@ -16,6 +17,7 @@ class TransparentEmail
const SERVICE_WWW_33MAIL_COM = Www33MailCom::class; const SERVICE_WWW_33MAIL_COM = Www33MailCom::class;
const SERVICE_OUTLOOK_COM = OutlookCom::class; const SERVICE_OUTLOOK_COM = OutlookCom::class;
const SERVICE_YAHOO_COM = YahooCom::class; const SERVICE_YAHOO_COM = YahooCom::class;
const SERVICE_APPS_GOOGLE_COM = AppsGoogleCom::class;
/** /**
* Constant ALL_SERVICES can contain different values depends on API version * Constant ALL_SERVICES can contain different values depends on API version
@ -26,6 +28,7 @@ class TransparentEmail
self::SERVICE_WWW_33MAIL_COM, self::SERVICE_WWW_33MAIL_COM,
self::SERVICE_OUTLOOK_COM, self::SERVICE_OUTLOOK_COM,
self::SERVICE_YAHOO_COM, self::SERVICE_YAHOO_COM,
self::SERVICE_APPS_GOOGLE_COM,
]; ];
private $services; private $services;

View File

@ -0,0 +1,27 @@
<?php
namespace bkrukowski\TransparentEmail\Tests\Services;
use bkrukowski\TransparentEmail\Services\AppsGoogleCom;
class AppsGoogleComTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider providerIsDomainSupported
*
* @param string $domain
* @param bool $result
*/
public function testIsDomainSupported(string $domain, bool $result)
{
$this->assertSame($result, (new AppsGoogleCom())->isDomainSupported($domain));
}
public function providerIsDomainSupported()
{
return [
['example.com', false],
['krukowski.me', true],
];
}
}

View File

@ -24,7 +24,7 @@ class GmailComTest extends \PHPUnit_Framework_TestCase
['Foo.Bar@GMAIL.COM', 'foobar@gmail.com'], ['Foo.Bar@GMAIL.COM', 'foobar@gmail.com'],
['foobar+alias@gmail.com', 'foobar@gmail.com'], ['foobar+alias@gmail.com', 'foobar@gmail.com'],
['fo.ob.ar+alias@gmail.com', 'foobar@gmail.com'], ['fo.ob.ar+alias@gmail.com', 'foobar@gmail.com'],
['JaneDoe@googlemail.com', 'janedoe@googlemail.com'], ['JaneDoe@googlemail.com', 'janedoe@gmail.com'],
]; ];
} }