diff --git a/src/smtp/smtp_service.rs b/src/smtp/smtp_service.rs index 35d79bd9..13ea6cec 100644 --- a/src/smtp/smtp_service.rs +++ b/src/smtp/smtp_service.rs @@ -56,18 +56,22 @@ impl LettreService<'_> { impl SmtpService for LettreService<'_> { fn send(&mut self, account: &AccountConfig, msg: &Msg) -> Result> { - let envelope: lettre::address::Envelope = msg.try_into()?; - let mut msg = msg.into_sendable_msg(account)?.formatted(); + let mut raw_msg = msg.into_sendable_msg(account)?.formatted(); - if let Some(cmd) = account.hooks.pre_send.as_deref() { - for cmd in cmd.split('|') { - msg = pipe_cmd(cmd.trim(), &msg) - .with_context(|| format!("cannot execute pre-send hook {:?}", cmd))? - } - }; + let envelope: lettre::address::Envelope = + if let Some(cmd) = account.hooks.pre_send.as_deref() { + for cmd in cmd.split('|') { + raw_msg = pipe_cmd(cmd.trim(), &raw_msg) + .with_context(|| format!("cannot execute pre-send hook {:?}", cmd))? + } + let parsed_mail = mailparse::parse_mail(&raw_msg)?; + Msg::from_parsed_mail(parsed_mail, account)?.try_into() + } else { + msg.try_into() + }?; - self.transport()?.send_raw(&envelope, &msg)?; - Ok(msg) + self.transport()?.send_raw(&envelope, &raw_msg)?; + Ok(raw_msg) } }