build smtp envelope after executing pre_send hook

This commit is contained in:
Clément DOUIN 2022-03-06 09:51:34 +01:00
parent 4dc1be25cd
commit 3899ec9c03
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72

View file

@ -56,18 +56,22 @@ impl LettreService<'_> {
impl SmtpService for LettreService<'_> {
fn send(&mut self, account: &AccountConfig, msg: &Msg) -> Result<Vec<u8>> {
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)
}
}