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
refactor: Use async-std-resolver instead of tokio (#375)
Amaury Martinyc67603753fe8
diff --git a/Cargo.lock b/Cargo.lockindex 9a7cfc23..1332437b 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -110,6 +110,18 @@ dependencies = ["slab",]+[[package]]+name = "async-std-resolver"+version = "0.19.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d113439234775ae3e43d4e7589c5cc64fa3565996ae82dfe26b4ed78c02165be"+dependencies = [+ "async-std",+ "async-trait",+ "futures",+ "trust-dns-resolver",+]+[[package]]name = "async-task"version = "1.3.1"@@ -216,6 +228,7 @@ name = "check-if-email-exists"version = "0.8.5"dependencies = ["async-smtp",+ "async-std-resolver","fast-socks5","futures","log",@@ -223,7 +236,7 @@ dependencies = ["rand","serde","serde_json",- "trust-dns-resolver",+ "trust-dns-proto",][[package]]@@ -1469,7 +1482,6 @@ dependencies = ["resolv-conf","smallvec","thiserror",- "tokio","trust-dns-proto",]diff --git a/core/Cargo.toml b/core/Cargo.tomlindex 2ad75350..5ab46121 100644--- a/core/Cargo.toml+++ b/core/Cargo.toml@@ -18,11 +18,12 @@ travis-ci = { repository = "amaurymartiny/check-if-email-exists", service = "git[dependencies]async-smtp = { version = "0.3", features = ["socks5"] }+async-std-resolver = "0.19"fast-socks5 = "0.3"futures = "0.3"log = "0.4"mailchecker = "3.3"rand = "0.7"-trust-dns-resolver = "0.19"serde = { version = "1.0", features = ["derive"] }serde_json = "1.0"+trust-dns-proto = "0.19"diff --git a/core/src/mx.rs b/core/src/mx.rsindex 6c077a39..a36ac458 100644--- a/core/src/mx.rs+++ b/core/src/mx.rs@@ -16,9 +16,9 @@use crate::syntax::SyntaxDetails;use crate::util::ser_with_display::ser_with_display;+use async_std_resolver::{config, lookup::MxLookup, resolver, ResolveError};use serde::{ser::SerializeMap, Serialize, Serializer};use std::io::Error;-use trust_dns_resolver::{config::*, error::ResolveError, lookup::MxLookup, TokioAsyncResolver};/// Details about the MX lookup.#[derive(Debug)]@@ -85,8 +85,11 @@ impl From<ResolveError> for MxError {/// Make a MX lookup.pub async fn check_mx(syntax: &SyntaxDetails) -> Result<MxDetails, MxError> {// Construct a new Resolver with default configuration options- let resolver =- TokioAsyncResolver::tokio(ResolverConfig::default(), ResolverOpts::default()).await?;+ let resolver = resolver(+ config::ResolverConfig::default(),+ config::ResolverOpts::default(),+ )+ .await?;// Lookup the MX records associated with a name.// The final dot forces this to be an FQDN, otherwise the search rules as specifieddiff --git a/core/src/smtp.rs b/core/src/smtp/mod.rssimilarity index 99%rename from core/src/smtp.rsrename to core/src/smtp/mod.rsindex ad1315c5..eca4e869 100644--- a/core/src/smtp.rs+++ b/core/src/smtp/mod.rs@@ -14,6 +14,7 @@// You should have received a copy of the GNU Affero General Public License// along with this program. If not, see <https://www.gnu.org/licenses/>.+use super::util::{constants::LOG_TARGET, input_output::CheckEmailInputProxy};use crate::util::ser_with_display::ser_with_display;use async_smtp::{smtp::{@@ -29,9 +30,7 @@ use fast_socks5::{use rand::{distributions::Alphanumeric, Rng};use serde::Serialize;use std::time::Duration;-use trust_dns_resolver::Name;--use super::util::{constants::LOG_TARGET, input_output::CheckEmailInputProxy};+use trust_dns_proto::rr::Name;/// Details that we gathered from connecting to this email via SMTP#[derive(Debug, Serialize)]@@ -105,7 +104,7 @@ async fn connect_to_host(proxy: &Option<CheckEmailInputProxy>,) -> Result<SmtpTransport, SmtpError> {let mut smtp_client =- SmtpClient::with_security((host.to_utf8().as_str(), port), ClientSecurity::None)+ SmtpClient::with_security((host.to_utf8().as_ref(), port), ClientSecurity::None).await?.hello_name(ClientId::Domain(hello_name.into())).timeout(Some(Duration::new(30, 0))) // Set timeout to 30s