From ffc498a5d007818d11f7f3545c3f135b0db3a3a7 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Fri, 15 Oct 2021 12:27:51 +0300 Subject: [PATCH] melib/smtp: fix Cc and Bcc ignored when sending mail --- melib/src/email.rs | 8 ++++++++ melib/src/smtp.rs | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/melib/src/email.rs b/melib/src/email.rs index 2baf6d92..450a9f44 100644 --- a/melib/src/email.rs +++ b/melib/src/email.rs @@ -488,6 +488,14 @@ impl Envelope { self.to.as_slice() } + pub fn cc(&self) -> &[Address] { + self.cc.as_slice() + } + + pub fn bcc(&self) -> &[Address] { + self.bcc.as_slice() + } + pub fn field_to_to_string(&self) -> String { if self.to.is_empty() { self.other_headers diff --git a/melib/src/smtp.rs b/melib/src/smtp.rs index 5246a440..e536a901 100644 --- a/melib/src/smtp.rs +++ b/melib/src/smtp.rs @@ -616,7 +616,7 @@ impl SmtpConnection { let envelope = Envelope::from_bytes(mail.as_bytes(), None) .chain_err_summary(|| "SMTP submission was aborted")?; let tos = tos.unwrap_or_else(|| envelope.to()); - if tos.is_empty() { + if tos.is_empty() && envelope.cc().is_empty() && envelope.bcc().is_empty() { return Err(MeliError::new("SMTP submission was aborted because there was no e-mail address found in the To: header field. Consider adding recipients.")); } let mut current_command: SmallVec<[&[u8]; 16]> = SmallVec::new(); @@ -651,7 +651,11 @@ impl SmtpConnection { //return a reply indicating whether the failure is permanent (i.e., will occur again if //the client tries to send the same address again) or temporary (i.e., the address might //be accepted if the client tries again later). - for addr in tos { + for addr in tos + .into_iter() + .chain(envelope.cc().into_iter()) + .chain(envelope.bcc().into_iter()) + { current_command.clear(); current_command.push(b"RCPT TO:<"); current_command.push(addr.address_spec_raw().trim());