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
fix: Revert back to using lowest-priority MX record (#1578)
Amaury60468b3f5334
diff --git a/backend/src/config.rs b/backend/src/config.rsindex 92de5810..98464090 100644--- a/backend/src/config.rs+++ b/backend/src/config.rs@@ -148,7 +148,7 @@ impl BackendConfig {.overrides.hotmailb2c.clone()- .unwrap_or_else(|| HotmailB2CVerifMethod::Headless),+ .unwrap_or(HotmailB2CVerifMethod::Headless),mimecast: self.overrides.mimecast@@ -163,7 +163,7 @@ impl BackendConfig {.overrides.yahoo.clone()- .unwrap_or_else(|| YahooVerifMethod::Headless),+ .unwrap_or(YahooVerifMethod::Headless),everything_else: EverythingElseVerifMethod::Smtp(default_smtp_config),}}diff --git a/core/src/lib.rs b/core/src/lib.rsindex 8772dc8b..2093758f 100644--- a/core/src/lib.rs+++ b/core/src/lib.rs@@ -52,13 +52,13 @@//! password: None//! });//! let verif_method = VerifMethod {-//! proxies,+//! proxies,//! gmail: GmailVerifMethod::Smtp(VerifMethodSmtpConfig {//! from_email: "[email protected]".to_string(), // Used in the `MAIL FROM:` command//! hello_name: "example.org".to_string(), // Used in the `EHLO` command//! smtp_port: 587, // Use port 587 instead of 25//! proxy: Some("proxy1".to_string()), // Use the proxy we defined above-//! ..Default::default()+//! ..Default::default()//! }),//! ..Default::default()//! };@@ -86,10 +86,8 @@ pub mod smtp;pub mod syntax;mod util;-use hickory_proto::rr::rdata::MX;use misc::{check_misc, MiscDetails};use mx::check_mx;-use rand::Rng;use rustls::crypto::ring;use smtp::{check_smtp, SmtpDetails, SmtpError};pub use smtp::{is_gmail, is_hotmail, is_hotmail_b2b, is_hotmail_b2c, is_yahoo};@@ -100,8 +98,6 @@ pub use util::input_output::*;#[cfg(feature = "sentry")]pub use util::sentry::*;-use crate::rules::{has_rule, Rule};-/// The target where to log check-if-email-exists logs.pub const LOG_TARGET: &str = "reacher";@@ -232,38 +228,15 @@ pub async fn check_email(input: &CheckEmailInput) -> CheckEmailOutput {"Found misc details");- // From the list of MX records, we only choose one: we don't choose the- // first or last ones, because some domains put dummy MX records at the- // beginning or end of the list (sorted by priority). Instead, we choose a- // random one in the middle of the list.- //- // See here for explanation: https://cwiki.apache.org/confluence/display/SPAMASSASSIN/OtherTricks- //- // If anyone has a better algorithm, let me know by creating an issue on- // Github.- // ref: https://github.com/reacherhq/check-if-email-exists/issues/1049- let mut mx_records = my_mx+ // From the list of MX records, we choose the one with the lowest priority.+ let mx_records = my_mx.lookup.as_ref().expect("If lookup is error, we already returned. qed.").iter()- // Don't try to connect to honey pot servers.- .filter(|a| {- !has_rule(- &my_syntax.domain,- &a.exchange().to_string(),- &Rule::HoneyPot,- )- })- .collect::<Vec<&MX>>();- mx_records.sort_by_key(|a| a.preference());- let host = if mx_records.len() >= 3 {- let mut rng = rand::thread_rng();- let index = rng.gen_range(1..mx_records.len() - 1);- mx_records[index]- } else {- mx_records[mx_records.len() - 1]- };+ .min_by_key(|a| a.preference())+ .expect("There should be at least one MX record after filtering.");+ let host = mx_records;let (my_smtp, smtp_debug) = check_smtp(my_syntaxdiff --git a/core/src/rules.json b/core/src/rules.jsonindex 89150b6d..cef81d38 100644--- a/core/src/rules.json+++ b/core/src/rules.json@@ -8,7 +8,6 @@"yahoo.fr": { "rules": ["SkipCatchAll"] }},"by_mx": {- "filter30.antispamcloud.com.": { "rules": ["HoneyPot"] },"futuresinitiative.org.": { "rules": ["SmtpTimeout45s"] },"mail.digimarcon.com.": { "rules": ["SmtpTimeout45s"] },"mail.glasasoftball.org.": { "rules": ["SmtpTimeout45s"] },diff --git a/core/src/rules.rs b/core/src/rules.rsindex 88d76b4e..41fe8fc2 100644--- a/core/src/rules.rs+++ b/core/src/rules.rs@@ -30,8 +30,6 @@ pub enum Rule {SkipCatchAll,/// Set the SMTP timeout to 45s.SmtpTimeout45s,- /// Honey pot.- HoneyPot,}#[derive(Debug, Deserialize, Serialize)]diff --git a/sqs/Makefile b/sqs/Makefilenew file mode 100644index 00000000..d8455fc5--- /dev/null+++ b/sqs/Makefile@@ -0,0 +1,5 @@+TAG = beta++.PHONY: docker_deploy+docker_deploy:+ cd .. && docker buildx build --platform linux/amd64 -t 430118836964.dkr.ecr.eu-west-3.amazonaws.com/reacherhq/sqs:$(TAG) -f sqs/Dockerfile .diff --git a/sqs/README.md b/sqs/README.mdindex 98d24ad9..55849a33 100644--- a/sqs/README.md+++ b/sqs/README.md@@ -3,5 +3,5 @@## Build Docker```bash-docker buildx build --platform linux/amd64 -t 430118836964.dkr.ecr.eu-west-3.amazonaws.com/reacherhq/sqs:$TAG -f sqs/Dockerfile .+make docker_deploy```