refactor: do not evaluate smtp_write! argument twice

This commit is contained in:
link2xt
2026-07-09 12:21:50 +00:00
committed by l
parent 678bf2a684
commit e47740f45f
+8 -6
View File
@@ -300,8 +300,10 @@ where
macro_rules! smtp_write { macro_rules! smtp_write {
($command: expr) => { ($command: expr) => {
log::trace!("Sending: {}", String::from_utf8_lossy($command)); let command = $command;
buf_stream.write_all($command).await?; let bytes: &[u8] = command.as_ref();
log::trace!("Sending: {}", String::from_utf8_lossy(bytes));
buf_stream.write_all(bytes).await?;
buf_stream.flush().await?; buf_stream.flush().await?;
}; };
} }
@@ -375,7 +377,7 @@ where
smtp_read!("initial greeting", "220")?; smtp_read!("initial greeting", "220")?;
smtp_cmd!( smtp_cmd!(
format!("{greeting} {}\r\n", { config.client_hostname }).as_bytes(), format!("{greeting} {}\r\n", { config.client_hostname }),
greeting, greeting,
"250" "250"
)?; )?;
@@ -421,7 +423,7 @@ where
buf_stream = BufStream::new(smtp_stream); buf_stream = BufStream::new(smtp_stream);
smtp_cmd!( smtp_cmd!(
format!("EHLO {}\r\n", config.client_hostname).as_bytes(), format!("EHLO {}\r\n", config.client_hostname),
"EHLO after STARTTLS", "EHLO after STARTTLS",
"250" "250"
)?; )?;
@@ -429,14 +431,14 @@ where
} }
// MAIL FROM // 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 { if !pipelining {
smtp_read!("MAIL FROM", "250")?; smtp_read!("MAIL FROM", "250")?;
} }
// RCPT TO // RCPT TO
for rcpt in &envelope.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 { if !pipelining {
smtp_read!("RCPT TO", "250")?; smtp_read!("RCPT TO", "250")?;
} }