From b1c04c5bad5f2d42ee5de8b98f1e06d99eb2223b Mon Sep 17 00:00:00 2001 From: Andrew Koryavchenko Date: Sat, 21 Oct 2017 16:10:57 +0300 Subject: [PATCH 1/2] C# usage sample --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 163d82b..9679e4e 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,30 @@ rl.on('close', () => { }); ``` +**C#** +```C# +private static readonly Lazy> _emailBlackList = + new Lazy>( + () => + { + var result = new HashSet(StringComparer.OrdinalIgnoreCase); + using (var reader = new StreamReader("disposable_email_blacklist.conf")) + { + string line; + while ((line = reader.ReadLine()) != null) + if (!string.IsNullOrWhiteSpace(line) && !line.TrimStart().StartsWith("//")) + result.Add(line); + } + return result; + }); + +... + +var addr = new MailAddress(email); +if (_emailBlackList.Value.Contains(addr.Host))) + throw new ApplicationException("Email is blacklisted."); +``` + Contributing ============ Feel free to create PR with additions or request removal of some domain (with reasons). From 41ae31c0eb2e9020faae57bff8f4ce5b9a979b77 Mon Sep 17 00:00:00 2001 From: Andrew Koryavchenko Date: Mon, 23 Oct 2017 00:20:57 +0300 Subject: [PATCH 2/2] Fix C# sample --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9679e4e..31a4608 100644 --- a/README.md +++ b/README.md @@ -103,10 +103,20 @@ private static readonly Lazy> _emailBlackList = return result; }); +private static bool IsBlacklisted(string domain) +{ + var parts = domain.Split('.'); + var len = parts.Length; + return + len == 1 && _emailBlackList.Value.Contains(domain) + || _emailBlackList.Value.Contains($"{parts[len - 2]}.{parts[len - 1]}") + || len > 2 && _emailBlackList.Value.Contains($"{parts[len - 3]}.{parts[len - 2]}.{parts[len - 1]}"); +} + ... var addr = new MailAddress(email); -if (_emailBlackList.Value.Contains(addr.Host))) +if (IsBlacklisted(addr.Host))) throw new ApplicationException("Email is blacklisted."); ```