extract account and config from cli to lib (#340)

This commit is contained in:
Clément DOUIN
2022-05-28 16:59:12 +02:00
parent 0e98def513
commit 3f5feed0ff
27 changed files with 219 additions and 103 deletions
+3 -2
View File
@@ -1,4 +1,5 @@
use anyhow::{Context, Result};
use himalaya_lib::account::AccountConfig;
use lettre::{
self,
transport::smtp::{
@@ -9,7 +10,7 @@ use lettre::{
};
use std::convert::TryInto;
use crate::{config::AccountConfig, msg::Msg, output::pipe_cmd};
use crate::{msg::Msg, output::pipe_cmd};
pub trait SmtpService {
fn send(&mut self, account: &AccountConfig, msg: &Msg) -> Result<Vec<u8>>;
@@ -62,7 +63,7 @@ impl SmtpService for LettreService<'_> {
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))?
.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()