Merge pull request #126 from andrewvk/cs-usage

C# usage sample
This commit is contained in:
François-Xavier de Guillebon 2017-10-22 23:37:40 +02:00 committed by GitHub
commit ed360890bd

View File

@ -86,6 +86,40 @@ rl.on('close', () => {
}); });
``` ```
**C#**
```C#
private static readonly Lazy<HashSet<string>> _emailBlackList =
new Lazy<HashSet<string>>(
() =>
{
var result = new HashSet<string>(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;
});
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 (IsBlacklisted(addr.Host)))
throw new ApplicationException("Email is blacklisted.");
```
Contributing Contributing
============ ============
Feel free to create PR with additions or request removal of some domain (with reasons). Feel free to create PR with additions or request removal of some domain (with reasons).