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(backend): Add one simple retry on Unknown
Amauryfcffc1a28bab
diff --git a/.gitignore b/.gitignoreindex 440529dc..0cba1cb8 100644--- a/.gitignore+++ b/.gitignore@@ -1,6 +1,7 @@target**/*.rs.bk.DS_Store+private# Output when debugging Hotmail password recovery using a headless browser.hotmail.jpegdiff --git a/backend/src/sentry_util.rs b/backend/src/sentry_util.rsindex 481df2d5..e1f967b2 100644--- a/backend/src/sentry_util.rs+++ b/backend/src/sentry_util.rs@@ -99,10 +99,7 @@ fn error(err: SentryError, result: &CheckEmailOutput) {level: Level::Error,environment: Some("production".into()),release: Some(CARGO_PKG_VERSION.into()),- message: Some(redact(- format!("{result:#?}").as_str(),- &result.syntax.username,- )),+ message: Some(format!("{result:#?}")),server_name: get_backend_name(),transaction: Some(format!("check_email:{}", result.syntax.domain)),..Default::default()diff --git a/backend/src/worker/check_email.rs b/backend/src/worker/check_email.rsindex 3f5b1f8f..cfd07d34 100644--- a/backend/src/worker/check_email.rs+++ b/backend/src/worker/check_email.rs@@ -14,8 +14,8 @@// 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 check_if_email_exists::LOG_TARGET;use check_if_email_exists::{CheckEmailInput, CheckEmailOutput};+use check_if_email_exists::{Reachable, LOG_TARGET};use lapin::message::Delivery;use lapin::{options::*, BasicProperties, Channel};use serde::{Deserialize, Serialize};@@ -80,6 +80,8 @@ pub async fn process_check_email(debug!(target: LOG_TARGET, reply_to=?reply_to, correlation_id=?correlation_id, "Sent reply")}+ let (email, is_reachable) = (output.input.to_owned(), output.is_reachable.clone());+// Check if we have a webhook to send the output to.if let Some(webhook) = payload.webhook {let webhook_output = WebhookOutput {@@ -100,7 +102,17 @@ pub async fn process_check_email(info!(target: LOG_TARGET, email=?webhook_output.output.input, is_reachable=?webhook_output.output.is_reachable, "Finished check");}- delivery.ack(BasicAckOptions::default()).await?;+ // If is_reachable is unknown, then we requeue the message, but only once.+ // We might want to add a requeue counter in the future, see:+ // https://stackoverflow.com/questions/25226080/rabbitmq-how-to-requeue-message-with-counter+ if is_reachable == Reachable::Unknown && !delivery.redelivered {+ delivery+ .reject(BasicRejectOptions { requeue: true })+ .await?;+ info!(target: LOG_TARGET, email=?email, "Requeued message");+ } else {+ delivery.ack(BasicAckOptions::default()).await?;+ }Ok(())}diff --git a/core/src/util/input_output.rs b/core/src/util/input_output.rsindex c00c1df3..95d97b1b 100644--- a/core/src/util/input_output.rs+++ b/core/src/util/input_output.rs@@ -407,7 +407,7 @@ impl CheckEmailInput {/// An enum to describe how confident we are that the recipient address is/// real.-#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]+#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]#[serde(rename_all = "lowercase")]pub enum Reachable {/// The email is safe to send.