From a8c63317cf7fafabfbe5c5aab4d31119624babb1 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 18 Feb 2020 12:31:34 +0100 Subject: [PATCH 1/3] add verifier provider disable all api providers by default --- README.md | 7 +++++ config/trashmail.php | 16 ++++++++++-- src/Providers/VerifierProvider.php | 41 ++++++++++++++++++++++++++++++ src/TrashmailManager.php | 8 ++++++ 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/Providers/VerifierProvider.php diff --git a/README.md b/README.md index 87389e1..1147593 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,13 @@ You can add your own blacklist, these domains will always be blocked - independe If you want to pass some domains always you can add them to the whitelist. These domains will always pass, even if they are listed in the blacklist. +# supported Providers + +* local configuration - `\Elbgoods\TrashmailRule\Providers\ConfigProvider` +* https://dead-letter.email - `\Elbgoods\TrashmailRule\Providers\DeadLetterProvider` +* https://disposable-email-detector.com - `\Elbgoods\TrashmailRule\Providers\DisposableEmailDetectorProvider` +* https://verifier.meetchopra.com - `\Elbgoods\TrashmailRule\Providers\VerifierProvider` + ## Usage ## Validation Rule diff --git a/config/trashmail.php b/config/trashmail.php index 5dd4704..8d0a8ae 100644 --- a/config/trashmail.php +++ b/config/trashmail.php @@ -10,6 +10,7 @@ 'providers' => [ 'config', 'disposable_email_detector', + 'verifier', 'dead_letter', ], @@ -17,7 +18,7 @@ * This package can load a remote blacklist from https://www.dead-letter.email */ 'dead_letter' => [ - 'enabled' => true, + 'enabled' => false, 'cache' => [ 'enabled' => true, 'store' => null, @@ -33,7 +34,18 @@ * This package can do a request to https://www.disposable-email-detector.com */ 'disposable_email_detector' => [ - 'enabled' => true, + 'enabled' => false, + 'guzzle' => [ + RequestOptions::TIMEOUT => 5, + ], + ], + + /* + * This package can do a request to https://verifier.meetchopra.com + */ + 'verifier' => [ + 'enabled' => false, + 'api_key' => null, 'guzzle' => [ RequestOptions::TIMEOUT => 5, ], diff --git a/src/Providers/VerifierProvider.php b/src/Providers/VerifierProvider.php new file mode 100644 index 0000000..341505f --- /dev/null +++ b/src/Providers/VerifierProvider.php @@ -0,0 +1,41 @@ +config = $config; + } + + public function isDisposable(string $domain): ?bool + { + if (! $this->config['enabled']) { + return null; + } + + if (empty($this->config['api_key'])) { + return null; + } + + $response = guzzle( + self::BASE_URL, + $this->config['guzzle'] + )->request('GET', $domain, [ + 'query' => [ + 'token' => $this->config['api_key'], + ], + ]); + + $body = $response->getBody()->getContents(); + + return (! json_decode($body, true)['status']) ?? null; + } +} diff --git a/src/TrashmailManager.php b/src/TrashmailManager.php index f9b4851..ad6f731 100644 --- a/src/TrashmailManager.php +++ b/src/TrashmailManager.php @@ -6,6 +6,7 @@ use Elbgoods\TrashmailRule\Providers\ConfigProvider; use Elbgoods\TrashmailRule\Providers\DeadLetterProvider; use Elbgoods\TrashmailRule\Providers\DisposableEmailDetectorProvider; +use Elbgoods\TrashmailRule\Providers\VerifierProvider; use Illuminate\Support\Manager; use RuntimeException; @@ -56,4 +57,11 @@ protected function createDisposableEmailDetectorDriver(): DisposableEmailDetecto 'config' => $this->config->get('trashmail.disposable_email_detector'), ]); } + + protected function createVerifierDriver(): VerifierProvider + { + return $this->container->make(VerifierProvider::class, [ + 'config' => $this->config->get('trashmail.verifier'), + ]); + } } From 3cfe5ba06bb138a7631c4ef6b0de19e1ba6ccb25 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 18 Feb 2020 12:33:27 +0100 Subject: [PATCH 2/3] v0.4.0 --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 346d03a..85335d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this package will be documented in this file. +## v0.4.0 + +* add https://verifier.meetchopra.com provider `\Elbgoods\TrashmailRule\Providers\VerifierProvider` + ## v0.3.0 * add https://disposable-email-detector.com provider `\Elbgoods\TrashmailRule\Providers\DisposableEmailDetectorProvider` @@ -17,4 +21,4 @@ All notable changes to this package will be documented in this file. ## v0.1.0 -* initial release \ No newline at end of file +* initial release From b77df5e4e2cfff984b351cbaf0d36bc019c8d642 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 18 Feb 2020 12:36:33 +0100 Subject: [PATCH 3/3] fix phpunit --- tests/Rules/TrashmailRuleTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/Rules/TrashmailRuleTest.php b/tests/Rules/TrashmailRuleTest.php index 3c0f8fb..b6c3fe2 100644 --- a/tests/Rules/TrashmailRuleTest.php +++ b/tests/Rules/TrashmailRuleTest.php @@ -11,6 +11,9 @@ final class TrashmailRuleTest extends TestCase /** @test */ public function it_validates_the_email_domain(): void { + $this->app['config']->set('trashmail.disposable_email_detector.enabled', true); + $this->app['config']->set('trashmail.dead_letter.enabled', true); + $rule = new TrashmailRule(); $this->assertFalse($rule->passes('email', 'example@fakeinbox.com')); @@ -23,6 +26,8 @@ public function it_validates_the_email_domain(): void */ public function it_fails_known_trashmail_providers(string $domain): void { + $this->app['config']->set('trashmail.disposable_email_detector.enabled', true); + $this->app['config']->set('trashmail.dead_letter.enabled', true); $this->app['config']->set('trashmail.blacklist', $this->trashMailDomains()); $rule = new TrashmailRule();