From 3fd7684ee8a0d7703a8ee558a0a090e7b5dd1378 Mon Sep 17 00:00:00 2001 From: link2xt Date: Thu, 9 Jul 2026 12:21:50 +0000 Subject: [PATCH] refactor: do not evaluate smtp_write! argument twice --- src/smtp_client.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/smtp_client.rs b/src/smtp_client.rs index 4604845..bff3d87 100644 --- a/src/smtp_client.rs +++ b/src/smtp_client.rs @@ -300,8 +300,10 @@ where macro_rules! smtp_write { ($command: expr) => { - log::trace!("Sending: {}", String::from_utf8_lossy($command)); - buf_stream.write_all($command).await?; + let command = $command; + let bytes: &[u8] = command.as_ref(); + log::trace!("Sending: {}", String::from_utf8_lossy(bytes)); + buf_stream.write_all(bytes).await?; buf_stream.flush().await?; }; } @@ -375,7 +377,7 @@ where smtp_read!("initial greeting", "220")?; smtp_cmd!( - format!("{greeting} {}\r\n", { config.client_hostname }).as_bytes(), + format!("{greeting} {}\r\n", { config.client_hostname }), greeting, "250" )?; @@ -421,7 +423,7 @@ where buf_stream = BufStream::new(smtp_stream); smtp_cmd!( - format!("EHLO {}\r\n", config.client_hostname).as_bytes(), + format!("EHLO {}\r\n", config.client_hostname), "EHLO after STARTTLS", "250" )?; @@ -429,14 +431,14 @@ where } // MAIL FROM - smtp_write!(format!("MAIL FROM:<{}>\r\n", envelope.mail_from).as_bytes()); + smtp_write!(format!("MAIL FROM:<{}>\r\n", envelope.mail_from)); if !pipelining { smtp_read!("MAIL FROM", "250")?; } // RCPT TO for rcpt in &envelope.rcpt_to { - smtp_write!(format!("RCPT TO:<{}>\r\n", rcpt).as_bytes()); + smtp_write!(format!("RCPT TO:<{}>\r\n", rcpt)); if !pipelining { smtp_read!("RCPT TO", "250")?; }