implement notmuch get_msg

This commit is contained in:
Clément DOUIN 2022-02-25 23:52:18 +01:00
parent 8766d8862a
commit 7093cfc715
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72

View file

@ -1,16 +1,14 @@
use std::convert::TryInto;
use std::{convert::TryInto, fs};
use anyhow::{anyhow, Context, Result};
use crate::{
backends::Backend,
backends::{Backend, NotmuchEnvelopes},
config::{AccountConfig, NotmuchBackendConfig},
mbox::Mboxes,
msg::{Envelopes, Msg},
};
use super::NotmuchEnvelopes;
pub struct NotmuchBackend<'a> {
account_config: &'a AccountConfig,
db: notmuch::Database,
@ -121,8 +119,18 @@ impl<'a> Backend<'a> for NotmuchBackend<'a> {
unimplemented!();
}
fn get_msg(&mut self, _mbox: &str, _id: &str) -> Result<Msg> {
unimplemented!();
fn get_msg(&mut self, _mbox: &str, id: &str) -> Result<Msg> {
let msg_filepath = self
.db
.find_message(id)
.context(format!("cannot find notmuch message {:?}", id))?
.ok_or_else(|| anyhow!("cannot find notmuch message {:?}", id))?
.filename()
.to_owned();
let raw_msg = fs::read(&msg_filepath)
.context(format!("cannot read message from file {:?}", msg_filepath))?;
let msg = Msg::from_parsed_mail(mailparse::parse_mail(&raw_msg)?, &self.account_config)?;
Ok(msg)
}
fn copy_msg(&mut self, _mbox_src: &str, _mbox_dst: &str, _id: &str) -> Result<()> {