From c84e60ef62e1ab69ff22d2205587d63a16da06d8 Mon Sep 17 00:00:00 2001 From: Md Razib <74146449+the-razib@users.noreply.github.com> Date: Sun, 3 Nov 2024 09:54:03 +0600 Subject: [PATCH] Add disposable email checker in Dart and update README --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 78c3be2..b61cfe7 100644 --- a/README.md +++ b/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> 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 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."); + } +} +```