Skip to content

Check if an email address exists without sending any email, written in Rust. Comes with a ⚙️ HTTP backend.

fix: Bring back `{yahoo,hotmailb2c}_verif_method` (#1606)

Amaury3fbe5200a3d8
diff --git a/Cargo.lock b/Cargo.lock
index ffb02cad..fa17eff4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -601,7 +601,7 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
name = "check-if-email-exists"
-version = "0.11.5"
+version = "0.11.6"
dependencies = [
"anyhow",
"async-recursion",
@@ -633,7 +633,7 @@ dependencies = [
[[package]]
name = "check-if-email-exists-cli"
-version = "0.11.5"
+version = "0.11.6"
dependencies = [
"anyhow",
"check-if-email-exists",
@@ -3062,7 +3062,7 @@ dependencies = [
[[package]]
name = "reacher_backend"
-version = "0.11.5"
+version = "0.11.6"
dependencies = [
"anyhow",
"async-smtp",
@@ -3095,7 +3095,7 @@ dependencies = [
[[package]]
name = "reacher_sqs"
-version = "0.11.5"
+version = "0.11.6"
dependencies = [
"check-if-email-exists",
"lambda_runtime",
diff --git a/backend/Cargo.toml b/backend/Cargo.toml
index f94a4524..de3f636e 100644
--- a/backend/Cargo.toml
+++ b/backend/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "reacher_backend"
-version = "0.11.5"
+version = "0.11.6"
edition = "2018"
license = "AGPL-3.0"
publish = false
diff --git a/backend/openapi.json b/backend/openapi.json
index a4f76131..e7fbf051 100644
--- a/backend/openapi.json
+++ b/backend/openapi.json
@@ -2,7 +2,7 @@
"openapi": "3.0.0",
"info": {
"title": "Reacher",
- "version": "0.10.0",
+ "version": "0.11.0",
"description": "### What is Reacher?\n\nReacher is a robust, open-source email verification API service available as both a SaaS and self-hosted solution.",
"license": {
"name": "AGPL-3.0 OR Commercial",
@@ -409,8 +409,7 @@
"is_reachable": "invalid",
"misc": {
"is_disposable": false,
- "is_role_account": true,
- "is_b2c": true
+ "is_role_account": true
},
"mx": {
"accepts_mail": true,
@@ -641,7 +640,7 @@
"id": "cuc5bj6ra2t0i"
},
"title": "HotmailB2CVerifMethod",
- "enum": ["Smtp", "Headless", "Api"],
+ "enum": ["Smtp", "Headless"],
"description": "Enumeration describing the method used to verify Hotmail B2C emails."
},
"GmailVerifMethod": {
@@ -650,7 +649,7 @@
"id": "xo5r48yhtxiwr"
},
"title": "GmailVerifMethod",
- "enum": ["Api", "Smtp"],
+ "enum": ["Smtp"],
"description": "Enumeration describing the method used to verify Gmail emails.",
"x-internal": false
},
diff --git a/backend/src/config.rs b/backend/src/config.rs
index 98464090..1d7b98ae 100644
--- a/backend/src/config.rs
+++ b/backend/src/config.rs
@@ -22,7 +22,7 @@ use anyhow::{bail, Context};
use check_if_email_exists::smtp::verif_method::{
EverythingElseVerifMethod, GmailVerifMethod, HotmailB2BVerifMethod, HotmailB2CVerifMethod,
MimecastVerifMethod, ProofpointVerifMethod, VerifMethod, VerifMethodSmtpConfig,
- YahooVerifMethod,
+ YahooVerifMethod, DEFAULT_PROXY_ID,
};
use check_if_email_exists::{CheckEmailInputProxy, WebdriverConfig, LOG_TARGET};
use config::Config;
@@ -121,13 +121,13 @@ impl BackendConfig {
pub fn get_verif_method(&self) -> VerifMethod {
let mut proxies = self.overrides.proxies.clone();
if let Some(proxy) = self.proxy.as_ref() {
- proxies.insert("default".to_string(), proxy.clone());
+ proxies.insert(DEFAULT_PROXY_ID.to_string(), proxy.clone());
}
let default_smtp_config = VerifMethodSmtpConfig {
from_email: self.from_email.clone(),
hello_name: self.hello_name.clone(),
- proxy: self.proxy.as_ref().map(|_| "default".to_string()),
+ proxy: self.proxy.as_ref().map(|_| DEFAULT_PROXY_ID.to_string()),
smtp_timeout: self.smtp_timeout.map(Duration::from_secs),
..Default::default()
};
@@ -382,11 +382,19 @@ mod tests {
// Proxies
assert_eq!(cfg.get_verif_method().proxies.len(), 1);
assert_eq!(
- cfg.get_verif_method().proxies.get("default").unwrap().host,
+ cfg.get_verif_method()
+ .proxies
+ .get(DEFAULT_PROXY_ID)
+ .unwrap()
+ .host,
"test-default-proxy"
);
assert_eq!(
- cfg.get_verif_method().proxies.get("default").unwrap().port,
+ cfg.get_verif_method()
+ .proxies
+ .get(DEFAULT_PROXY_ID)
+ .unwrap()
+ .port,
5678
);
diff --git a/backend/src/http/v0/check_email/backwardcompat.rs b/backend/src/http/v0/check_email/backwardcompat.rs
new file mode 100644
index 00000000..fb6cf351
--- /dev/null
+++ b/backend/src/http/v0/check_email/backwardcompat.rs
@@ -0,0 +1,90 @@
+use std::time::Duration;
+
+use check_if_email_exists::smtp::verif_method::{
+ HotmailB2CVerifMethod, VerifMethodSmtpConfig, YahooVerifMethod, DEFAULT_PROXY_ID,
+};
+use serde::{Deserialize, Serialize};
+
+/// These types are for backward compatibility. The previous API allowed for
+/// - yahoo_verif_method: Smtp, Headless, Api
+/// - hotmailb2c_verif_method: Smtp, Headless
+/// - hotmailb2b_verif_method: Smtp
+/// - gmail_verif_method: Smtp
+///
+/// We keep these types for backward compatibility.
+
+#[derive(Debug, Default, Deserialize, Serialize)]
+pub enum BackwardCompatYahooVerifMethod {
+ Api,
+ #[default]
+ Headless,
+ Smtp,
+}
+
+impl BackwardCompatYahooVerifMethod {
+ pub fn to_yahoo_verif_method(
+ &self,
+ // If set, this will use the "default" proxy configuration.
+ use_default_proxy: bool,
+ hello_name: String,
+ from_email: String,
+ smtp_timeout: Option<Duration>,
+ smtp_port: u16,
+ retries: usize,
+ ) -> YahooVerifMethod {
+ match self {
+ BackwardCompatYahooVerifMethod::Api => YahooVerifMethod::Api,
+ BackwardCompatYahooVerifMethod::Headless => YahooVerifMethod::Headless,
+ BackwardCompatYahooVerifMethod::Smtp => YahooVerifMethod::Smtp(VerifMethodSmtpConfig {
+ from_email,
+ hello_name,
+ smtp_port,
+ smtp_timeout,
+ proxy: if use_default_proxy {
+ Some(DEFAULT_PROXY_ID.to_string())
+ } else {
+ None
+ },
+ retries,
+ }),
+ }
+ }
+}
+
+#[derive(Debug, Default, Deserialize, Serialize)]
+pub enum BackwardCompatHotmailB2CVerifMethod {
+ #[default]
+ Headless,
+ Smtp,
+}
+
+impl BackwardCompatHotmailB2CVerifMethod {
+ pub fn to_hotmailb2c_verif_method(
+ &self,
+ // If set, this will use the "default" proxy configuration.
+ use_default_proxy: bool,
+ hello_name: String,
+ from_email: String,
+ smtp_timeout: Option<Duration>,
+ smtp_port: u16,
+ retries: usize,
+ ) -> HotmailB2CVerifMethod {
+ match self {
+ BackwardCompatHotmailB2CVerifMethod::Headless => HotmailB2CVerifMethod::Headless,
+ BackwardCompatHotmailB2CVerifMethod::Smtp => {
+ HotmailB2CVerifMethod::Smtp(VerifMethodSmtpConfig {
+ from_email,
+ hello_name,
+ smtp_port,
+ smtp_timeout,
+ proxy: if use_default_proxy {
+ Some(DEFAULT_PROXY_ID.to_string())
+ } else {
+ None
+ },
+ retries,
+ })
+ }
+ }
+ }
+}
diff --git a/backend/src/http/v0/check_email/mod.rs b/backend/src/http/v0/check_email/mod.rs
index 9fbd6cb2..50a72573 100644
--- a/backend/src/http/v0/check_email/mod.rs
+++ b/backend/src/http/v0/check_email/mod.rs
@@ -14,4 +14,5 @@
// 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/>.
+mod backwardcompat;
pub mod post;
diff --git a/backend/src/http/v0/check_email/post.rs b/backend/src/http/v0/check_email/post.rs
index 3e18eb08..da06cb72 100644
--- a/backend/src/http/v0/check_email/post.rs
+++ b/backend/src/http/v0/check_email/post.rs
@@ -23,6 +23,7 @@ use std::sync::Arc;
use std::time::Duration;
use warp::{http, Filter};
+use super::backwardcompat::{BackwardCompatHotmailB2CVerifMethod, BackwardCompatYahooVerifMethod};
use crate::config::BackendConfig;
use crate::http::{check_header, ReacherResponseError};
@@ -35,34 +36,69 @@ pub struct CheckEmailRequest {
pub proxy: Option<CheckEmailInputProxy>,
pub smtp_timeout: Option<Duration>,
pub smtp_port: Option<u16>,
+ // The following fields are for backward compatibility.
+ pub yahoo_verif_method: Option<BackwardCompatYahooVerifMethod>,
+ pub hotmailb2c_verif_method: Option<BackwardCompatHotmailB2CVerifMethod>,
}
impl CheckEmailRequest {
pub fn to_check_email_input(&self, config: Arc<BackendConfig>) -> CheckEmailInput {
+ let hello_name = self
+ .hello_name
+ .clone()
+ .unwrap_or_else(|| config.hello_name.clone());
+ let from_email = self
+ .from_email
+ .clone()
+ .unwrap_or_else(|| config.from_email.clone());
+ let smtp_timeout = self
+ .smtp_timeout
+ .or_else(|| config.smtp_timeout.map(Duration::from_secs));
+ let smtp_port = self.smtp_port.unwrap_or(25);
+ let retries = 1;
+
// The current behavior is a bit complex. If the proxy field is present,
// we force use the proxy for all the verifications. If the proxy field is
// not present, we use the default configuration for all the verifications.
//
// If the proxy field is unset, but one of the other fields (from_email,
// hello_name, smtp_timeout, smtp_port) is set, we ignore those fields.
- let verif_method = if let Some(proxy) = &self.proxy {
+ let mut verif_method = if let Some(proxy) = &self.proxy {
VerifMethod::new_with_same_config_for_all(
Some(proxy.clone()),
- self.hello_name
- .clone()
- .unwrap_or_else(|| config.hello_name.clone()),
- self.from_email
- .clone()
- .unwrap_or_else(|| config.from_email.clone()),
- self.smtp_port.unwrap_or(25),
- self.smtp_timeout
- .or(config.smtp_timeout.map(Duration::from_secs)),
- 1,
+ hello_name.clone(),
+ from_email.clone(),
+ smtp_port,
+ smtp_timeout.clone(),
+ retries,
)
} else {
config.get_verif_method()
};
+ // Also support backward compatibility of the *_verif_method fields, which
+ // override the verif_method.
+ if let Some(yahoo_verif_method) = &self.yahoo_verif_method {
+ verif_method.yahoo = yahoo_verif_method.to_yahoo_verif_method(
+ self.proxy.is_some(),
+ hello_name.clone(),
+ from_email.clone(),
+ smtp_timeout.clone(),
+ smtp_port,
+ retries,
+ );
+ }
+ if let Some(hotmailb2c_verif_method) = &self.hotmailb2c_verif_method {
+ verif_method.hotmailb2c = hotmailb2c_verif_method.to_hotmailb2c_verif_method(
+ self.proxy.is_some(),
+ hello_name,
+ from_email,
+ smtp_timeout,
+ smtp_port,
+ retries,
+ );
+ }
+
CheckEmailInput {
to_email: self.to_email.clone(),
verif_method,
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index de89f5fd..cb7b8a09 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "check-if-email-exists-cli"
-version = "0.11.5"
+version = "0.11.6"
default-run = "check_if_email_exists"
edition = "2018"
description = "Check if an email address exists without sending any email."
diff --git a/core/Cargo.toml b/core/Cargo.toml
index b379fe41..1bac173b 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "check-if-email-exists"
-version = "0.11.5"
+version = "0.11.6"
authors = ["Amaury <[email protected]>"]
categories = ["email"]
description = "Check if an email address exists without sending any email"
diff --git a/core/src/smtp/verif_method.rs b/core/src/smtp/verif_method.rs
index afaedd17..2bbae638 100644
--- a/core/src/smtp/verif_method.rs
+++ b/core/src/smtp/verif_method.rs
@@ -67,6 +67,10 @@ impl EmailProvider {
}
type ProxyID = String;
+// This is a convention ID for the proxy in the top-level "proxy" field of the
+// request, which will be added as a key in the `proxies` map of the
+// `VerifMethod` struct.
+pub const DEFAULT_PROXY_ID: &str = "default";
/// The verification method to use for each email provider.
#[derive(Debug, Default, Clone, Deserialize, PartialEq, Serialize)]
@@ -104,8 +108,8 @@ impl VerifMethod {
retries: usize,
) -> Self {
let mut proxies = HashMap::new();
- let proxy_id = if let Some(proxy) = proxy {
- let proxy_id = "default".to_string();
+ let proxy_id: Option<String> = if let Some(proxy) = proxy {
+ let proxy_id = DEFAULT_PROXY_ID.to_string();
proxies.insert(proxy_id.clone(), proxy);
Some(proxy_id)
} else {
diff --git a/sqs/Cargo.toml b/sqs/Cargo.toml
index 49d800cf..1c02dc2e 100644
--- a/sqs/Cargo.toml
+++ b/sqs/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "reacher_sqs"
-version = "0.11.5"
+version = "0.11.6"
edition = "2018"
license = "AGPL-3.0"
publish = false