Skip to content

Commit

Permalink
Merge pull request #7 from elbgoods/ft-add-disposable-email-detector
Browse files Browse the repository at this point in the history
add disposable email detector
  • Loading branch information
Gummibeer authored Feb 18, 2020
2 parents 2b0f999 + c3aac6c commit 278d496
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions config/trashmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],

Expand All @@ -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.
*/
Expand Down
33 changes: 33 additions & 0 deletions src/Providers/DisposableEmailDetectorProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Elbgoods\TrashmailRule\Providers;

use Elbgoods\TrashmailRule\Contracts\ProviderContract;

class DisposableEmailDetectorProvider implements ProviderContract
{
protected const BASE_URL = 'https://api.disposable-email-detector.com/api/dea/v1/check/';

protected array $config;

public function __construct(array $config)
{
$this->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;
}
}
8 changes: 8 additions & 0 deletions src/TrashmailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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'),
]);
}
}

0 comments on commit 278d496

Please sign in to comment.