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 diff --git a/config/trashmail.php b/config/trashmail.php index 70f7a0e..5dd4704 100644 --- a/config/trashmail.php +++ b/config/trashmail.php @@ -3,8 +3,13 @@ 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', + 'disposable_email_detector', 'dead_letter', ], @@ -24,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..2232350 --- /dev/null +++ b/src/Providers/DisposableEmailDetectorProvider.php @@ -0,0 +1,33 @@ +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'), + ]); + } }