Check if an email address exists without sending any email, written in Rust. Comes with a ⚙️ HTTP backend.
Rust emailemail-validationemail-validation-apiemail-verificationemail-verification-apiemail-verifierhacktoberfest
Parallelize the tasks
Amaury Martiny62f9f3752bdf
diff --git a/Cargo.lock b/Cargo.lockindex 5f8e32bf..acd36ae6 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -103,6 +103,7 @@ dependencies = ["clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)","env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)","log 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",+ "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)","telnet 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)","trust-dns-resolver 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",]@@ -130,6 +131,15 @@ dependencies = ["bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",]+[[package]]+name = "crossbeam-deque"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+dependencies = [+ "crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",+]+[[package]]name = "crossbeam-deque"version = "0.6.1"@@ -139,6 +149,20 @@ dependencies = ["crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",]+[[package]]+name = "crossbeam-epoch"+version = "0.3.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+dependencies = [+ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",+ "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",+ "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",+ "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",+ "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",+ "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",+]+[[package]]name = "crossbeam-epoch"version = "0.5.2"@@ -152,6 +176,14 @@ dependencies = ["scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",]+[[package]]+name = "crossbeam-utils"+version = "0.2.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+dependencies = [+ "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",+]+[[package]]name = "crossbeam-utils"version = "0.5.0"@@ -166,6 +198,11 @@ dependencies = ["winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",]+[[package]]+name = "either"+version = "1.5.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+[[package]]name = "env_logger"version = "0.5.13"@@ -463,6 +500,27 @@ name = "rand_core"version = "0.2.1"source = "registry+https://github.com/rust-lang/crates.io-index"+[[package]]+name = "rayon"+version = "1.0.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+dependencies = [+ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",+ "either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",+ "rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)",+]++[[package]]+name = "rayon-core"+version = "1.4.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+dependencies = [+ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",+ "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",+ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",+ "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",+]+[[package]]name = "redox_syscall"version = "0.1.40"@@ -938,10 +996,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index""checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3""checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e""checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"+"checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3""checksum crossbeam-deque 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3486aefc4c0487b9cb52372c97df0a48b8c249514af1ee99703bf70d2f2ceda1"+"checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150""checksum crossbeam-epoch 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30fecfcac6abfef8771151f8be4abc9e4edc112c2bcb233314cafde2680536e9"+"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9""checksum crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "677d453a17e8bd2b913fa38e8b9cf04bcdbb5be790aa294f2389661d72036015""checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850"+"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0""checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38""checksum error-chain 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faa976b4fd2e4c2b2f3f486874b19e61944d3de3de8b61c9fcf835d583871bcc""checksum error-chain 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6930e04918388a9a2e41d518c25cf679ccafe26733fb4127dbf21993f2575d46"@@ -978,6 +1040,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index""checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd""checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c""checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2"+"checksum rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "373814f27745b2686b350dd261bfd24576a6fb0e2c5919b3a2b6005f820b0473"+"checksum rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b055d1e92aba6877574d8fe604a63c8b5df60f60e5982bf7ccbb1338ea527356""checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1""checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76""checksum regex 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "67d0301b0c6804eca7e3c275119d0b01ff3b7ab9258a65709e608a66312a1025"diff --git a/Cargo.toml b/Cargo.tomlindex 425057db..50cb6fd8 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -7,5 +7,6 @@ authors = ["Amaury Martiny <[email protected]>"]clap = {version = "2.32", features = ["yaml"]}env_logger = "0.5.13"log = "0.4"+rayon = "1.0.3"telnet = "0.1.2"trust-dns-resolver = "0.9.1"diff --git a/src/main.rs b/src/main.rsindex 0720c55b..57d30e57 100644--- a/src/main.rs+++ b/src/main.rs@@ -3,8 +3,10 @@ extern crate clap;extern crate env_logger;#[macro_use]extern crate log;+extern crate rayon;use clap::App;+use rayon::prelude::*;use std::process;mod mx_hosts;@@ -18,7 +20,7 @@ fn main() {let matches = App::from_yaml(yaml).get_matches();let from_email = matches.value_of("from").unwrap_or("[email protected]");- // Calling .unwrap() is safe here because "EMAIL" is required+ // Calling .unwrap() is safe here because "TO" is requiredlet to_email = matches.value_of("TO").unwrap();debug!("User inputted email {}", to_email);@@ -42,11 +44,11 @@ fn main() {combinations.push((host.exchange(), port))}}- for c in combinations {- let (domain, port) = c;- let found = telnet::connect(from_email, to_email, domain, port);- debug!("found? {}", found)- }- println!("false");+ let found = combinations+ .par_iter() // Parallelize the find_any+ .find_any(|(domain, port)| telnet::connect(from_email, to_email, domain, *port))+ .is_some();++ println!("{}", found);}diff --git a/src/telnet.rs b/src/telnet.rsindex 8aeb1485..a11a78dd 100644--- a/src/telnet.rs+++ b/src/telnet.rs@@ -21,7 +21,7 @@ pub fn connect(from: &str, to: &str, domain: &Name, port: u16) -> bool {let mut connection = match Telnet::connect((domain.to_utf8().as_str(), port), 256) {Ok(i) => i,Err(e) => {- debug!("Failed to connect, {}", e);+ debug!("On {}:{}, failed to connect, {}", domain, port, e);return false;}};@@ -45,7 +45,7 @@ pub fn connect(from: &str, to: &str, domain: &Name, port: u16) -> bool {_ => break,};- debug!("Received: {}", answer);+ debug!("On {}:{}, received: {}", domain, port, answer);// `question` is what we ask the serverlet mut question = match step {@@ -87,13 +87,13 @@ pub fn connect(from: &str, to: &str, domain: &Name, port: u16) -> bool {_ => panic!("Step is Found/NotFound where it shouldn't be."),};- debug!("Sent: {}", question);+ debug!("On {}:{}, sent: {}", domain, port, question);// Buffer to write to telnetquestion.push_str("\n");let write_buffer = question.as_bytes();if let Err(e) = connection.write(&write_buffer) {- debug!("Error while writing, {}", e);+ debug!("On {}:{}, error while writing, {}", domain, port, e);}}}