From d8246a9f2dd42e4b7a3c480b53a9b5d7ec540504 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 18 Feb 2020 12:17:22 +0100 Subject: [PATCH 1/4] add providers config comment --- config/trashmail.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/trashmail.php b/config/trashmail.php index 70f7a0e..9974abc 100644 --- a/config/trashmail.php +++ b/config/trashmail.php @@ -3,6 +3,10 @@ use GuzzleHttp\RequestOptions; return [ + /* + * The list of providers that should run to decide whether an email is disposable or not. + * The order of providers is respected - so you should put the fastest or most important ones at the top. + */ 'providers' => [ 'config', 'dead_letter', From 280e2e9b0fe86f97adec9931580948afbad5113e Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 18 Feb 2020 12:17:37 +0100 Subject: [PATCH 2/4] add disposable_email_detector --- config/trashmail.php | 11 ++++++ .../DisposableEmailDetectorProvider.php | 35 +++++++++++++++++++ src/TrashmailManager.php | 8 +++++ 3 files changed, 54 insertions(+) create mode 100644 src/Providers/DisposableEmailDetectorProvider.php diff --git a/config/trashmail.php b/config/trashmail.php index 9974abc..5dd4704 100644 --- a/config/trashmail.php +++ b/config/trashmail.php @@ -9,6 +9,7 @@ */ 'providers' => [ 'config', + 'disposable_email_detector', 'dead_letter', ], @@ -28,6 +29,16 @@ ], ], + /* + * This package can do a request to https://www.disposable-email-detector.com + */ + 'disposable_email_detector' => [ + 'enabled' => true, + 'guzzle' => [ + RequestOptions::TIMEOUT => 5, + ], + ], + /* * Here you can define your own blacklisted domains. */ diff --git a/src/Providers/DisposableEmailDetectorProvider.php b/src/Providers/DisposableEmailDetectorProvider.php new file mode 100644 index 0000000..3fb3d0c --- /dev/null +++ b/src/Providers/DisposableEmailDetectorProvider.php @@ -0,0 +1,35 @@ +config = $config; + } + + public function isDisposable(string $domain): ?bool + { + if (! $this->config['enabled']) { + return null; + } + + $response = guzzle( + self::BASE_URL, + $this->config['guzzle'] + )->request('GET', $domain); + + $body = $response->getBody()->getContents(); + + return json_decode($body, true)['result']['isDisposable'] ?? null; + } +} diff --git a/src/TrashmailManager.php b/src/TrashmailManager.php index 7bd74fa..f9b4851 100644 --- a/src/TrashmailManager.php +++ b/src/TrashmailManager.php @@ -5,6 +5,7 @@ use Elbgoods\TrashmailRule\Contracts\ProviderContract; use Elbgoods\TrashmailRule\Providers\ConfigProvider; use Elbgoods\TrashmailRule\Providers\DeadLetterProvider; +use Elbgoods\TrashmailRule\Providers\DisposableEmailDetectorProvider; use Illuminate\Support\Manager; use RuntimeException; @@ -48,4 +49,11 @@ protected function createDeadLetterDriver(): DeadLetterProvider 'config' => $this->config->get('trashmail.dead_letter'), ]); } + + protected function createDisposableEmailDetectorDriver(): DisposableEmailDetectorProvider + { + return $this->container->make(DisposableEmailDetectorProvider::class, [ + 'config' => $this->config->get('trashmail.disposable_email_detector'), + ]); + } } From 543693553b27c0b911eabeeb4a58ce44976af035 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 18 Feb 2020 12:17:57 +0100 Subject: [PATCH 3/4] fix php cs --- src/Providers/DisposableEmailDetectorProvider.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Providers/DisposableEmailDetectorProvider.php b/src/Providers/DisposableEmailDetectorProvider.php index 3fb3d0c..2232350 100644 --- a/src/Providers/DisposableEmailDetectorProvider.php +++ b/src/Providers/DisposableEmailDetectorProvider.php @@ -3,8 +3,6 @@ namespace Elbgoods\TrashmailRule\Providers; use Elbgoods\TrashmailRule\Contracts\ProviderContract; -use Illuminate\Contracts\Cache\Factory as CacheFactory; -use Illuminate\Contracts\Cache\Repository as CacheRepository; class DisposableEmailDetectorProvider implements ProviderContract { From c3aac6cd4bb94fb8d0964c5093357da761fe1459 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 18 Feb 2020 12:22:06 +0100 Subject: [PATCH 4/4] v0.3.0 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa73feb..346d03a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this package will be documented in this file. +## v0.3.0 + +* add https://disposable-email-detector.com provider `\Elbgoods\TrashmailRule\Providers\DisposableEmailDetectorProvider` + ## v0.2.0 * switch to manager driver pattern