-
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from FGRibreau/platform-rust
Rust support 👍
- Loading branch information
Showing
18 changed files
with
1,110 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,6 @@ compare.js | |
Gemfile.lock | ||
vendor/ | ||
.env | ||
|
||
rust.iml | ||
platform/rust/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# http://doc.crates.io/manifest.html | ||
|
||
[package] | ||
name = "mailchecker" | ||
version = "3.0.20" | ||
authors = ["François-Guillaume Ribreau <[email protected]>"] | ||
|
||
# A short blurb about the package. This is not rendered in any format when | ||
# uploaded to crates.io (aka this is not markdown). | ||
description = "Cross-language temporary (disposable/throwaway) email detection library. Covers 2740 fake email providers." | ||
|
||
# These URLs point to more information about the repository. These are | ||
# intended to be webviews of the relevant data, not necessarily compatible | ||
# with VCS tools and the like. | ||
documentation = "https://doc.rust-lang.org/mailchecker" | ||
homepage = "https://github.com/FGRibreau/mailchecker" | ||
repository = "https://github.com/FGRibreau/mailchecker" | ||
|
||
# This points to a file in the repository (relative to this `Cargo.toml`). The | ||
# contents of this file are stored and indexed in the registry. | ||
readme = "../../README.md" | ||
|
||
# This is a list of up to five keywords that describe this crate. Keywords | ||
# are searchable on crates.io, and you may choose any words that would | ||
# help someone find this crate. | ||
keywords = ["email", "validation", "validator", "domains", "disposable"] | ||
|
||
# This is a list of up to five categories where this crate would fit. | ||
# Categories are a fixed list available at crates.io/category_slugs, and | ||
# they must match exactly. | ||
categories = ["email", "web-programming"] | ||
|
||
# This is a string description of the license for this package. Currently | ||
# crates.io will validate the license provided against a whitelist of known | ||
# license identifiers from http://spdx.org/licenses/. Multiple licenses can be | ||
# separated with a `/`. | ||
license = "MIT" | ||
|
||
include = ["src/lib.rs", "Cargo.toml"] | ||
|
||
[dependencies] | ||
fast_chemail = "0.9.3" | ||
|
||
[dev-dependencies] | ||
|
||
[lib] | ||
|
||
# This field points at where the crate is located, relative to the `Cargo.toml`. | ||
path = "src/lib.rs" | ||
|
||
# A flag for enabling unit tests for this target. This is used by `cargo test`. | ||
test = true | ||
|
||
# A flag for enabling documentation tests for this target. This is only relevant | ||
# for libraries, it has no effect on other sections. This is used by | ||
# `cargo test`. | ||
doctest = true | ||
|
||
# A flag for enabling benchmarks for this target. This is used by `cargo bench`. | ||
bench = true | ||
|
||
# A flag for enabling documentation of this target. This is used by `cargo doc`. | ||
doc = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
extern crate mailchecker; | ||
use std::iter::FromIterator; | ||
|
||
trait ExtendedIterator: Iterator { | ||
fn tail<B>(&mut self) -> B where B:FromIterator<Self::Item>, Self::Item: Eq + Clone, Self: Sized{ | ||
self.next(); | ||
self.collect() | ||
} | ||
} | ||
|
||
impl<I> ExtendedIterator for I where I: Iterator {} | ||
|
||
fn main() { | ||
// let arr = vec!["[email protected]", "a", "b"]; | ||
// let t: Vec<_> = arr.iter().tail(); | ||
// println!("Tail: {} {}", t[0], t[1]); | ||
// | ||
// let t: Vec<_> = "ok@[email protected]".split("@").tail(); | ||
println!("Ok: {:?}", mailchecker::is_valid("[email protected]")); | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
extern crate fast_chemail; | ||
|
||
static BLACKLIST: &'static [&'static str] = &[{{ &listSTR }}]; | ||
|
||
|
||
/// # Usage | ||
/// | ||
/// | ||
/// The `mailchecker` crate provides a `is_valid(email)` function that ensure the email is valid **and** does not come from a disposable email service. | ||
/// | ||
/// # Examples | ||
/// | ||
/// Emails below will be considered valid: | ||
/// | ||
/// ``` | ||
/// extern crate mailchecker; | ||
/// | ||
/// assert_eq!(true, mailchecker::is_valid("[email protected]")); | ||
/// assert_eq!(true, mailchecker::is_valid("[email protected]")); | ||
/// assert_eq!(true, mailchecker::is_valid("[email protected]")); | ||
/// assert_eq!(true, mailchecker::is_valid("[email protected]")); | ||
/// assert_eq!(true, mailchecker::is_valid("[email protected]")); | ||
/// assert_eq!(true, mailchecker::is_valid("[email protected]")); | ||
/// ``` | ||
/// | ||
/// Emails below will be considered invalid because of a wrong format: | ||
/// | ||
/// ``` | ||
/// extern crate mailchecker; | ||
/// | ||
/// assert_eq!(false, mailchecker::is_valid("")); | ||
/// assert_eq!(false, mailchecker::is_valid("plopplop.com")); | ||
/// assert_eq!(false, mailchecker::is_valid("my+ok@ok=plop.com")); | ||
/// assert_eq!(false, mailchecker::is_valid("my,[email protected]")); | ||
/// assert_eq!(false, mailchecker::is_valid(" [email protected] ")); | ||
/// assert_eq!(false, mailchecker::is_valid(" [email protected]")); | ||
/// assert_eq!(false, mailchecker::is_valid("[email protected] ")); | ||
/// assert_eq!(false, mailchecker::is_valid("\[email protected]\n")); | ||
/// assert_eq!(false, mailchecker::is_valid("\[email protected]")); | ||
/// assert_eq!(false, mailchecker::is_valid("[email protected]\n")); | ||
/// ``` | ||
/// | ||
/// Emails below will be considered invalid because they came from an invalid domain | ||
/// | ||
/// ``` | ||
/// extern crate mailchecker; | ||
/// | ||
/// assert_eq!(false, mailchecker::is_valid("[email protected]")); | ||
/// assert_eq!(false, mailchecker::is_valid("[email protected]")); | ||
/// assert_eq!(false, mailchecker::is_valid("[email protected]")); | ||
/// ``` | ||
pub fn is_valid(email: &str) -> bool { | ||
// first check that the email is valid | ||
if !fast_chemail::is_valid_email(email) { | ||
return false; | ||
} | ||
|
||
let lowercase_email = email.to_lowercase(); | ||
let email_domain_is_in_blacklist = all_domain_suffixes(&lowercase_email).iter().any(|ref domain| suffix_is_blacklisted(domain)); | ||
return !email_domain_is_in_blacklist; | ||
} | ||
|
||
fn all_domain_suffixes(email: &str) -> Vec<String>{ | ||
let domains = email.split("@").skip(1).collect::<String>(); | ||
let domain_part: Vec<&str> = domains.split('.').collect(); | ||
(1..domain_part.len()+1).map(|i| (domain_part[0..i]).iter().map(|&x| x).collect::<Vec<&str>>().join(".")).collect::<Vec<String>>() | ||
} | ||
|
||
|
||
fn suffix_is_blacklisted(domain: &str) -> bool{ | ||
return BLACKLIST.contains(&domain) | ||
} | ||
|
||
/// # Usage | ||
/// | ||
/// | ||
/// `blacklist` exposes the vector of disposable domains | ||
/// | ||
/// | ||
/// | ||
/// ``` | ||
/// extern crate mailchecker; | ||
/// | ||
/// assert!(mailchecker::blacklist().len() > 2000, "blacklist should at least contain 2000 items"); | ||
/// ``` | ||
pub fn blacklist() -> Vec<&'static str> { | ||
return BLACKLIST.to_vec(); | ||
} | ||
|
||
|
||
// Helpers | ||
// https://gist.github.com/FGRibreau/9bab6501c13367e787b5f31dc1d670f4 | ||
|
||
use std::iter::FromIterator; | ||
|
||
trait ExtendedIterator: Iterator { | ||
fn tail<B>(&mut self) -> B where B:FromIterator<Self::Item>, Self::Item: Eq + Clone, Self: Sized{ | ||
self.skip(1).collect::<B>() | ||
} | ||
} | ||
|
||
impl<I> ExtendedIterator for I where I: Iterator {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta http-equiv="refresh" content="0;URL=fn.blacklist.html"> | ||
</head> | ||
<body> | ||
<p>Redirecting to <a href="fn.blacklist.html">fn.blacklist.html</a>...</p> | ||
<script>location.replace("fn.blacklist.html" + location.search + location.hash);</script> | ||
</body> | ||
</html> |
Oops, something went wrong.