Skip to content

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

fix(core): Fix MX random record selection (#1263)

Amaury9fae593b8590
diff --git a/backend/src/main.rs b/backend/src/main.rs
index 935dfb09..43fa8fb9 100644
--- a/backend/src/main.rs
+++ b/backend/src/main.rs
@@ -124,7 +124,7 @@ async fn run_warp_server(
.expect("Environment variable PORT is malformed.")
})
.unwrap_or(8080);
- println!("Server is listening on {}:{}.", host, port);
+ println!("Server is listening on {host}:{port}.");
warp::serve(routes).run((host, port)).await;
diff --git a/backend/src/sentry_util.rs b/backend/src/sentry_util.rs
index 1c929bb8..4644a8a2 100644
--- a/backend/src/sentry_util.rs
+++ b/backend/src/sentry_util.rs
@@ -82,7 +82,7 @@ impl<'a> SentryError<'a> {
/// Helper function to send an Error event to Sentry. We redact all sensitive
/// info before sending to Sentry, by removing all instances of `username`.
fn error(err: SentryError, result: &CheckEmailOutput) {
- let exception_value = redact(format!("{:?}", err).as_str(), &result.syntax.username);
+ let exception_value = redact(format!("{err:?}").as_str(), &result.syntax.username);
log::debug!(
target: LOG_TARGET,
"Sending error to Sentry: {}",
@@ -103,7 +103,7 @@ fn error(err: SentryError, result: &CheckEmailOutput) {
environment: Some("production".into()),
release: Some(CARGO_PKG_VERSION.into()),
message: Some(redact(
- format!("{:#?}", result).as_str(),
+ format!("{result:#?}").as_str(),
&result.syntax.username,
)),
server_name: get_backend_name(),
diff --git a/cli/src/main.rs b/cli/src/main.rs
index 4a28835a..9779f9cf 100644
--- a/cli/src/main.rs
+++ b/cli/src/main.rs
@@ -114,10 +114,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
match serde_json::to_string_pretty(&result) {
Ok(output) => {
- println!("{}", output);
+ println!("{output}");
}
Err(err) => {
- println!("{}", err);
+ println!("{err}");
}
};
diff --git a/core/src/gravatar.rs b/core/src/gravatar.rs
index 62145756..d5ace16c 100644
--- a/core/src/gravatar.rs
+++ b/core/src/gravatar.rs
@@ -25,7 +25,7 @@ pub async fn check_gravatar(to_email: &str) -> Option<String> {
let mail_hash: Digest = md5::compute(to_email);
- let url = format!("{}{:x}", API_BASE_URL, mail_hash);
+ let url = format!("{API_BASE_URL}{mail_hash:x}");
log::debug!(
target: LOG_TARGET,
diff --git a/core/src/lib.rs b/core/src/lib.rs
index 9592c025..5782c5bb 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -205,7 +205,7 @@ pub async fn check_email(input: &CheckEmailInput) -> CheckEmailOutput {
mx_records.sort_by_key(|a| a.preference());
let host = if mx_records.len() >= 3 {
let mut rng = rand::thread_rng();
- let index = rng.gen_range(1..mx_records.len() - 2);
+ let index = rng.gen_range(1..mx_records.len() - 1);
mx_records[index]
} else {
mx_records[mx_records.len() - 1]
diff --git a/core/src/normalize.rs b/core/src/normalize.rs
index 86e991c7..706f55c8 100644
--- a/core/src/normalize.rs
+++ b/core/src/normalize.rs
@@ -1,7 +1,7 @@
pub fn normalize_email(username: &str, domain: &str) -> String {
match domain {
"gmail.com" | "googlemail.com" => normalize_gmail(username),
- _ => format!("{}@{}", username, domain),
+ _ => format!("{username}@{domain}"),
}
}
@@ -29,7 +29,7 @@ fn normalize_gmail(username: &str) -> String {
})
.collect::<String>();
- format!("{}@gmail.com", username)
+ format!("{username}@gmail.com",)
}
#[cfg(test)]
diff --git a/core/src/smtp/connect.rs b/core/src/smtp/connect.rs
index e93f0bd5..05884760 100644
--- a/core/src/smtp/connect.rs
+++ b/core/src/smtp/connect.rs
@@ -228,7 +228,7 @@ async fn smtp_is_catch_all(
.map(char::from)
.take(15)
.collect();
- let random_email = EmailAddress::new(format!("{}@{}", random_email, domain));
+ let random_email = EmailAddress::new(format!("{random_email}@{domain}"));
email_deliverable(
smtp_transport,
diff --git a/core/src/smtp/gmail.rs b/core/src/smtp/gmail.rs
index 42853b15..c4250e5f 100644
--- a/core/src/smtp/gmail.rs
+++ b/core/src/smtp/gmail.rs
@@ -38,7 +38,7 @@ pub enum GmailError {
impl fmt::Display for GmailError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{:?}", self)
+ write!(f, "{self:?}")
}
}
diff --git a/core/src/smtp/parser.rs b/core/src/smtp/parser.rs
index 6c81adcd..febbb2db 100644
--- a/core/src/smtp/parser.rs
+++ b/core/src/smtp/parser.rs
@@ -59,7 +59,7 @@ pub fn is_invalid(e: &str, email: &EmailAddress) -> bool {
// 550 No such user here
|| e.contains("no such user")
// permanent: 5.1.1 MXIN501 mailbox <EMAIL> unknown (on @virginmedia.com)
- || e.contains(format!("mailbox {} unknown", email).as_str())
+ || e.contains(format!("mailbox {email} unknown").as_str())
// 550 5.1.1 : Mailbox not found
// 550 Unknown address error ‘MAILBOX NOT FOUND’
|| e.contains("mailbox not found")
diff --git a/core/src/smtp/yahoo.rs b/core/src/smtp/yahoo.rs
index 3bc8cd0f..492e7869 100644
--- a/core/src/smtp/yahoo.rs
+++ b/core/src/smtp/yahoo.rs
@@ -92,7 +92,7 @@ pub enum YahooError {
impl fmt::Display for YahooError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Customize so only `x` and `y` are denoted.
- write!(f, "{:?}", self)
+ write!(f, "{self:?}")
}
}