Skip to content

Commit 3fbe520

Browse files
authored
fix: Bring back {yahoo,hotmailb2c}_verif_method (#1606)
* fix: Bring back {yahoo,hotmailb2c}_verif_method * 0.11.6 * Update openapi
1 parent ae9042d commit 3fbe520

File tree

11 files changed

+169
-31
lines changed

11 files changed

+169
-31
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "reacher_backend"
3-
version = "0.11.5"
3+
version = "0.11.6"
44
edition = "2018"
55
license = "AGPL-3.0"
66
publish = false

backend/openapi.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"openapi": "3.0.0",
33
"info": {
44
"title": "Reacher",
5-
"version": "0.10.0",
5+
"version": "0.11.0",
66
"description": "### What is Reacher?\n\nReacher is a robust, open-source email verification API service available as both a SaaS and self-hosted solution.",
77
"license": {
88
"name": "AGPL-3.0 OR Commercial",
@@ -409,8 +409,7 @@
409409
"is_reachable": "invalid",
410410
"misc": {
411411
"is_disposable": false,
412-
"is_role_account": true,
413-
"is_b2c": true
412+
"is_role_account": true
414413
},
415414
"mx": {
416415
"accepts_mail": true,
@@ -641,7 +640,7 @@
641640
"id": "cuc5bj6ra2t0i"
642641
},
643642
"title": "HotmailB2CVerifMethod",
644-
"enum": ["Smtp", "Headless", "Api"],
643+
"enum": ["Smtp", "Headless"],
645644
"description": "Enumeration describing the method used to verify Hotmail B2C emails."
646645
},
647646
"GmailVerifMethod": {
@@ -650,7 +649,7 @@
650649
"id": "xo5r48yhtxiwr"
651650
},
652651
"title": "GmailVerifMethod",
653-
"enum": ["Api", "Smtp"],
652+
"enum": ["Smtp"],
654653
"description": "Enumeration describing the method used to verify Gmail emails.",
655654
"x-internal": false
656655
},

backend/src/config.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use anyhow::{bail, Context};
2222
use check_if_email_exists::smtp::verif_method::{
2323
EverythingElseVerifMethod, GmailVerifMethod, HotmailB2BVerifMethod, HotmailB2CVerifMethod,
2424
MimecastVerifMethod, ProofpointVerifMethod, VerifMethod, VerifMethodSmtpConfig,
25-
YahooVerifMethod,
25+
YahooVerifMethod, DEFAULT_PROXY_ID,
2626
};
2727
use check_if_email_exists::{CheckEmailInputProxy, WebdriverConfig, LOG_TARGET};
2828
use config::Config;
@@ -121,13 +121,13 @@ impl BackendConfig {
121121
pub fn get_verif_method(&self) -> VerifMethod {
122122
let mut proxies = self.overrides.proxies.clone();
123123
if let Some(proxy) = self.proxy.as_ref() {
124-
proxies.insert("default".to_string(), proxy.clone());
124+
proxies.insert(DEFAULT_PROXY_ID.to_string(), proxy.clone());
125125
}
126126

127127
let default_smtp_config = VerifMethodSmtpConfig {
128128
from_email: self.from_email.clone(),
129129
hello_name: self.hello_name.clone(),
130-
proxy: self.proxy.as_ref().map(|_| "default".to_string()),
130+
proxy: self.proxy.as_ref().map(|_| DEFAULT_PROXY_ID.to_string()),
131131
smtp_timeout: self.smtp_timeout.map(Duration::from_secs),
132132
..Default::default()
133133
};
@@ -382,11 +382,19 @@ mod tests {
382382
// Proxies
383383
assert_eq!(cfg.get_verif_method().proxies.len(), 1);
384384
assert_eq!(
385-
cfg.get_verif_method().proxies.get("default").unwrap().host,
385+
cfg.get_verif_method()
386+
.proxies
387+
.get(DEFAULT_PROXY_ID)
388+
.unwrap()
389+
.host,
386390
"test-default-proxy"
387391
);
388392
assert_eq!(
389-
cfg.get_verif_method().proxies.get("default").unwrap().port,
393+
cfg.get_verif_method()
394+
.proxies
395+
.get(DEFAULT_PROXY_ID)
396+
.unwrap()
397+
.port,
390398
5678
391399
);
392400

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
use std::time::Duration;
2+
3+
use check_if_email_exists::smtp::verif_method::{
4+
HotmailB2CVerifMethod, VerifMethodSmtpConfig, YahooVerifMethod, DEFAULT_PROXY_ID,
5+
};
6+
use serde::{Deserialize, Serialize};
7+
8+
/// These types are for backward compatibility. The previous API allowed for
9+
/// - yahoo_verif_method: Smtp, Headless, Api
10+
/// - hotmailb2c_verif_method: Smtp, Headless
11+
/// - hotmailb2b_verif_method: Smtp
12+
/// - gmail_verif_method: Smtp
13+
///
14+
/// We keep these types for backward compatibility.
15+
16+
#[derive(Debug, Default, Deserialize, Serialize)]
17+
pub enum BackwardCompatYahooVerifMethod {
18+
Api,
19+
#[default]
20+
Headless,
21+
Smtp,
22+
}
23+
24+
impl BackwardCompatYahooVerifMethod {
25+
pub fn to_yahoo_verif_method(
26+
&self,
27+
// If set, this will use the "default" proxy configuration.
28+
use_default_proxy: bool,
29+
hello_name: String,
30+
from_email: String,
31+
smtp_timeout: Option<Duration>,
32+
smtp_port: u16,
33+
retries: usize,
34+
) -> YahooVerifMethod {
35+
match self {
36+
BackwardCompatYahooVerifMethod::Api => YahooVerifMethod::Api,
37+
BackwardCompatYahooVerifMethod::Headless => YahooVerifMethod::Headless,
38+
BackwardCompatYahooVerifMethod::Smtp => YahooVerifMethod::Smtp(VerifMethodSmtpConfig {
39+
from_email,
40+
hello_name,
41+
smtp_port,
42+
smtp_timeout,
43+
proxy: if use_default_proxy {
44+
Some(DEFAULT_PROXY_ID.to_string())
45+
} else {
46+
None
47+
},
48+
retries,
49+
}),
50+
}
51+
}
52+
}
53+
54+
#[derive(Debug, Default, Deserialize, Serialize)]
55+
pub enum BackwardCompatHotmailB2CVerifMethod {
56+
#[default]
57+
Headless,
58+
Smtp,
59+
}
60+
61+
impl BackwardCompatHotmailB2CVerifMethod {
62+
pub fn to_hotmailb2c_verif_method(
63+
&self,
64+
// If set, this will use the "default" proxy configuration.
65+
use_default_proxy: bool,
66+
hello_name: String,
67+
from_email: String,
68+
smtp_timeout: Option<Duration>,
69+
smtp_port: u16,
70+
retries: usize,
71+
) -> HotmailB2CVerifMethod {
72+
match self {
73+
BackwardCompatHotmailB2CVerifMethod::Headless => HotmailB2CVerifMethod::Headless,
74+
BackwardCompatHotmailB2CVerifMethod::Smtp => {
75+
HotmailB2CVerifMethod::Smtp(VerifMethodSmtpConfig {
76+
from_email,
77+
hello_name,
78+
smtp_port,
79+
smtp_timeout,
80+
proxy: if use_default_proxy {
81+
Some(DEFAULT_PROXY_ID.to_string())
82+
} else {
83+
None
84+
},
85+
retries,
86+
})
87+
}
88+
}
89+
}
90+
}

backend/src/http/v0/check_email/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17+
mod backwardcompat;
1718
pub mod post;

backend/src/http/v0/check_email/post.rs

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::sync::Arc;
2323
use std::time::Duration;
2424
use warp::{http, Filter};
2525

26+
use super::backwardcompat::{BackwardCompatHotmailB2CVerifMethod, BackwardCompatYahooVerifMethod};
2627
use crate::config::BackendConfig;
2728
use crate::http::{check_header, ReacherResponseError};
2829

@@ -35,34 +36,69 @@ pub struct CheckEmailRequest {
3536
pub proxy: Option<CheckEmailInputProxy>,
3637
pub smtp_timeout: Option<Duration>,
3738
pub smtp_port: Option<u16>,
39+
// The following fields are for backward compatibility.
40+
pub yahoo_verif_method: Option<BackwardCompatYahooVerifMethod>,
41+
pub hotmailb2c_verif_method: Option<BackwardCompatHotmailB2CVerifMethod>,
3842
}
3943

4044
impl CheckEmailRequest {
4145
pub fn to_check_email_input(&self, config: Arc<BackendConfig>) -> CheckEmailInput {
46+
let hello_name = self
47+
.hello_name
48+
.clone()
49+
.unwrap_or_else(|| config.hello_name.clone());
50+
let from_email = self
51+
.from_email
52+
.clone()
53+
.unwrap_or_else(|| config.from_email.clone());
54+
let smtp_timeout = self
55+
.smtp_timeout
56+
.or_else(|| config.smtp_timeout.map(Duration::from_secs));
57+
let smtp_port = self.smtp_port.unwrap_or(25);
58+
let retries = 1;
59+
4260
// The current behavior is a bit complex. If the proxy field is present,
4361
// we force use the proxy for all the verifications. If the proxy field is
4462
// not present, we use the default configuration for all the verifications.
4563
//
4664
// If the proxy field is unset, but one of the other fields (from_email,
4765
// hello_name, smtp_timeout, smtp_port) is set, we ignore those fields.
48-
let verif_method = if let Some(proxy) = &self.proxy {
66+
let mut verif_method = if let Some(proxy) = &self.proxy {
4967
VerifMethod::new_with_same_config_for_all(
5068
Some(proxy.clone()),
51-
self.hello_name
52-
.clone()
53-
.unwrap_or_else(|| config.hello_name.clone()),
54-
self.from_email
55-
.clone()
56-
.unwrap_or_else(|| config.from_email.clone()),
57-
self.smtp_port.unwrap_or(25),
58-
self.smtp_timeout
59-
.or(config.smtp_timeout.map(Duration::from_secs)),
60-
1,
69+
hello_name.clone(),
70+
from_email.clone(),
71+
smtp_port,
72+
smtp_timeout.clone(),
73+
retries,
6174
)
6275
} else {
6376
config.get_verif_method()
6477
};
6578

79+
// Also support backward compatibility of the *_verif_method fields, which
80+
// override the verif_method.
81+
if let Some(yahoo_verif_method) = &self.yahoo_verif_method {
82+
verif_method.yahoo = yahoo_verif_method.to_yahoo_verif_method(
83+
self.proxy.is_some(),
84+
hello_name.clone(),
85+
from_email.clone(),
86+
smtp_timeout.clone(),
87+
smtp_port,
88+
retries,
89+
);
90+
}
91+
if let Some(hotmailb2c_verif_method) = &self.hotmailb2c_verif_method {
92+
verif_method.hotmailb2c = hotmailb2c_verif_method.to_hotmailb2c_verif_method(
93+
self.proxy.is_some(),
94+
hello_name,
95+
from_email,
96+
smtp_timeout,
97+
smtp_port,
98+
retries,
99+
);
100+
}
101+
66102
CheckEmailInput {
67103
to_email: self.to_email.clone(),
68104
verif_method,

cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "check-if-email-exists-cli"
3-
version = "0.11.5"
3+
version = "0.11.6"
44
default-run = "check_if_email_exists"
55
edition = "2018"
66
description = "Check if an email address exists without sending any email."

core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "check-if-email-exists"
3-
version = "0.11.5"
3+
version = "0.11.6"
44
authors = ["Amaury <[email protected]>"]
55
categories = ["email"]
66
description = "Check if an email address exists without sending any email"

core/src/smtp/verif_method.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ impl EmailProvider {
6767
}
6868

6969
type ProxyID = String;
70+
// This is a convention ID for the proxy in the top-level "proxy" field of the
71+
// request, which will be added as a key in the `proxies` map of the
72+
// `VerifMethod` struct.
73+
pub const DEFAULT_PROXY_ID: &str = "default";
7074

7175
/// The verification method to use for each email provider.
7276
#[derive(Debug, Default, Clone, Deserialize, PartialEq, Serialize)]
@@ -104,8 +108,8 @@ impl VerifMethod {
104108
retries: usize,
105109
) -> Self {
106110
let mut proxies = HashMap::new();
107-
let proxy_id = if let Some(proxy) = proxy {
108-
let proxy_id = "default".to_string();
111+
let proxy_id: Option<String> = if let Some(proxy) = proxy {
112+
let proxy_id = DEFAULT_PROXY_ID.to_string();
109113
proxies.insert(proxy_id.clone(), proxy);
110114
Some(proxy_id)
111115
} else {

0 commit comments

Comments
 (0)