mirror of
https://github.com/retailcrm/transparent-email.git
synced 2024-11-21 21:06:04 +03:00
Support for apps.google.com
This commit is contained in:
parent
457a2da2f3
commit
94119d07e3
23
src/Services/AppsGoogleCom.php
Normal file
23
src/Services/AppsGoogleCom.php
Normal 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;
|
||||
}
|
||||
}
|
@ -11,11 +11,19 @@ class GmailCom implements ServiceInterface
|
||||
{
|
||||
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
|
||||
{
|
||||
return in_array(strtolower($domain), ['gmail.com', 'googlemail.com']);
|
||||
}
|
||||
|
||||
private function mapDomain(string $domain) : string
|
||||
{
|
||||
$mapping = [
|
||||
'googlemail.com' => 'gmail.com',
|
||||
];
|
||||
return $mapping[$domain] ?? $domain;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace bkrukowski\TransparentEmail;
|
||||
|
||||
use bkrukowski\TransparentEmail\Services\AppsGoogleCom;
|
||||
use bkrukowski\TransparentEmail\Services\GmailCom;
|
||||
use bkrukowski\TransparentEmail\Services\OutlookCom;
|
||||
use bkrukowski\TransparentEmail\Services\ServiceInterface;
|
||||
@ -16,6 +17,7 @@ class TransparentEmail
|
||||
const SERVICE_WWW_33MAIL_COM = Www33MailCom::class;
|
||||
const SERVICE_OUTLOOK_COM = OutlookCom::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
|
||||
@ -26,6 +28,7 @@ class TransparentEmail
|
||||
self::SERVICE_WWW_33MAIL_COM,
|
||||
self::SERVICE_OUTLOOK_COM,
|
||||
self::SERVICE_YAHOO_COM,
|
||||
self::SERVICE_APPS_GOOGLE_COM,
|
||||
];
|
||||
|
||||
private $services;
|
||||
|
27
tests/Services/AppsGoogleComTest.php
Normal file
27
tests/Services/AppsGoogleComTest.php
Normal 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],
|
||||
];
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ class GmailComTest extends \PHPUnit_Framework_TestCase
|
||||
['Foo.Bar@GMAIL.COM', 'foobar@gmail.com'],
|
||||
['foobar+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'],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user