Skip to content

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

fix(core): Add more invalid parsing and improve logging (#1156)

Amauryb5ae9f8ad910
diff --git a/core/src/lib.rs b/core/src/lib.rs
index dbc6bf39..757ba00e 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -77,6 +77,9 @@ pub use util::input_output::*;
/// Given an email's misc and smtp details, calculate an estimate of our
/// confidence on how reachable the email is.
+///
+/// Maybe we can switch to a points-based system?
+/// ref: https://github.com/reacherhq/check-if-email-exists/issues/935
fn calculate_reachable(misc: &MiscDetails, smtp: &Result<SmtpDetails, SmtpError>) -> Reachable {
if let Ok(smtp) = smtp {
if misc.is_disposable || misc.is_role_account || smtp.is_catch_all || smtp.has_full_inbox {
@@ -108,7 +111,7 @@ pub async fn check_email(input: &CheckEmailInput) -> CheckEmailOutput {
log::debug!(
target: LOG_TARGET,
- "email={} Checking email \"{}\"",
+ "[email={}] Checking email \"{}\"",
to_email,
to_email
);
@@ -124,7 +127,7 @@ pub async fn check_email(input: &CheckEmailInput) -> CheckEmailOutput {
log::debug!(
target: LOG_TARGET,
- "email={} Found the following syntax validation: {:?}",
+ "[email={}] Found the following syntax validation: {:?}",
to_email,
my_syntax
);
@@ -157,7 +160,7 @@ pub async fn check_email(input: &CheckEmailInput) -> CheckEmailOutput {
log::debug!(
target: LOG_TARGET,
- "email={} Found the following MX hosts: {:?}",
+ "[email={}] Found the following MX hosts: {:?}",
to_email,
my_mx
.lookup
@@ -171,7 +174,7 @@ pub async fn check_email(input: &CheckEmailInput) -> CheckEmailOutput {
let my_misc = check_misc(&my_syntax);
log::debug!(
target: LOG_TARGET,
- "email={} Found the following misc details: {:?}",
+ "[email={}] Found the following misc details: {:?}",
to_email,
my_misc
);
diff --git a/core/src/smtp/error.rs b/core/src/smtp/error.rs
index 735c7425..aed0cd62 100644
--- a/core/src/smtp/error.rs
+++ b/core/src/smtp/error.rs
@@ -59,7 +59,9 @@ impl From<YahooError> for SmtpError {
impl SmtpError {
/// Get a human-understandable description of the error, in form of an enum
- /// SmtpErrorDesc.
+ /// SmtpErrorDesc. This only parses the following known errors:
+ /// - IP blacklisted
+ /// - IP needs reverse DNS
pub fn get_description(&self) -> Option<SmtpErrorDesc> {
match self {
SmtpError::SmtpError(_) => {
diff --git a/core/src/smtp/mod.rs b/core/src/smtp/mod.rs
index 8d068201..879ed0fa 100644
--- a/core/src/smtp/mod.rs
+++ b/core/src/smtp/mod.rs
@@ -22,10 +22,7 @@ use super::util::{constants::LOG_TARGET, input_output::CheckEmailInput};
use async_native_tls::TlsConnector;
use async_recursion::async_recursion;
use async_smtp::{
- smtp::{
- commands::*, error::Error as AsyncSmtpError, extension::ClientId, ServerAddress,
- Socks5Config,
- },
+ smtp::{commands::*, extension::ClientId, ServerAddress, Socks5Config},
ClientTlsParameters, EmailAddress, SmtpClient, SmtpTransport,
};
use async_std::future;
@@ -58,7 +55,7 @@ pub struct SmtpDetails {
macro_rules! try_smtp (
($res: expr, $client: ident, $to_email: expr, $host: expr, $port: expr) => ({
if let Err(err) = $res {
- log::debug!(target: LOG_TARGET, "email={} Closing {}:{}, because of error '{:?}'.", $to_email, $host, $port, err);
+ log::debug!(target: LOG_TARGET, "[email={}] Closing [host={}:{}], because of error '{:?}'.", $to_email, $host, $port, err);
// Try to close the connection, but ignore if there's an error.
let _ = $client.close().await;
@@ -348,7 +345,7 @@ async fn retry(
) -> Result<SmtpDetails, SmtpError> {
log::debug!(
target: LOG_TARGET,
- "email={} Check SMTP attempt #{} on {}:{}",
+ "[email={}] Check SMTP [attempt={}] on [host={}:{}]",
input.to_email,
input.retries - count + 1,
host,
@@ -359,7 +356,7 @@ async fn retry(
log::debug!(
target: LOG_TARGET,
- "email={} Got result for attempt #{} on {}:{}, result={:?}",
+ "[email={}] Got result for [attempt={}] on [host={}:{}], [result={:?}]",
input.to_email,
input.retries - count + 1,
host,
@@ -367,17 +364,15 @@ async fn retry(
result
);
- match result {
- // Only retry if the error was a temporary/transient error, or a
- // timeout error.
- Err(SmtpError::SmtpError(AsyncSmtpError::Transient(_)))
- | Err(SmtpError::SmtpError(AsyncSmtpError::Timeout(_))) => {
+ match &result {
+ // Only retry if the error was unknown.
+ Err(err) if err.get_description().is_none() => {
if count <= 1 {
result
} else {
log::debug!(
target: LOG_TARGET,
- "email={} Potential greylisting detected, retrying.",
+ "[email={}] Potential greylisting detected, retrying.",
input.to_email,
);
retry(to_email, host, port, domain, input, count - 1).await
diff --git a/core/src/smtp/parser.rs b/core/src/smtp/parser.rs
index 040d05e5..e810bb10 100644
--- a/core/src/smtp/parser.rs
+++ b/core/src/smtp/parser.rs
@@ -44,6 +44,8 @@ pub fn is_invalid(e: &str) -> bool {
|| e.contains("recipient rejected")
// permanent: 5.1.1 Unknown recipient address
|| e.contains("unknown recipient address")
+ // 554 Unknown Recipient (#5.1.1) (on @parkwayhonda.com)
+ || e.contains("unknown recipient")
|| e.contains("undeliverable")
// 550 User unknown
// 550 5.1.1 <EMAIL> User unknown
@@ -69,6 +71,8 @@ pub fn is_invalid(e: &str) -> bool {
|| e.contains("no such mailbox")
// 550 Requested action not taken: mailbox unavailable
|| e.contains("mailbox unavailable")
+ // 5.5.0 Requested actions not taken as the mailbox is unavailable (on @etu.uca.fr)
+ || e.contains("mailbox is unavailable")
// 550 5.1.1 Is not a valid mailbox
|| e.contains("not a valid mailbox")
// No such recipient here
@@ -156,7 +160,7 @@ pub fn is_err_ip_blacklisted(e: &SmtpError) -> bool {
// Your access to this mail system has been rejected due to the sending MTA\'s poor reputation. If you believe that this failure is in error, please contact the intended recipient via alternate means.
first_line.contains("poor reputation") ||
// JunkMail rejected - (gmail.com) [193.218.118.140]:46615 is in an RBL: http://www.barracudanetworks.com/reputation/?pr=1&ip=193.218.118.140
- first_line.contains("junkmail")||
+ first_line.contains("junkmail") ||
// Transient errors
diff --git a/core/src/smtp/yahoo.rs b/core/src/smtp/yahoo.rs
index 53dee561..6dc7d094 100644
--- a/core/src/smtp/yahoo.rs
+++ b/core/src/smtp/yahoo.rs
@@ -110,7 +110,7 @@ fn create_client(input: &CheckEmailInput) -> Result<reqwest::Client, ReqwestErro
if let Some(proxy) = &input.proxy {
log::debug!(
target: LOG_TARGET,
- "email={} Using proxy socks://{}:{} for Yahoo API",
+ "[email={}] Using proxy socks://{}:{} for Yahoo API",
input.to_email,
proxy.host,
proxy.port
@@ -146,13 +146,13 @@ pub async fn check_yahoo(
let to_email = to_email.to_string();
log::debug!(
target: LOG_TARGET,
- "email={} Yahoo 1st response: {:?}",
+ "[email={}] Yahoo 1st response: {:?}",
to_email,
response
);
log::debug!(
target: LOG_TARGET,
- "email={} Yahoo cookies: {:?}",
+ "[email={}] Yahoo cookies: {:?}",
to_email,
cookies
);
@@ -203,7 +203,7 @@ pub async fn check_yahoo(
log::debug!(
target: LOG_TARGET,
- "email={} Yahoo 2nd response: {:?}",
+ "[email={}] Yahoo 2nd response: {:?}",
to_email,
response
);