diff --git a/core/src/smtp/gmail.rs b/core/src/smtp/gmail.rs
index 5980a39c61..95aab253cd 100644
--- a/core/src/smtp/gmail.rs
+++ b/core/src/smtp/gmail.rs
@@ -15,8 +15,11 @@
// along with this program. If not, see .
use super::SmtpDetails;
-use crate::util::{
- constants::LOG_TARGET, input_output::CheckEmailInput, ser_with_display::ser_with_display,
+use crate::{
+ smtp::http_api::create_client,
+ util::{
+ constants::LOG_TARGET, input_output::CheckEmailInput, ser_with_display::ser_with_display,
+ },
};
use async_smtp::EmailAddress;
use reqwest::Error as ReqwestError;
@@ -45,31 +48,13 @@ impl From for GmailError {
}
}
-/// Helper function to create a reqwest client, with optional proxy.
-fn create_client(input: &CheckEmailInput) -> Result {
- if let Some(proxy) = &input.proxy {
- log::debug!(
- target: LOG_TARGET,
- "[email={}] Using proxy socks://{}:{} for gmail API",
- input.to_email,
- proxy.host,
- proxy.port
- );
-
- let proxy = reqwest::Proxy::all(&format!("socks5://{}:{}", proxy.host, proxy.port))?;
- reqwest::Client::builder().proxy(proxy).build()
- } else {
- Ok(reqwest::Client::new())
- }
-}
-
/// Use HTTP request to verify if a Gmail email address exists.
/// See:
pub async fn check_gmail(
to_email: &EmailAddress,
input: &CheckEmailInput,
) -> Result {
- let response = create_client(input)?
+ let response = create_client(input, "gmail")?
.head(GLXU_PAGE)
.query(&[("email", to_email)])
.send()
diff --git a/core/src/smtp/http_api.rs b/core/src/smtp/http_api.rs
new file mode 100644
index 0000000000..05341a467d
--- /dev/null
+++ b/core/src/smtp/http_api.rs
@@ -0,0 +1,40 @@
+// check-if-email-exists
+// Copyright (C) 2018-2022 Reacher
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published
+// by the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+
+use crate::util::{constants::LOG_TARGET, input_output::CheckEmailInput};
+use reqwest::Error as ReqwestError;
+
+/// Helper function to create a reqwest client, with optional proxy.
+pub fn create_client(
+ input: &CheckEmailInput,
+ api_name: &str,
+) -> Result {
+ if let Some(proxy) = &input.proxy {
+ log::debug!(
+ target: LOG_TARGET,
+ "[email={}] Using proxy socks://{}:{} for {} API",
+ input.to_email,
+ proxy.host,
+ proxy.port,
+ api_name,
+ );
+
+ let proxy = reqwest::Proxy::all(&format!("socks5://{}:{}", proxy.host, proxy.port))?;
+ reqwest::Client::builder().proxy(proxy).build()
+ } else {
+ Ok(reqwest::Client::new())
+ }
+}
diff --git a/core/src/smtp/mod.rs b/core/src/smtp/mod.rs
index 2f973beeca..2672e7af3e 100644
--- a/core/src/smtp/mod.rs
+++ b/core/src/smtp/mod.rs
@@ -19,6 +19,7 @@ mod error;
mod gmail;
#[cfg(feature = "headless")]
mod hotmail;
+mod http_api;
mod parser;
mod yahoo;
diff --git a/core/src/smtp/yahoo.rs b/core/src/smtp/yahoo.rs
index 6dc7d09482..3bc8cd0f02 100644
--- a/core/src/smtp/yahoo.rs
+++ b/core/src/smtp/yahoo.rs
@@ -15,8 +15,11 @@
// along with this program. If not, see .
use super::SmtpDetails;
-use crate::util::{
- constants::LOG_TARGET, input_output::CheckEmailInput, ser_with_display::ser_with_display,
+use crate::{
+ smtp::http_api::create_client,
+ util::{
+ constants::LOG_TARGET, input_output::CheckEmailInput, ser_with_display::ser_with_display,
+ },
};
use async_smtp::EmailAddress;
use regex::Regex;
@@ -105,31 +108,13 @@ impl From for YahooError {
}
}
-/// Helper function to create a reqwest client, with optional proxy.
-fn create_client(input: &CheckEmailInput) -> Result {
- if let Some(proxy) = &input.proxy {
- log::debug!(
- target: LOG_TARGET,
- "[email={}] Using proxy socks://{}:{} for Yahoo API",
- input.to_email,
- proxy.host,
- proxy.port
- );
-
- let proxy = reqwest::Proxy::all(&format!("socks5://{}:{}", proxy.host, proxy.port))?;
- reqwest::Client::builder().proxy(proxy).build()
- } else {
- Ok(reqwest::Client::new())
- }
-}
-
/// Use well-crafted HTTP requests to verify if a Yahoo email address exists.
/// Inspired by https://github.com/hbattat/verifyEmail.
pub async fn check_yahoo(
to_email: &EmailAddress,
input: &CheckEmailInput,
) -> Result {
- let response = create_client(input)?
+ let response = create_client(input, "yahoo")?
.get(SIGNUP_PAGE)
.header("User-Agent", USER_AGENT)
.send()
@@ -178,7 +163,7 @@ pub async fn check_yahoo(
};
// Mimic a real HTTP request.
- let response = create_client(input)?
+ let response = create_client(input, "yahoo")?
.post(SIGNUP_API)
.header("Origin", "https://login.yahoo.com")
.header("X-Requested-With", "XMLHttpRequest")