mirror of
https://github.com/disposable-email-domains/disposable-email-domains.git
synced 2024-11-22 00:28:12 +08:00
Add disposable email checker in Dart and update README
This commit is contained in:
parent
0c27e67123
commit
c84e60ef62
35
README.md
35
README.md
@ -243,3 +243,38 @@ func checkBlockList(email: String, completion: @escaping (Bool) -> Void) {
|
||||
task.resume()
|
||||
}
|
||||
```
|
||||
|
||||
### Dart
|
||||
contributed by [@the-razib](https://github.com/the-razib)
|
||||
|
||||
```dart
|
||||
import 'dart:io';
|
||||
|
||||
Future<Set<String>> loadBlocklist() async {
|
||||
const filePath = 'lib/disposable_email_blocklist.conf';
|
||||
final file = File(filePath);
|
||||
|
||||
if (!(await file.exists())) {
|
||||
throw Exception("Blocklist file not found at path: $filePath");
|
||||
}
|
||||
|
||||
final lines = await file.readAsLines();
|
||||
return lines.map((line) => line.trim().toLowerCase()).toSet();
|
||||
}
|
||||
|
||||
Future<bool> isDisposableEmail(String email) async {
|
||||
final blocklist = await loadBlocklist();
|
||||
final emailDomain = email.split('@').last.toLowerCase();
|
||||
return blocklist.contains(emailDomain);
|
||||
}
|
||||
|
||||
void main() async {
|
||||
const email = "test@gmail.com";
|
||||
|
||||
if (await isDisposableEmail(email)) {
|
||||
print("Please enter your permanent email address.");
|
||||
} else {
|
||||
print("Email is valid.");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user