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
feat: Add `smtp.error.description` field for human-readable description of error (#1111)
Amaury43b47ea2b925
diff --git a/Cargo.lock b/Cargo.lockindex 8036b885..2a8c69b2 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -318,7 +318,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"[[package]]name = "check-if-email-exists"-version = "0.8.29"+version = "0.8.30"dependencies = ["async-native-tls","async-recursion",@@ -340,7 +340,7 @@ dependencies = [[[package]]name = "check-if-email-exists-cli"-version = "0.8.29"+version = "0.8.30"dependencies = ["check-if-email-exists","clap",@@ -1103,9 +1103,9 @@ checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a"[[package]]name = "openssl-src"-version = "111.18.0+1.1.1n"+version = "111.20.0+1.1.1o"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "7897a926e1e8d00219127dc020130eca4292e5ca666dd592480d72c3eca2ff6c"+checksum = "92892c4f87d56e376e469ace79f1128fdaded07646ddf73aa0be4706ff712dec"dependencies = ["cc",]@@ -1250,11 +1250,11 @@ dependencies = [[[package]]name = "proc-macro2"-version = "1.0.38"+version = "1.0.39"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "9027b48e9d4c9175fa2218adf3557f91c1137021739951d4932f5f8268ac48aa"+checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f"dependencies = [- "unicode-xid",+ "unicode-ident",][[package]]@@ -1538,13 +1538,13 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"[[package]]name = "syn"-version = "1.0.93"+version = "1.0.95"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "04066589568b72ec65f42d65a1a52436e954b168773148893c020269563decf2"+checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942"dependencies = ["proc-macro2","quote",- "unicode-xid",+ "unicode-ident",][[package]]@@ -1762,6 +1762,12 @@ dependencies = ["matches",]+[[package]]+name = "unicode-ident"+version = "1.0.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"+[[package]]name = "unicode-normalization"version = "0.1.19"@@ -1783,12 +1789,6 @@ version = "0.1.8"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"-[[package]]-name = "unicode-xid"-version = "0.2.2"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"-[[package]]name = "url"version = "2.2.2"diff --git a/Cargo.toml b/Cargo.tomlindex 74ca476d..6e85fbb7 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -1,6 +1,6 @@[package]name = "check-if-email-exists-cli"-version = "0.8.29"+version = "0.8.30"default-run = "check_if_email_exists"edition = "2018"description = "Check if an email address exists without sending any email."diff --git a/Dockerfile b/Dockerfileindex 851c38b9..42aa7f87 100644--- a/Dockerfile+++ b/Dockerfile@@ -8,7 +8,7 @@ FROM alpine# `ciee` stands for check-if-email-existsWORKDIR /ciee# Fetch latest version-ENV CIEE_VERSION 0.8.29+ENV CIEE_VERSION 0.8.30# Install needed librariesRUN apk update && \diff --git a/README.md b/README.mdindex 12cd6745..589448de 100644--- a/README.md+++ b/README.md@@ -88,7 +88,7 @@ Head to the [releases page](https://github.com/reacherhq/check-if-email-exists/r```> $ check_if_email_exists --help-check_if_email_exists 0.8.29+check_if_email_exists 0.8.30Check if an email address exists without sending an email.USAGE:diff --git a/core/Cargo.toml b/core/Cargo.tomlindex 22df006c..36ad94ff 100644--- a/core/Cargo.toml+++ b/core/Cargo.toml@@ -1,6 +1,6 @@[package]name = "check-if-email-exists"-version = "0.8.29"+version = "0.8.30"authors = ["Amaury <[email protected]>"]categories = ["email"]description = "Check if an email address exists without sending any email"diff --git a/core/src/smtp/error.rs b/core/src/smtp/error.rsnew file mode 100644index 00000000..50244c1b--- /dev/null+++ b/core/src/smtp/error.rs@@ -0,0 +1,87 @@+// 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 <https://www.gnu.org/licenses/>.++use super::parser;+use super::yahoo::YahooError;+use crate::util::ser_with_display::ser_with_display;+use async_smtp::smtp::error::Error as AsyncSmtpError;+use async_std::future;+use fast_socks5::SocksError;+use serde::Serialize;++/// Error occured connecting to this email server via SMTP.+#[derive(Debug, Serialize)]+#[serde(tag = "type", content = "message")]+pub enum SmtpError {+ /// Error if we're using a SOCKS5 proxy.+ #[serde(serialize_with = "ser_with_display")]+ SocksError(SocksError),+ /// Error when communicating with SMTP server.+ #[serde(serialize_with = "ser_with_display")]+ SmtpError(AsyncSmtpError),+ /// Time-out error.+ #[serde(serialize_with = "ser_with_display")]+ TimeoutError(future::TimeoutError),+ /// Error when verifying a Yahoo email.+ YahooError(YahooError),+}++impl From<SocksError> for SmtpError {+ fn from(e: SocksError) -> Self {+ SmtpError::SocksError(e)+ }+}++impl From<future::TimeoutError> for SmtpError {+ fn from(e: future::TimeoutError) -> Self {+ SmtpError::TimeoutError(e)+ }+}++impl From<YahooError> for SmtpError {+ fn from(e: YahooError) -> Self {+ SmtpError::YahooError(e)+ }+}++impl SmtpError {+ /// Get a human-understandable description of the error, in form of an enum+ /// SmtpErrorDesc.+ pub fn get_description(&self) -> Option<SmtpErrorDesc> {+ match self {+ SmtpError::SmtpError(_) => {+ if parser::is_err_ip_blacklisted(self) {+ Some(SmtpErrorDesc::IpBlacklisted)+ } else if parser::is_err_needs_rdns(self) {+ Some(SmtpErrorDesc::NeedsRDNS)+ } else {+ None+ }+ }+ _ => None,+ }+ }+}++#[derive(Debug, Serialize)]+/// SmtpErrorDesc describes a description of which category the error belongs+/// to.+pub enum SmtpErrorDesc {+ /// The IP is blacklisted.+ IpBlacklisted,+ /// The IP needs a reverse DNS entry.+ NeedsRDNS,+}diff --git a/core/src/smtp/mod.rs b/core/src/smtp/mod.rsindex 1481763f..c2e04366 100644--- a/core/src/smtp/mod.rs+++ b/core/src/smtp/mod.rs@@ -14,10 +14,11 @@// 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/>.+pub mod error;+mod parser;mod yahoo;use super::util::{constants::LOG_TARGET, input_output::CheckEmailInput};-use crate::util::ser_with_display::ser_with_display;use async_native_tls::TlsConnector;use async_recursion::async_recursion;use async_smtp::{@@ -28,9 +29,10 @@ use async_smtp::{ClientTlsParameters, EmailAddress, SmtpClient, SmtpTransport,};use async_std::future;+pub use error::*;use fast_socks5::{client::{Config, Socks5Stream},- Result, SocksError,+ Result,};use rand::rngs::SmallRng;use rand::{distributions::Alphanumeric, Rng, SeedableRng};@@ -40,7 +42,6 @@ use std::iter;use std::str::FromStr;use std::time::Duration;use trust_dns_proto::rr::Name;-use yahoo::YahooError;/// Details that we gathered from connecting to this email via SMTP#[derive(Debug, Default, Deserialize, Serialize)]@@ -57,41 +58,6 @@ pub struct SmtpDetails {pub is_disabled: bool,}-/// Error occured connecting to this email server via SMTP.-#[derive(Debug, Serialize)]-#[serde(tag = "type", content = "message")]-pub enum SmtpError {- /// Error if we're using a SOCKS5 proxy.- #[serde(serialize_with = "ser_with_display")]- SocksError(SocksError),- /// Error when communicating with SMTP server.- #[serde(serialize_with = "ser_with_display")]- SmtpError(AsyncSmtpError),- /// Time-out error.- #[serde(serialize_with = "ser_with_display")]- TimeoutError(future::TimeoutError),- /// Error when verifying a Yahoo email.- YahooError(YahooError),-}--impl From<SocksError> for SmtpError {- fn from(error: SocksError) -> Self {- SmtpError::SocksError(error)- }-}--impl From<future::TimeoutError> for SmtpError {- fn from(error: future::TimeoutError) -> Self {- SmtpError::TimeoutError(error)- }-}--impl From<YahooError> for SmtpError {- fn from(error: YahooError) -> Self {- SmtpError::YahooError(error)- }-}-/// Try to send an smtp command, close and return Err if fails.macro_rules! try_smtp (($res: expr, $client: ident, $to_email: expr, $host: expr, $port: expr) => ({@@ -242,11 +208,7 @@ async fn email_deliverable(let err_string = err.to_string().to_lowercase();// Check if the email account has been disabled or blocked.- // 554 The email account that you tried to reach is disabled. Learn more at https://support.google.com/mail/?p=DisabledUser"- if err_string.contains("disabled")- // 554 delivery error: Sorry your message to [email] cannot be delivered. This account has been disabled or discontinued- || err_string.contains("discontinued")- {+ if parser::is_disabled_account(err_string.as_str()) {return Ok(Deliverability {has_full_inbox: false,is_deliverable: false,@@ -255,11 +217,7 @@ async fn email_deliverable(}// Check if the email account has a full inbox.- if err_string.contains("insufficient")- || err_string.contains("over quota")- // 550 user has too many messages on the server- || err_string.contains("too many messages")- {+ if parser::is_full_inbox(err_string.as_str()) {return Ok(Deliverability {has_full_inbox: true,is_deliverable: false,@@ -280,59 +238,8 @@ async fn email_deliverable(});}- // These are the possible error messages when email account doesn't exist.- // 550 Address rejected- // 550 5.1.1 : Recipient address rejected- // 550 5.1.1 : Recipient address rejected: User unknown in virtual alias table- // 550 5.1.1 <[email protected]>: Recipient address rejected: User unknown in relay recipient table- if err_string.contains("address rejected")- // 550 5.1.1 : Unrouteable address- || err_string.contains("unrouteable")- // 550 5.1.1 : The email account that you tried to reach does not exist- || err_string.contains("does not exist")- // 550 invalid address- // 550 User not local or invalid address – Relay denied- || err_string.contains("invalid address")- // 5.1.1 Invalid email address- || err_string.contains("invalid email address")- // 550 Invalid recipient- || err_string.contains("invalid recipient")- || err_string.contains("may not exist")- || err_string.contains("recipient invalid")- // 550 5.1.1 : Recipient rejected- || err_string.contains("recipient rejected")- || err_string.contains("undeliverable")- // 550 User unknown- // 550 5.1.1 <EMAIL> User unknown- // 550 recipient address rejected: user unknown in local recipient table- || err_string.contains("user unknown")- // 550 Unknown user- || err_string.contains("unknown user")- // 5.1.1 Recipient unknown <EMAIL>- || err_string.contains("recipient unknown")- // 550 5.1.1 No such user - pp- // 550 No such user here- || err_string.contains("no such user")- // 550 5.1.1 : Mailbox not found- // 550 Unknown address error ‘MAILBOX NOT FOUND’- || err_string.contains("not found")- // 550 5.1.1 : Invalid mailbox- || err_string.contains("invalid mailbox")- // 550 5.1.1 Sorry, no mailbox here by that name- || err_string.contains("no mailbox")- // 5.2.0 No such mailbox- || err_string.contains("no such mailbox")- // 550 Requested action not taken: mailbox unavailable- || err_string.contains("mailbox unavailable")- // 550 5.1.1 Is not a valid mailbox- || err_string.contains("not a valid mailbox")- // No such recipient here- || err_string.contains("no such recipient")- // 554 delivery error: This user doesn’t have an account- || err_string.contains("have an account")- // 5.1.1 RCP-P1 Domain facebook.com no longer available https://www.facebook.com/postmaster/response_codes?ip=3.80.111.155#RCP-P1- || err_string.contains("no longer available")- {+ // Check that the mailbox doesn't exist.+ if parser::is_invalid(err_string.as_str()) {return Ok(Deliverability {has_full_inbox: false,is_deliverable: false,@@ -340,6 +247,7 @@ async fn email_deliverable(});}+ // Return all unparsable errors,.Err(SmtpError::SmtpError(err))}}@@ -396,15 +304,17 @@ async fn create_smtp_future(// Unfortunately `smtp_transport.is_connected()` doesn't report about this,// so we can only check for "io: incomplete" SMTP error being returned.// https://github.com/async-email/async-smtp/issues/37- if is_io_incomplete_smtp_error(&result) {- log::debug!(- target: LOG_TARGET,- "Got `io: incomplete` error, reconnecting."- );-- let _ = smtp_transport.close().await;- smtp_transport = connect_to_host(host, port, input).await?;- result = email_deliverable(&mut smtp_transport, to_email).await;+ if let Err(e) = &result {+ if parser::is_err_io_errors(e) {+ log::debug!(+ target: LOG_TARGET,+ "Got `io: incomplete` error, reconnecting."+ );++ let _ = smtp_transport.close().await;+ smtp_transport = connect_to_host(host, port, input).await?;+ result = email_deliverable(&mut smtp_transport, to_email).await;+ }}result?@@ -415,17 +325,6 @@ async fn create_smtp_future(Ok((is_catch_all, deliverability))}-/// Indicates whether the given [`Result`] represents an `io: incomplete`-/// [`SmtpError::Error`].-fn is_io_incomplete_smtp_error<T>(result: &Result<T, SmtpError>) -> bool {- match result {- Err(SmtpError::SmtpError(AsyncSmtpError::Io(err))) => {- err.to_string().as_str() == "incomplete"- }- _ => false,- }-}-/// Get all email details we can from one single `EmailAddress`, without/// retries.async fn check_smtp_without_retry(diff --git a/core/src/smtp/parser.rs b/core/src/smtp/parser.rsnew file mode 100644index 00000000..30bddb3c--- /dev/null+++ b/core/src/smtp/parser.rs@@ -0,0 +1,191 @@+// Reacher - Email Verification+// 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 <https://www.gnu.org/licenses/>.++//! Parse the SMTP responses to get information about the email address.++use super::error::SmtpError;+use async_smtp::smtp::error::Error as AsyncSmtpError;++/// is_invalid checks for SMTP responses meaning that the email is invalid,+/// i.e. that the mailbox doesn;t exist.+pub fn is_invalid(e: &str) -> bool {+ // 550 Address rejected+ // 550 5.1.1 : Recipient address rejected+ // 550 5.1.1 : Recipient address rejected: User unknown in virtual alias table+ // 550 5.1.1 <[email protected]>: Recipient address rejected: User unknown in relay recipient table+ e.contains("address rejected")+ // 550 5.1.1 : Unrouteable address+ || e.contains("unrouteable")+ // 550 5.1.1 : The email account that you tried to reach does not exist+ || e.contains("does not exist")+ // 550 invalid address+ // 550 User not local or invalid address – Relay denied+ || e.contains("invalid address")+ // 5.1.1 Invalid email address+ || e.contains("invalid email address")+ // 550 Invalid recipient+ || e.contains("invalid recipient")+ || e.contains("may not exist")+ || e.contains("recipient invalid")+ // 550 5.1.1 : Recipient rejected+ || e.contains("recipient rejected")+ // permanent: 5.1.1 Unknown recipient address+ || e.contains("unknown recipient address")+ || e.contains("undeliverable")+ // 550 User unknown+ // 550 5.1.1 <EMAIL> User unknown+ // 550 recipient address rejected: user unknown in local recipient table+ || e.contains("user unknown")+ // 550 Unknown user+ || e.contains("unknown user")+ // 5.1.1 Recipient unknown <EMAIL>+ || e.contains("recipient unknown")+ // 550 5.1.1 No such user - pp+ // 550 No such user here+ || e.contains("no such user")+ // permanent: 5.1.1 MXIN501 mailbox <EMAIL> unknown (on @virginmedia.com)+ || e.contains("")+ // 550 5.1.1 : Mailbox not found+ // 550 Unknown address error ‘MAILBOX NOT FOUND’+ || e.contains("mailbox not found")+ // 550 5.1.1 : Invalid mailbox+ || e.contains("invalid mailbox")+ // 550 5.1.1 Sorry, no mailbox here by that name+ || e.contains("no mailbox")+ // 5.2.0 No such mailbox+ || e.contains("no such mailbox")+ // 550 Requested action not taken: mailbox unavailable+ || e.contains("mailbox unavailable")+ // 550 5.1.1 Is not a valid mailbox+ || e.contains("not a valid mailbox")+ // No such recipient here+ || e.contains("no such recipient")+ // 554 delivery error: This user doesn’t have an account+ || e.contains("have an account")+ // permanent: Unknown local part <USER> in <[email protected]> (on @flabeg.com)+ || e.contains("unknown local part")+ // 5.1.1 RCP-P1 Domain facebook.com no longer available https://www.facebook.com/postmaster/response_codes?ip=3.80.111.155#RCP-P1+ || e.contains("no longer available")+}++/// Check that the mailbox has a full inbox.+pub fn is_full_inbox(e: &str) -> bool {+ e.contains("insufficient")+ // https://answers.microsoft.com/en-us/outlook_com/forum/all/how-do-i-interpret-the-delivery-failure-message/2f1bf9c0-8b03-4f8f-aacc-5f6ba60a73f3+ || e.contains("mailbox full")+ // https://answers.microsoft.com/en-us/outlook_com/forum/all/how-do-i-interpret-the-delivery-failure-message/2f1bf9c0-8b03-4f8f-aacc-5f6ba60a73f3+ || e.contains("quote exceeded")+ || e.contains("over quota")+ // 550 user has too many messages on the server+ || e.contains("too many messages")+}++/// Check if the email account has been disabled or blocked by the email+/// provider.+pub fn is_disabled_account(e: &str) -> bool {+ // 554 The email account that you tried to reach is disabled. Learn more at https://support.google.com/mail/?p=DisabledUser"+ e.contains("disabled")+ // 554 delivery error: Sorry your message to [email] cannot be delivered. This account has been disabled or discontinued+ || e.contains("discontinued")+}++/// Check if the error is an IO "incomplete" error.+pub fn is_err_io_errors(e: &SmtpError) -> bool {+ match e {+ SmtpError::SmtpError(AsyncSmtpError::Io(err)) => err.to_string() == "incomplete",+ _ => false,+ }+}++/// Check if the IP is blacklisted.+pub fn is_err_ip_blacklisted(e: &SmtpError) -> bool {+ let message: &Vec<String> = match e {+ SmtpError::SmtpError(AsyncSmtpError::Transient(r) | AsyncSmtpError::Permanent(r)) => {+ r.message.as_ref()+ }+ _ => {+ return false;+ }+ };+ let first_line = message[0].to_lowercase();++ // Permanent errors++ // 5.7.1 IP address blacklisted by recipient+ // 5.7.1 Service unavailable; Client host [147.75.45.223] is blacklisted. Visit https://www.sophos.com/en-us/threat-center/ip-lookup.aspx?ip=147.75.45.223 to request delisting+ // 5.3.0 <[email protected]>... Mail from 147.75.45.223 rejected by Abusix blacklist+ first_line.contains("blacklist") ||+ // Rejected because 23.129.64.213 is in a black list at b.barracudacentral.org+ first_line.contains("black list") ||+ // 5.7.1 Recipient not authorized, your IP has been found on a block list+ first_line.contains("block list") ||+ // Unable to add <EMAIL> because host 23.129.64.184 is listed on zen.spamhaus.org+ // 5.7.1 Service unavailable, Client host [23.129.64.184] blocked using Spamhaus.+ // 5.7.1 Email cannot be delivered. Reason: Email detected as Spam by spam filters.+ first_line.contains("spam") ||+ // host 23.129.64.216 is listed at combined.mail.abusix.zone (127.0.0.12,+ first_line.contains("abusix") ||+ // 5.7.1 Relaying denied. IP name possibly forged [45.154.35.252]+ // 5.7.1 Relaying denied: You must check for new mail before sending mail. [23.129.64.216]+ first_line.contains("relaying denied") ||+ // 5.7.1 <unknown[23.129.64.100]>: Client host rejected: Access denied+ first_line.contains("access denied") ||+ // sorry, mail from your location [5.79.109.48] is administratively denied (#5.7.1)+ first_line.contains("administratively denied") ||+ // 5.7.606 Access denied, banned sending IP [23.129.64.216]+ first_line.contains("banned") ||+ // Blocked - see https://ipcheck.proofpoint.com/?ip=23.129.64.192+ // 5.7.1 Mail from 23.129.64.183 has been blocked by Trend Micro Email Reputation Service.+ first_line.contains("blocked") ||+ // Connection rejected by policy [7.3] 38206, please visit https://support.symantec.com/en_US/article.TECH246726.html for more details about this error message.+ first_line.contains("connection rejected") ||+ // csi.mimecast.org Poor Reputation Sender. - https://community.mimecast.com/docs/DOC-1369#550 [6ATVl4DjOvSA6XNsWGoUFw.us31]+ // 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")||++ // Transient errors++ // Blocked - see https://www.spamcop.net/bl.shtml?23.129.64.211+ first_line.contains("blocked") ||+ // 4.7.1 <EMAIL>: Relay access denied+ first_line.contains("access denied") ||+ // relay not permitted!+ first_line.contains("relay not permitted") ||+ // 23.129.64.216 is not yet authorized to deliver mail from+ first_line.contains("not yet authorized")+}++/// Check if the IP needs a reverse DNS.+pub fn is_err_needs_rdns(e: &SmtpError) -> bool {+ let message: &Vec<String> = match e {+ SmtpError::SmtpError(AsyncSmtpError::Transient(r) | AsyncSmtpError::Permanent(r)) => {+ r.message.as_ref()+ }+ _ => {+ return false;+ }+ };+ let first_line = message[0].to_lowercase();++ // 4.7.25 Client host rejected: cannot find your hostname, [147.75.45.223]+ // 4.7.1 Client host rejected: cannot find your reverse hostname, [147.75.45.223]+ // 5.7.1 Client host rejected: cannot find your reverse hostname, [23.129.64.184]+ first_line.contains("cannot find your reverse hostname") ||+ // You dont seem to have a reverse dns entry. Come back later. You are greylisted for 20 minutes. See http://www.fsf.org/about/systems/greylisting+ first_line.contains("reverse dns entry")+}diff --git a/core/src/util/input_output.rs b/core/src/util/input_output.rsindex ee43bdbe..a8c547b5 100644--- a/core/src/util/input_output.rs+++ b/core/src/util/input_output.rs@@ -16,7 +16,7 @@use crate::misc::{MiscDetails, MiscError};use crate::mx::{MxDetails, MxError};-use crate::smtp::{SmtpDetails, SmtpError};+use crate::smtp::{SmtpDetails, SmtpError, SmtpErrorDesc};use crate::syntax::SyntaxDetails;use async_smtp::{ClientSecurity, ClientTlsParameters};use serde::{ser::SerializeMap, Deserialize, Serialize, Serializer};@@ -280,6 +280,10 @@ impl Serialize for CheckEmailOutput {#[derive(Serialize)]struct MyError<E> {error: E,+ // We add an optional "description" field when relevant, given by+ // the `get_description` on SmtpError.+ #[serde(skip_serializing_if = "Option::is_none")]+ description: Option<SmtpErrorDesc>,}let mut map = serializer.serialize_map(Some(1))?;@@ -287,17 +291,85 @@ impl Serialize for CheckEmailOutput {map.serialize_entry("is_reachable", &self.is_reachable)?;match &self.misc {Ok(t) => map.serialize_entry("misc", &t)?,- Err(error) => map.serialize_entry("misc", &MyError { error })?,+ Err(error) => map.serialize_entry(+ "misc",+ &MyError {+ error,+ description: None,+ },+ )?,}match &self.mx {Ok(t) => map.serialize_entry("mx", &t)?,- Err(error) => map.serialize_entry("mx", &MyError { error })?,+ Err(error) => map.serialize_entry(+ "mx",+ &MyError {+ error,+ description: None,+ },+ )?,}match &self.smtp {Ok(t) => map.serialize_entry("smtp", &t)?,- Err(error) => map.serialize_entry("smtp", &MyError { error })?,+ Err(error) => map.serialize_entry(+ "smtp",+ &MyError {+ error,+ description: error.get_description(),+ },+ )?,}map.serialize_entry("syntax", &self.syntax)?;map.end()}}++#[cfg(test)]+mod tests {+ use super::CheckEmailOutput;+ use async_smtp::smtp::response::{Category, Code, Detail, Response, Severity};++ #[test]+ fn should_serialize_correctly() {+ // create a dummy CheckEmailOutput, with a given message as a transient+ // SMTP error.+ fn dummy_response_with_message(m: &str) -> CheckEmailOutput {+ let r = Response::new(+ Code {+ severity: Severity::TransientNegativeCompletion,+ category: Category::MailSystem,+ detail: Detail::Zero,+ },+ vec![m.to_string(), "8BITMIME".to_string(), "SIZE 42".to_string()],+ );++ CheckEmailOutput {+ input: "foo".to_string(),+ is_reachable: super::Reachable::Unknown,+ misc: Ok(super::MiscDetails::default()),+ mx: Ok(super::MxDetails::default()),+ syntax: super::SyntaxDetails::default(),+ smtp: Err(super::SmtpError::SmtpError(r.into())),+ }+ }++ let res = dummy_response_with_message("blacklist");+ let actual = serde_json::to_string(&res).unwrap();+ // Make sure the `description` is present with IpBlacklisted.+ let expected = r#"{"input":"foo","is_reachable":"unknown","misc":{"is_disposable":false,"is_role_account":false},"mx":{"accepts_mail":false,"records":[]},"smtp":{"error":{"type":"SmtpError","message":"transient: blacklist"},"description":"IpBlacklisted"},"syntax":{"address":null,"domain":"","is_valid_syntax":false,"username":""}}"#;+ assert_eq!(expected, actual);++ let res =+ dummy_response_with_message("Client host rejected: cannot find your reverse hostname");+ let actual = serde_json::to_string(&res).unwrap();+ // Make sure the `description` is present with NeedsRDNs.+ let expected = r#"{"input":"foo","is_reachable":"unknown","misc":{"is_disposable":false,"is_role_account":false},"mx":{"accepts_mail":false,"records":[]},"smtp":{"error":{"type":"SmtpError","message":"transient: Client host rejected: cannot find your reverse hostname"},"description":"NeedsRDNS"},"syntax":{"address":null,"domain":"","is_valid_syntax":false,"username":""}}"#;+ assert_eq!(expected, actual);++ let res = dummy_response_with_message("foobar");+ let actual = serde_json::to_string(&res).unwrap();+ // Make sure the `description` is NOT present.+ let expected = r#"{"input":"foo","is_reachable":"unknown","misc":{"is_disposable":false,"is_role_account":false},"mx":{"accepts_mail":false,"records":[]},"smtp":{"error":{"type":"SmtpError","message":"transient: foobar"}},"syntax":{"address":null,"domain":"","is_valid_syntax":false,"username":""}}"#;+ assert_eq!(expected, actual);+ }+}