Skip to content

Commit

Permalink
Merge pull request #92 from FGRibreau/platform-rust
Browse files Browse the repository at this point in the history
Rust support 👍
  • Loading branch information
FGRibreau authored Jan 28, 2017
2 parents 3e1f458 + f3ceb6e commit 625d483
Show file tree
Hide file tree
Showing 18 changed files with 1,110 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ compare.js
Gemfile.lock
vendor/
.env

rust.iml
platform/rust/target/
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ npm run build

These amazing people are maintaining this project:

<ul><li><a href="http://bit.ly/2c7uFJq">Francois-Guillaume Ribreau</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=FGRibreau" title="View the GitHub contributions of Francois-Guillaume Ribreau on repository FGRibreau/mailchecker">view contributions</a></li></ul>
<ul><li><a href="http://bit.ly/2c7uFJq">Francois-Guillaume Ribreau</a></li></ul>

<h3>Sponsors</h3>

Expand All @@ -240,30 +240,30 @@ No sponsors yet! Will you be the first?

These amazing people have contributed code to this project:

<ul><li><a href="http://www.owenstephens.co.uk">Owen Stephens</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=owst" title="View the GitHub contributions of Owen Stephens on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="http://jacobburenstam.com">Jacob Burenstam</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=buren" title="View the GitHub contributions of Jacob Burenstam on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="http://hermanslatman.nl">Herman Slatman</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=hslatman" title="View the GitHub contributions of Herman Slatman on repository FGRibreau/mailchecker">view contributions</a></li>
<ul><li><a href="http://www.owenstephens.co.uk">Owen Stephens</a></li>
<li><a href="http://jacobburenstam.com">Jacob Burenstam</a></li>
<li><a href="http://hermanslatman.nl">Herman Slatman</a></li>
<li><a href="https://github.com/trisix">trisix</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=trisix" title="View the GitHub contributions of trisix on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="http://greenkeeper.io/">Greenkeeper</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=greenkeeperio-bot" title="View the GitHub contributions of Greenkeeper on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="http://greenkeeper.io/">Greenkeeper</a></li>
<li><a href="http://wusty.io">Dustin Clark</a></li>
<li><a href="http://antonz.ru/">Anton Zhiyanov</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=algenon" title="View the GitHub contributions of Anton Zhiyanov on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="http://antonz.ru/">Anton Zhiyanov</a></li>
<li><a href="https://github.com/NBruel">Bruel Nicolas</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=NBruel" title="View the GitHub contributions of Bruel Nicolas on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="https://github.com/R-J">Robin</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=R-J" title="View the GitHub contributions of Robin on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="https://github.com/Spir">Spir</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=Spir" title="View the GitHub contributions of Spir on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="http://flat.io">Vincent Giersch</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=gierschv" title="View the GitHub contributions of Vincent Giersch on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="http://flat.io">Vincent Giersch</a></li>
<li><a href="https://github.com/watadarkstar">watadarkstar</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=watadarkstar" title="View the GitHub contributions of watadarkstar on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="http://djpowers.github.io">Dave Powers</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=djpowers" title="View the GitHub contributions of Dave Powers on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="http://djpowers.github.io">Dave Powers</a></li>
<li><a href="https://github.com/frankydp">Frank Phillips</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=frankydp" title="View the GitHub contributions of Frank Phillips on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="https://github.com/LuckyDino">LuckyDino</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=LuckyDino" title="View the GitHub contributions of LuckyDino on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="https://github.com/vendethiel">ven</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=vendethiel" title="View the GitHub contributions of ven on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="http://www.linkedin.com/in/romaingay">Romain Gay</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=vikbez" title="View the GitHub contributions of Romain Gay on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="http://stormforger.com">Sebastian Cohnen</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=tisba" title="View the GitHub contributions of Sebastian Cohnen on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="http://www.linkedin.com/in/romaingay">Romain Gay</a></li>
<li><a href="http://stormforger.com">Sebastian Cohnen</a></li>
<li><a href="https://github.com/dav1a1223">Dalai</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=dav1a1223" title="View the GitHub contributions of Dalai on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="https://github.com/quaswex">quaswex</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=quaswex" title="View the GitHub contributions of quaswex on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="https://github.com/sxyuan">sxyuan</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=sxyuan" title="View the GitHub contributions of sxyuan on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="http://bit.ly/2c7uFJq">Francois-Guillaume Ribreau</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=FGRibreau" title="View the GitHub contributions of Francois-Guillaume Ribreau on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="http://dusty.wtf">Dustin Clark</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=dustywusty" title="View the GitHub contributions of Dustin Clark on repository FGRibreau/mailchecker">view contributions</a></li>
<li><a href="http://synpro.io">larsvegas</a> — <a href="https://github.com/FGRibreau/mailchecker/commits?author=larsvegas" title="View the GitHub contributions of larsvegas on repository FGRibreau/mailchecker">view contributions</a></li></ul>
<li><a href="http://bit.ly/2c7uFJq">Francois-Guillaume Ribreau</a></li>
<li><a href="http://dusty.wtf">Dustin Clark</a></li>
<li><a href="http://synpro.io">larsvegas</a></li></ul>



Expand Down
5 changes: 5 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ machine:
version: 2.2.2
python:
version: pypy-2.2.1
services:
- docker



dependencies:
override:
Expand All @@ -21,3 +25,4 @@ test:
- phpunit test/platform.php.test.php
- ruby test/platform.ruby.test.rb
- python test/platform.python.test.py
- docker run -it --rm -v $(pwd)/platform/rust:/source jimmycuadra/rust cargo test
2 changes: 1 addition & 1 deletion lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var Generator = new EventEmitter2({
Generator.DIR = p.resolve(__dirname, '../platform');

Generator.getTemplatesSync = function () {
return glob.sync(p.resolve(this.DIR, './*/*.tmpl.*')).map(this.parsePath);
return glob.sync(p.resolve(this.DIR, './**/*.tmpl.*')).map(this.parsePath);
};

Generator.parsePath = function (fullpath) {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
"changelog": "github-changes --o $(node -p 'process.env.npm_package_repository_url.split(\"/\")[3];') --r $(node -p 'a=process.env.npm_package_repository_url.split(\"/\");a[a.length-1].split(\".\")[0]') --token $CHANGELOG_GITHUB_TOKEN_FG -f CHANGELOG.md",
"changelog-git": "npm run changelog && git add CHANGELOG.md && git commit -m 'docs(changelog): updated' && git push origin master",
"release-after-pr": "git pull --rebase && npm run build && npm run test && git commit -a -m 'feat(build): update plateform files' && npm run release-patch",
"release-patch": "npm-release patch && npm run changelog-git && npm run publish-gem",
"publish-gem": "sed -E -i '' \"s/spec.version[[:space:]]*=(.*)/spec.version='${npm_package_version}'/g\" *.gemspec && (git add *.gemspec && git commit -m \"feat(gemspec): updated to ${npm_package_version}\" || true) && gem build *.gemspec && gem push ruby-mailchecker-${npm_package_version}.gem"
"release-patch": "npm-release patch && npm run changelog-git && npm run publish-gem && npm run publish-cargo",
"publish-gem": "sed -E -i '' \"s/spec.version[[:space:]]*=(.*)/spec.version='${npm_package_version}'/g\" *.gemspec && (git add *.gemspec && git commit -m \"feat(gemspec): updated to ${npm_package_version}\" || true) && gem build *.gemspec && gem push ruby-mailchecker-${npm_package_version}.gem",
"publish-cargo": "cd platform/rust && sed -E -i '' \"s/version[[:space:]]*=(.*)/version = \\\"${npm_package_version}\\\"/g\" Cargo.toml && (git add Cargo.toml && git commit -m \"feat(cargo): updated to ${npm_package_version}\" || true) && cargo package && cargo publish"
},
"repository": {
"type": "git",
Expand Down
23 changes: 23 additions & 0 deletions platform/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions platform/rust/Cargo.toml
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
20 changes: 20 additions & 0 deletions platform/rust/examples/example.rs
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]"));
}
103 changes: 103 additions & 0 deletions platform/rust/src/lib.rs

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions platform/rust/src/lib.tmpl.rs
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 {}
10 changes: 10 additions & 0 deletions platform/rust/target/doc/mailchecker/blacklist.v.html
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>
Loading

0 comments on commit 625d483

Please sign in to comment.