Skip to content

Commit

Permalink
Merge pull request #8 from elbgoods/ft-verifier-provider
Browse files Browse the repository at this point in the history
add verifier provider
  • Loading branch information
Gummibeer authored Feb 18, 2020
2 parents 278d496 + b77df5e commit 1e9afea
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 3 deletions.
6 changes: 5 additions & 1 deletion 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.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`
Expand All @@ -17,4 +21,4 @@ All notable changes to this package will be documented in this file.

## v0.1.0

* initial release
* initial release
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions config/trashmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
'providers' => [
'config',
'disposable_email_detector',
'verifier',
'dead_letter',
],

/*
* This package can load a remote blacklist from https://www.dead-letter.email
*/
'dead_letter' => [
'enabled' => true,
'enabled' => false,
'cache' => [
'enabled' => true,
'store' => null,
Expand All @@ -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,
],
Expand Down
41 changes: 41 additions & 0 deletions src/Providers/VerifierProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Elbgoods\TrashmailRule\Providers;

use Elbgoods\TrashmailRule\Contracts\ProviderContract;

class VerifierProvider implements ProviderContract
{
protected const BASE_URL = 'https://verifier.meetchopra.com/verify/';

protected array $config;

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

Expand Down Expand Up @@ -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'),
]);
}
}
5 changes: 5 additions & 0 deletions tests/Rules/TrashmailRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '[email protected]'));
Expand All @@ -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();
Expand Down

0 comments on commit 1e9afea

Please sign in to comment.