From c7c81d1fdffc238af6fe2cf6fb2c897b6c3dbbfa Mon Sep 17 00:00:00 2001 From: Aman Nurani Date: Wed, 25 Sep 2019 19:03:26 +0530 Subject: [PATCH] Add disposable email list support --- CHANGELOG.md | 21 ++++--- README.md | 29 +++++---- composer.json | 18 +++++- src/EmailChecker.php | 12 +++- src/Helpers/Helper.php | 119 +++++++++++++++++++++++++++++++++++++ tests/EmailCheckerTest.php | 4 +- 6 files changed, 179 insertions(+), 24 deletions(-) create mode 100644 src/Helpers/Helper.php diff --git a/CHANGELOG.md b/CHANGELOG.md index f60708c..3f1dfce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,20 @@ # CHANGELOG -## 1.0.0 -- Initial release -- Added test cases. -- Update EmailChecker to handle domain validations. -- Added docs. +## 2.0.0 +- Helper added to enhance checking of dispossable emails. +- Added deep check option in checkDisposableEmail() method. +- Large dispossable email list has been added to gist and it is directly used with package. + +## 1.2.0 +- Added license inside composer.json +- Facade updated composer.json ## 1.1.0 - Added License.md - Added Security.md -## 1.2.0 -- Added license inside composer.json -- Facade updated composer.json +## 1.0.0 +- Initial release +- Added test cases. +- Update EmailChecker to handle domain validations. +- Added docs. diff --git a/README.md b/README.md index 483e946..19d5de0 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Nowadays most of websites are using registration process where they need to veri ## Installation -Laravel Exceptions requires [PHP](https://php.net) > 7.0. This particular version supports with latest [Laravel](https://laravel.com/). +Email Checker requires [PHP](https://php.net) > 7.0. This particular version supports with latest [Laravel](https://laravel.com/). To get the latest version, simply require the project using [Composer](https://getcomposer.org): @@ -21,17 +21,23 @@ Once installed, You need to include `Aman\EmailVerifier\EmailChecker` to access ## Usage -#### Check Disposable Emails +### Check Disposable Emails If you want to check email is [disposable emails](https://en.wikipedia.org/wiki/Disposable_email_address) or not then you can use the following function of [emailchecker](https://github.com/aman00323/email-verifier/) +***Added new option to check disposable emails*** + +This option is part of checkDisposableEmail() method, you need to pass second argument as true. + +When you pass true inside helper will check emails with list of dispossable. which are hosted on gist, So whenever list will be changed you would't have to update package. + ``` -app(EmailChecker::class)->checkDisposableEmail('something@example.com')); +app(EmailChecker::class)->checkDisposableEmail('something@example.com','boolean')); ``` This email verification will be done on the basis of [disposable emails](https://en.wikipedia.org/wiki/Disposable_email_address) list, This function will check if entered email address is in the list of disposable or not. -#### Check DNS And MX Records +### Check DNS And MX Records Another usage is to check [DNS](https://en.wikipedia.org/wiki/Domain_Name_System) and [MX Record](https://en.wikipedia.org/wiki/MX_record) of the email address, In this method package will try to extract records from email address and try to verify using [SMTP](https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol). @@ -44,7 +50,7 @@ This will return array with success and details, Details will indicate email ver For better output your server needs to support [fsockopen()](https://www.php.net/manual/en/function.fsockopen.php). -#### Check Domain Status +### Check Domain Status Sometime it is hard to identify that email exist or not based on DNS and MX Records, So this method will check the domain status using [cURL](https://www.php.net/manual/en/book.curl.php). @@ -56,26 +62,29 @@ app(EmailChecker::class)->checkDomain('something@example.com')); This method will return TRUE or FALSE, if it successfully get response then it will return TRUE. Response validates based on [HTTP Status Code](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes). -#### Check Email +### Check Email This method will use all of the methods and it gives detail response, if it gives TRUE. If any of the method will respond with FALSE then will not give detail report. ``` -app(EmailChecker::class)->checkEmail('something@example.com')); +app(EmailChecker::class)->checkEmail('something@example.com','boolean')); ``` - + +As we have added new option with checkDisposableEmail() which has second argument that will enable deep check to compare domain with large list. + +Don't worry it would't take too much time. :) All are different method you can use individually as per your requirement. To call all of the method at once use **Check Email** ## Future Developement -Planning to add more disposable email list in next release. +Please let add your ideas to improve this package. ## Contribution -All contributer are appreciated, Code must follow [PSR2](https://www.php-fig.org/psr/psr-2/). create feature branch to compare with email checker. Your code must pass testcases. +All contributer are welcome, Code must follow [PSR2](https://www.php-fig.org/psr/psr-2/). create feature branch to compare with email checker. Your code must pass testcases. **NOTE** : This package will not ensure to verify each and email address, some of them cannot be verify due to MAIL server securities. diff --git a/composer.json b/composer.json index 8640b25..c8642dd 100644 --- a/composer.json +++ b/composer.json @@ -1,10 +1,26 @@ { "name": "aman00323/emailchecker", "description": "Laravel package for checking email address is exist or not in real world", + "keywords": [ + "email validation", + "disposable email checker", + "php email verifier", + "email exist or not", + "disposable emails", + "email verification" + ], + "homepage": "https://github.com/aman00323/email-checker", + "license": "MIT", + "authors": [ + { + "name": "Aman Nurani", + "email": "work.amannurani@gmail.com", + "role": "Software Engineer" + } + ], "require": { "php": ">=7.0.0" }, - "license": "MIT", "minimum-stability": "stable", "prefer-stable": true, "autoload": { diff --git a/src/EmailChecker.php b/src/EmailChecker.php index fccb036..b39ec7d 100644 --- a/src/EmailChecker.php +++ b/src/EmailChecker.php @@ -2,6 +2,8 @@ namespace Aman\EmailVerifier; +use Aman\EmailVerifier\Helpers\Helper; + class EmailChecker { public $domian; @@ -19,13 +21,13 @@ class EmailChecker @return array */ - public function checkEmail($email) + public function checkEmail($email, $deepCheck = false) { $disposable = $mxrecord = $domain = array(); if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // check for disposable email - if ($this->checkDisposableEmail($email) === true) { + if ($this->checkDisposableEmail($email, $deepCheck) === true) { return [ 'success' => false, 'error' => 'Entered email address is disposable', @@ -82,7 +84,7 @@ public function checkEmail($email) @return true | false */ - public function checkDisposableEmail($email) + public function checkDisposableEmail($email, $deepCheck = false) { if (filter_var($email, FILTER_VALIDATE_EMAIL)) { $domain = $this->splitEmail($email); @@ -93,6 +95,10 @@ public function checkDisposableEmail($email) |fansworldwide.de|privymail.de|gishpuppy|spamevader|uroid|tempmail|soodo|deadaddress|trbvm)/i", $domain)) // Possiblities of domain name that can genrate dispossable emails COURTESY FORMGET { return true; + } + + if ($deepCheck) { + return Helper::deepCheck($domain); } else { return false; } diff --git a/src/Helpers/Helper.php b/src/Helpers/Helper.php new file mode 100644 index 0000000..4fd77bc --- /dev/null +++ b/src/Helpers/Helper.php @@ -0,0 +1,119 @@ +disposableEmailList(); for ($i = 0; $i < count($dispossibleEmail); $i++) { self::assertTrue( - $emailChecker->checkDisposableEmail($dispossibleEmail[$i]) + $emailChecker->checkDisposableEmail($dispossibleEmail[$i], true) ); } $emailList = $this->emailList(); @@ -28,7 +28,7 @@ public function testCheckDomain() $emailChecker = new EmailChecker(); $emailList = $this->emailList(); for ($i = 0; $i < count($emailList); $i++) { - $response = $emailChecker->checkDomain($emailList[$i]); + $response = $emailChecker->checkDomain($emailList[$i], false); self::assertTrue($response); }