Skip to content

Commit bcaa76f

Browse files
Initial release
1 parent f19b43a commit bcaa76f

File tree

13 files changed

+362
-1
lines changed

13 files changed

+362
-1
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

.gitattributes

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1-
# Auto detect text files and perform LF normalization
21
* text=auto
2+
3+
*.md diff=markdown
4+
*.php diff=php
5+
6+
/.github export-ignore
7+
/tests export-ignore
8+
.editorconfig export-ignore
9+
.gitattributes export-ignore
10+
.gitignore export-ignore
11+
.styleci.yml export-ignore
12+
CHANGELOG.md export-ignore
13+
phpstan.neon.dist export-ignore
14+
phpunit.xml.dist export-ignore

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.idea/
2+
/.vscode/
3+
/*.iml
4+
/vendor
5+
/.env
6+
composer.lock
7+
/phpunit.xml
8+
.phpunit.result.cache

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
3+
All notable changes to `laravel-sift` will be documented in this file.
4+
5+
## 1.0.0 - 2025-02-06
6+
7+
- Initial release.

README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Sift – Simple Email Domain Extraction & Filtering
2+
3+
Sift is a **Laravel package** for extracting and filtering email domains. Whether you're handling **user registrations**, **blocking public email providers**, or ensuring only **business emails** are used, **Sift** makes it simple.
4+
5+
## Features
6+
- **Domain Extraction** → Extracts the domain from any email address.
7+
- **Smart Filtering** → Automatically detects and filters out public/free email providers.
8+
- **Handles Major Providers** → Includes Gmail, Yahoo, Outlook, and many more out of the box.
9+
- **Customizable** → Easily modify the list of common domains in the config file.
10+
- **Laravel-Optimized** → Designed for seamless integration with Laravel.
11+
12+
## Installation
13+
Install Sift via Composer:
14+
15+
```sh
16+
composer require mischasigtermans/laravel-sift
17+
```
18+
19+
> **Note:** Laravel auto-discovers the package, so no manual setup is needed.
20+
21+
To publish the config file:
22+
23+
```sh
24+
php artisan vendor:publish --tag=sift-config
25+
```
26+
27+
This creates `config/sift.php`, allowing customization of filtered domains.
28+
29+
## Usage
30+
### **Extract an email's domain**
31+
```php
32+
use Sift;
33+
34+
Sift::domain('user@example.com'); // Returns 'example.com'
35+
36+
// By default, public email domains are filtered:
37+
Sift::domain('user@gmail.com'); // Returns null
38+
39+
// Allow public domains explicitly:
40+
Sift::domain('user@gmail.com', true); // Returns 'gmail.com'
41+
42+
// Business email remains unaffected:
43+
Sift::domain('user@company.com'); // Returns 'company.com'
44+
```
45+
46+
### **Check if a domain is common**
47+
```php
48+
Sift::isCommon('gmail.com'); // true
49+
Sift::isCommon('user@company.com'); // false
50+
Sift::isCommon('invalid-email'); // null
51+
```
52+
53+
### **Blade Example**
54+
```blade
55+
{{ Sift::domain('hello@company.org') }}
56+
```
57+
58+
## Configuration
59+
Modify the common domain list in `config/sift.php` after publishing the config:
60+
61+
```php
62+
return [
63+
'additional_domains' => [
64+
// 'example.org', 'testmail.com'
65+
],
66+
'common_domains' => [
67+
'gmail.com', 'yahoo.com', 'outlook.com', 'hotmail.com', 'icloud.com',
68+
'protonmail.com', 'zoho.com', 'gmx.com', 'aol.com', 'yandex.com',
69+
'qq.com', 'live.com', 'rediffmail.com', 'mail.com', 'bigmir.net',
70+
// (Full list continues...)
71+
],
72+
];
73+
```
74+
View the full list of common domains in the configuration file [here](https://github.com/mischasigtermans/laravel-sift/blob/main/config/sift.php).
75+
76+
## Running Tests
77+
Sift includes lightweight but effective tests using Pest. To run them:
78+
79+
```sh
80+
vendor/bin/pest
81+
```
82+
83+
## Contributing
84+
Contributions are welcome. If you spot missing providers or have improvements, feel free to:
85+
- Open an issue on GitHub
86+
- Submit a pull request
87+
88+
## License
89+
Sift is open-source software licensed under the MIT License.

composer.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "mischasigtermans/laravel-sift",
3+
"description": "Extract and filter common email domains in Laravel.",
4+
"keywords": ["email", "domain", "filter", "extract", "email extractor", "free email domains", "email blacklist", "domain blacklist", "Laravel"],
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Mischa Sigtermans",
9+
"email": "mischa@sigtermans.me"
10+
}
11+
],
12+
"require": {
13+
"php": "^8.0",
14+
"illuminate/support": "^9.0|^10.0|^11.0"
15+
},
16+
"require-dev": {
17+
"laravel/pint": "^1.20",
18+
"orchestra/testbench": "^8.31",
19+
"pestphp/pest": "^2.36",
20+
"pestphp/pest-plugin-laravel": "^2.4"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"MischaSigtermans\\Sift\\": "src/"
25+
}
26+
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"MischaSigtermans\\Sift\\Tests\\": "tests/"
30+
}
31+
},
32+
"scripts": {
33+
"test": "vendor/bin/pest"
34+
},
35+
"config": {
36+
"sort-packages": true,
37+
"allow-plugins": {
38+
"pestphp/pest-plugin": true
39+
}
40+
},
41+
"extra": {
42+
"laravel": {
43+
"providers": [
44+
"MischaSigtermans\\Sift\\SiftServiceProvider"
45+
],
46+
"aliases": {
47+
"Sift": "MischaSigtermans\\Sift\\Facades\\Sift"
48+
}
49+
}
50+
},
51+
"minimum-stability": "stable",
52+
"prefer-stable": true
53+
}

config/sift.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
return [
4+
// Add any custom domains you want to filter out
5+
'additional_domains' => [
6+
// 'example.org', 'testmail.com'
7+
],
8+
// Customize common domains to your liking
9+
'common_domains' => [
10+
'alice.it', 'aol.com', 'bigmir.net', 'bigpond.com', 'bluewin.ch', 'bk.ru', 'burnermail.io',
11+
'centrum.cz', 'docomo.ne.jp', 'excite.com', 'ezweb.ne.jp', 'free.fr', 'freenet.de',
12+
'fastmail.com', 'gmail.com', 'gmx.at', 'gmx.ch', 'gmx.com', 'gmx.de',
13+
'gmx.net', 'guerrillamail.com', 'hotmail.co.uk', 'hotmail.com', 'hotmail.de',
14+
'hotmail.es', 'hotmail.fr', 'hotmail.it', 'hushmail.com', 'icloud.com',
15+
'indiatimes.com', 'inbox.ru', 'laposte.net', 'libero.it', 'list.ru',
16+
'live.co.uk', 'live.com', 'live.de', 'live.es', 'live.fr', 'live.it',
17+
'lycos.com', 'mail.bg', 'mail.com', 'mail.ru', 'maildrop.cc', 'mailinator.com',
18+
'me.com', 'msn.com', 'orange.fr', 'outlook.com', 'protonmail.ch', 'protonmail.com',
19+
'qq.com', 'rediffmail.com', 'rocketmail.com', 'seznam.cz', 'sina.com',
20+
'softbank.ne.jp', 'sohu.com', 'tiscali.it', 't-online.de', 'temp-mail.org',
21+
'trashmail.com', 'virgilio.it', 'web.de', 'yahoo.ca', 'yahoo.co.in', 'yahoo.co.jp',
22+
'yahoo.co.uk', 'yahoo.com', 'yahoo.com.au', 'yahoo.com.sg', 'yahoo.de',
23+
'yahoo.es', 'yahoo.fr', 'yahoo.it', 'yandex.com', 'yopmail.com', 'zoho.com',
24+
'zoho.com.au', 'zoho.eu', 'zoho.in', '163.com', '126.com', '10minutemail.com',
25+
],
26+
];

src/Facades/Sift.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace MischaSigtermans\Sift\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
class Sift extends Facade
8+
{
9+
protected static function getFacadeAccessor(): string
10+
{
11+
return \MischaSigtermans\Sift\Sift::class;
12+
}
13+
}

src/Sift.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace MischaSigtermans\Sift;
4+
5+
use Illuminate\Support\Facades\Config;
6+
7+
class Sift
8+
{
9+
public static function domain(string $email, bool $includeCommon = false): ?string
10+
{
11+
$domain = self::extractDomain($email);
12+
13+
return ($domain && ($includeCommon || ! self::isCommon($domain))) ? $domain : null;
14+
}
15+
16+
public static function isCommon(string $emailOrDomain): ?bool
17+
{
18+
$domain = self::extractDomain($emailOrDomain);
19+
20+
if (! $domain) {
21+
return null;
22+
}
23+
24+
$commonDomains = array_merge(
25+
Config::get('sift.common_domains', []),
26+
Config::get('sift.additional_domains', [])
27+
);
28+
29+
return in_array($domain, $commonDomains, true);
30+
}
31+
32+
public static function extractDomain(string $emailOrDomain): ?string
33+
{
34+
if (str_contains($emailOrDomain, '@')) {
35+
$domain = strrchr($emailOrDomain, '@');
36+
37+
return $domain ? strtolower(substr($domain, 1)) : null;
38+
}
39+
40+
return strtolower($emailOrDomain);
41+
}
42+
}

src/SiftServiceProvider.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace MischaSigtermans\Sift;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
use MischaSigtermans\Sift\Facades\Sift as SiftFacade;
7+
8+
class SiftServiceProvider extends ServiceProvider
9+
{
10+
public function register()
11+
{
12+
$this->mergeConfigFrom(__DIR__.'/../config/sift.php', 'sift');
13+
14+
$this->app->singleton(Sift::class, function ($app) {
15+
return new Sift;
16+
});
17+
18+
$this->app->alias(Sift::class, SiftFacade::class);
19+
}
20+
21+
public function boot()
22+
{
23+
$this->publishes([
24+
__DIR__.'/../config/sift.php' => config_path('sift.php'),
25+
], 'sift-config');
26+
}
27+
}

0 commit comments

Comments
 (0)