├── .github ├── CODEOWNERS ├── FUNDING.yml ├── pull_request_template.md └── workflows │ ├── ci-phpstan.yml │ └── ci-tests.yml ├── .gitignore ├── .styleci.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── UPGRADE.md ├── composer.json ├── config └── active-email.php ├── phpstan.neon ├── phpunit.xml ├── src ├── DisposableEmail.php ├── Facades │ └── ActiveEmail.php ├── Providers │ └── ActiveEmailProvider.php └── Rules │ └── NotBlacklistedEmail.php ├── testbench.yaml └── tests ├── Architecture ├── ClassesTest.php ├── GlobalsTest.php └── ProvidersTest.php ├── Pest.php ├── TestCase.php └── Unit ├── ActiveEmailTest.php └── TestCase.php /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | ## Code changes will send PR to following users. 2 | * @veeqtoh 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: veeqtoh 4 | custom: https://www.paypal.com/paypalme/veeqtoh 5 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ### Motivation and Context ### 2 | Why is this change required? What problem does it solve? If it fixes an open issue, please link to the issue here. 3 | 4 | 5 | 6 | ### Dependencies ### 7 | Note if this change has any dependencies, e.g. a library (write the command to install it here e.g composer install or update ) 8 | 9 | 10 | 11 | ### Test Instructions ### 12 | Provide a list of tests the reviewer must complete to appropriately QA this work. This may include automated or manual tests. Consider the complexity of the change when compiling this list, and be sure to include any build instructions e.g. composer install. 13 | -------------------------------------------------------------------------------- /.github/workflows/ci-phpstan.yml: -------------------------------------------------------------------------------- 1 | name: run-phpstan 2 | 3 | on: 4 | pull_request: 5 | 6 | jobs: 7 | run-tests: 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | php: [8.1, 8.2, 8.3] 13 | laravel: [10.*, 11.*] 14 | include: 15 | - laravel: 11.* 16 | testbench: 9.* 17 | - laravel: 10.* 18 | testbench: 8.* 19 | exclude: 20 | - laravel: 11.* 21 | php: 8.1 22 | 23 | name: PHP${{ matrix.php }} - Laravel ${{ matrix.laravel }} 24 | 25 | steps: 26 | - name: Update apt 27 | run: sudo apt-get update --fix-missing 28 | 29 | - name: Checkout code 30 | uses: actions/checkout@v2 31 | 32 | - name: Setup PHP 33 | uses: shivammathur/setup-php@v2 34 | with: 35 | php-version: ${{ matrix.php }} 36 | coverage: none 37 | 38 | - name: Setup Problem Matches 39 | run: | 40 | echo "::add-matcher::${{ runner.tool_cache }}/php.json" 41 | echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" 42 | 43 | - name: Install dependencies 44 | run: | 45 | composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update 46 | composer update --prefer-dist --no-interaction --no-suggest 47 | - name: Run Larastan 48 | run: vendor/bin/phpstan analyse -------------------------------------------------------------------------------- /.github/workflows/ci-tests.yml: -------------------------------------------------------------------------------- 1 | name: tests 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - '*.x' 8 | pull_request: 9 | schedule: 10 | - cron: '0 0 * * *' 11 | 12 | jobs: 13 | tests: 14 | runs-on: ubuntu-22.04 15 | 16 | strategy: 17 | fail-fast: true 18 | matrix: 19 | php: [8.1, 8.2, 8.3, 8.4] 20 | 21 | name: PHP ${{ matrix.php }} 22 | 23 | steps: 24 | - name: Checkout code 25 | uses: actions/checkout@v4 26 | 27 | - name: Setup PHP 28 | uses: shivammathur/setup-php@v2 29 | with: 30 | php-version: ${{ matrix.php }} 31 | extensions: dom, curl, libxml, mbstring, zip, bcmath 32 | ini-values: error_reporting=E_ALL 33 | tools: composer:v2 34 | coverage: none 35 | 36 | - name: Install dependencies (Laravel 10) 37 | run: | 38 | composer update --prefer-dist --no-interaction --no-progress --with="illuminate/contracts:^10" 39 | if: matrix.php >= 8.1 && matrix.php < 8.4 40 | 41 | - name: Execute tests (Laravel 10) 42 | run: ./vendor/bin/pest --display-deprecations --fail-on-deprecation 43 | if: matrix.php >= 8.1 && matrix.php < 8.4 44 | 45 | - name: Install dependencies (Laravel 11) 46 | run: | 47 | composer update --prefer-dist --no-interaction --no-progress --with="illuminate/contracts:^11" 48 | if: matrix.php >= 8.2 && matrix.php <= 8.4 49 | 50 | - name: Execute tests (Laravel 11) 51 | run: ./vendor/bin/pest --display-deprecations --fail-on-deprecation 52 | if: matrix.php >= 8.2 && matrix.php <= 8.4 53 | 54 | - name: Install dependencies (Laravel 12) 55 | run: | 56 | composer update --prefer-dist --no-interaction --no-progress --with="illuminate/contracts:^12" 57 | if: matrix.php >= 8.2 && matrix.php <= 8.4 58 | 59 | - name: Execute tests (Laravel 12) 60 | run: ./vendor/bin/pest --display-deprecations --fail-on-deprecation 61 | if: matrix.php >= 8.2 && matrix.php <= 8.4 62 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | vendor/ 3 | composer.lock 4 | composer.phar 5 | /.phpunit.cache -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Victor Ukam 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # laravel-active-email 2 | 3 |
9 | 10 | ## Table of Contents 11 | 12 | - [Overview](#overview) 13 | - [Key Features](#key-features) 14 | - [Installation](#installation) 15 | - [Requirements](#requirements) 16 | - [Install the Package](#install-the-package) 17 | - [Publish the Config](#publish-the-config) 18 | - [Usage](#usage) 19 | - [Validator Approach](#validator-approach) 20 | - [Class Approach](#class-approach) 21 | - [Customization](#customization) 22 | - [Strict Mode](#strict-mode) 23 | - [Black List](#black-list) 24 | - [Grey List](#grey-list) 25 | - [White List](#white-list) 26 | - [Error Message](#error-message) 27 | - [Testing](#testing) 28 | - [To do](#to-do) 29 | - [Security](#security) 30 | - [Contribution](#contribution) 31 | - [Changelog](#changelog) 32 | - [Upgrading](#upgrading) 33 | - [License](#license) 34 | 35 | ## Overview 36 | 37 | This package provides a library of disposable domains and adds a validator to Laravel apps to check that a given email address isn't coming from a disposable email service such as `Mailinator`, `Guerillamail`, `Tempmail` considering all their possible wildcards. 38 | 39 | ### Key Features 40 | 41 | - You can add your own preferred domains to the [black list](#black-list). 42 | - You can [white list](#white-list) a domain to bye pass the blacklist. This can be useful in development environment. 43 | - With [strict mode](#strict-mode), you can control the strictness of the validator, thereby allowing or preventing domains that are not necessarily disposable, but have been classified as disposable. 44 | - Case-aware. 45 | - Wildcard-aware. 46 | 47 | ## Installation 48 | 49 | 50 | ### Requirements 51 | 52 | The package has been developed and tested to work with the following minimum requirements: 53 | 54 | - PHP 8.x 55 | - Laravel 10.x and above. 56 | 57 | ### Install the Package 58 | 59 | You can install the package via Composer. The service provider is discovered automatically. 60 | 61 | ```bash 62 | composer require veeqtoh/laravel-active-email 63 | ``` 64 | 65 | ### Publish the Config 66 | 67 | You can then publish the package's config file and update it as you'd prefer: 68 | ```bash 69 | php artisan vendor:publish --provider="Veeqtoh\ActiveEmail\Providers\ActiveEmailProvider" 70 | ``` 71 | 72 | ## Usage 73 | 74 | ### Validator Approach 75 | 76 | Add the `notblacklisted` validator to your email validation rules array (or string) to ensure that the domain for a given email address is not blacklisted. I'd recommend you add it after the email validator to make sure a valid email is passed through: 77 | ```php 78 | 'emailField' => 'email|notblacklisted', 79 | ``` 80 | 81 | or 82 | 83 | ```php 84 | 'emailField' => ['email', 'notblacklisted'], 85 | ``` 86 | 87 | ### Class Approach 88 | 89 | Instantiate the `NotBlackListedEmail` Class as part of your email validation rules array to ensure that the domain for a given email address is not blacklisted. Again, I'd recommend you add it after the email validator to make sure a valid email is passed through: 90 | 91 | ```php 92 | use Veeqtoh\ActiveEmail\Rules\NotBlackListedEmail; 93 | 94 | 'emailField' => ['email', new NotBlackListedEmail()], 95 | ``` 96 | 97 | ### Customization 98 | 99 | The package is highly customizable from the config file with the following features: 100 | 101 | #### Strict Mode 102 | 103 | This value determines the strictness level of this feature. when set to `true`, domains in the [grey list](#grey-list) are also blacklisted. 104 | 105 | It is turned on by default, but can be set in your .env file as follows: 106 | 107 | ```php 108 | DISPOSABLE_EMAIL_STRICT_MODE=true, 109 | ``` 110 | 111 | #### Black List 112 | 113 | This is a list of base domains with or without the TLD that are blacklisted by default. Add a domain to this list to blacklist it. 114 | 115 | #### Grey List 116 | 117 | This is a list of base domains with or without the TLD that aren't blacklisted by default except when in strict mode. Add a domain to this list to whitelist it when the feature is not set to strict mode. Ensure that the domain is not on the [black list](#black-list). 118 | 119 | #### White List 120 | 121 | This is a list of base domains with or without the TLD that are blacklisted by default but you want them to be bye passed. 122 | 123 | #### Error Message 124 | 125 | You may define your preferred error message or leave as is to use the package's. 126 | 127 | ## To Do 128 | 129 | There's always something that can be done to improve this package. I'd keep updating this list as I think of them. 130 | 131 | - Crawl the web to grab an updated list of disposable domains. 132 | - Maybe setup a schedule for it.. 133 | 134 | ## Testing 135 | 136 | To run the package's unit tests, run the following command: 137 | 138 | ``` bash 139 | vendor/bin/pest 140 | ``` 141 | 142 | ## Security 143 | 144 | If you find any security related issues, please contact me directly at [victorjohnukam@gmail.com](mailto:victorjohnukam@gmail.com) to report it. 145 | 146 | ## Contribution 147 | 148 | If you wish to make any changes or improvements to the package, feel free to make a pull request. 149 | 150 | Note: A contribution guide will be added soon. 151 | 152 | ## Changelog 153 | 154 | Check the [CHANGELOG](CHANGELOG.md) to get more information about the latest changes. 155 | 156 | ## Upgrading 157 | 158 | Check the [UPGRADE](UPGRADE.md) guide to get more information on how to update this library to newer versions. 159 | 160 | ## License 161 | 162 | The MIT License (MIT). Please see [License File](LICENSE) for more information. 163 | 164 | ## Support Me 165 | 166 | If you've found this package useful, please consider [sponsoring this project](https://github.com/sponsors/veeqtoh). It will encourage me to keep maintaining it. 167 | -------------------------------------------------------------------------------- /UPGRADE.md: -------------------------------------------------------------------------------- 1 | # Upgrade -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "veeqtoh/laravel-active-email", 3 | "description": "A Laravel package providing validation rule against disposable email addresses.", 4 | "type": "library", 5 | "homepage": "https://github.com/veeqtoh/laravel-active-email", 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Victor Ukam", 10 | "email": "victorjohnukam@gmail.com" 11 | } 12 | ], 13 | "keywords": [ 14 | "veeqtoh", 15 | "victor-ukam", 16 | "disposable-email", 17 | "disposable-emails", 18 | "disposable-emails-domains", 19 | "disposable-email-domains", 20 | "validation", 21 | "validation-rule", 22 | "laravel-validation", 23 | "active-email-address", 24 | "laravel", 25 | "laravel-package" 26 | ], 27 | "require": { 28 | "php": "^8.1", 29 | "nesbot/carbon": "^2.0|^3.0", 30 | "illuminate/container": "^10.0|^11.0|^12.0", 31 | "illuminate/database": "^10.0|^11.0|^12.0" 32 | }, 33 | "require-dev": { 34 | "mockery/mockery": "^1.0", 35 | "orchestra/testbench": "^8.0|^9.0|^10.0", 36 | "larastan/larastan": "^2.0", 37 | "pestphp/pest-plugin-laravel": "^2.3|^3.0" 38 | }, 39 | "autoload": { 40 | "psr-4": { 41 | "Veeqtoh\\ActiveEmail\\": "src/" 42 | } 43 | }, 44 | "autoload-dev": { 45 | "psr-4": { 46 | "Veeqtoh\\ActiveEmail\\Tests\\": "tests/" 47 | } 48 | }, 49 | "extra": { 50 | "laravel": { 51 | "providers": [ 52 | "Veeqtoh\\ActiveEmail\\Providers\\ActiveEmailProvider" 53 | ], 54 | "aliases": { 55 | "ActiveEmail": "Veeqtoh\\ActiveEmail\\Facades\\ActiveEmail" 56 | } 57 | } 58 | }, 59 | "scripts": { 60 | "test": "vendor/bin/pest" 61 | }, 62 | "minimum-stability": "dev", 63 | "prefer-stable": true, 64 | "config": { 65 | "allow-plugins": { 66 | "pestphp/pest-plugin": true 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /config/active-email.php: -------------------------------------------------------------------------------- 1 | env('DISPOSABLE_EMAIL_STRICT_MODE', true), 15 | 16 | /* 17 | |-------------------------------------------------------------------------- 18 | | Black List 19 | |-------------------------------------------------------------------------- 20 | | 21 | | This is a list of base domains with or without the TLD that are 22 | | blacklisted by default. Add a domain to this list to blacklist it. 23 | | 24 | */ 25 | 26 | 'blacklist' => [ 27 | // 28 | ], 29 | 30 | /* 31 | |-------------------------------------------------------------------------- 32 | | Grey List 33 | |-------------------------------------------------------------------------- 34 | | 35 | | This is a list of base domains with or without the TLD that aren't 36 | | blacklisted by default except when in strict mode. Add a domain to this 37 | | list to whitelist it when the feature is not set to strict mode. 38 | | Ensure that the domain is not on the blacklist above. 39 | | 40 | */ 41 | 42 | 'greylist' => [ 43 | // 44 | ], 45 | 46 | /* 47 | |-------------------------------------------------------------------------- 48 | | White List 49 | |-------------------------------------------------------------------------- 50 | | 51 | | This is a list of base domains with or without the TLD that are 52 | | blacklisted by default but you want them to be bye passed. 53 | | 54 | */ 55 | 56 | 'whitelist' => [ 57 | // 58 | ], 59 | 60 | /* 61 | |-------------------------------------------------------------------------- 62 | | Validation Message 63 | |-------------------------------------------------------------------------- 64 | | 65 | | This is the message that is displayed when an email fails validation. 66 | | Leave as is to use the package's default message. 67 | | 68 | */ 69 | 70 | 'error_message' => '', 71 | 72 | ]; 73 | -------------------------------------------------------------------------------- /phpstan.neon: -------------------------------------------------------------------------------- 1 | includes: 2 | - ./vendor/larastan/larastan/extension.neon 3 | 4 | parameters: 5 | 6 | paths: 7 | - src 8 | 9 | level: 4 10 | 11 | ignoreErrors: 12 | 13 | checkMissingIterableValueType: false -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 |