mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-08 18:45:13 +00:00
make Backend::add_msg return String instead of trait (#340)
This step was necessary to move logic from CLI to lib.
This commit is contained in:
parent
7c01f88006
commit
e1c92d3f57
|
@ -30,7 +30,7 @@ pub trait Backend<'a> {
|
||||||
page_size: usize,
|
page_size: usize,
|
||||||
page: usize,
|
page: usize,
|
||||||
) -> Result<Box<dyn Envelopes>>;
|
) -> Result<Box<dyn Envelopes>>;
|
||||||
fn add_msg(&mut self, mbox: &str, msg: &[u8], flags: &str) -> Result<Box<dyn ToString>>;
|
fn add_msg(&mut self, mbox: &str, msg: &[u8], flags: &str) -> Result<String>;
|
||||||
fn get_msg(&mut self, mbox: &str, id: &str) -> Result<Msg>;
|
fn get_msg(&mut self, mbox: &str, id: &str) -> Result<Msg>;
|
||||||
fn copy_msg(&mut self, mbox_src: &str, mbox_dst: &str, ids: &str) -> Result<()>;
|
fn copy_msg(&mut self, mbox_src: &str, mbox_dst: &str, ids: &str) -> Result<()>;
|
||||||
fn move_msg(&mut self, mbox_src: &str, mbox_dst: &str, ids: &str) -> Result<()>;
|
fn move_msg(&mut self, mbox_src: &str, mbox_dst: &str, ids: &str) -> Result<()>;
|
||||||
|
|
|
@ -342,7 +342,7 @@ impl<'a> Backend<'a> for ImapBackend<'a> {
|
||||||
Ok(Box::new(envelopes))
|
Ok(Box::new(envelopes))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_msg(&mut self, mbox: &str, msg: &[u8], flags: &str) -> Result<Box<dyn ToString>> {
|
fn add_msg(&mut self, mbox: &str, msg: &[u8], flags: &str) -> Result<String> {
|
||||||
let flags: ImapFlags = flags.into();
|
let flags: ImapFlags = flags.into();
|
||||||
self.sess()?
|
self.sess()?
|
||||||
.append(mbox, msg)
|
.append(mbox, msg)
|
||||||
|
@ -354,7 +354,7 @@ impl<'a> Backend<'a> for ImapBackend<'a> {
|
||||||
.select(mbox)
|
.select(mbox)
|
||||||
.context(format!("cannot select mailbox {:?}", mbox))?
|
.context(format!("cannot select mailbox {:?}", mbox))?
|
||||||
.exists;
|
.exists;
|
||||||
Ok(Box::new(last_seq))
|
Ok(last_seq.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_msg(&mut self, mbox: &str, seq: &str) -> Result<Msg> {
|
fn get_msg(&mut self, mbox: &str, seq: &str) -> Result<Msg> {
|
||||||
|
|
|
@ -215,7 +215,7 @@ impl<'a> Backend<'a> for MaildirBackend<'a> {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_msg(&mut self, dir: &str, msg: &[u8], flags: &str) -> Result<Box<dyn ToString>> {
|
fn add_msg(&mut self, dir: &str, msg: &[u8], flags: &str) -> Result<String> {
|
||||||
info!(">> add maildir message");
|
info!(">> add maildir message");
|
||||||
debug!("dir: {:?}", dir);
|
debug!("dir: {:?}", dir);
|
||||||
debug!("flags: {:?}", flags);
|
debug!("flags: {:?}", flags);
|
||||||
|
@ -246,7 +246,7 @@ impl<'a> Backend<'a> for MaildirBackend<'a> {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
info!("<< add maildir message");
|
info!("<< add maildir message");
|
||||||
Ok(Box::new(hash))
|
Ok(hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_msg(&mut self, dir: &str, short_hash: &str) -> Result<Msg> {
|
fn get_msg(&mut self, dir: &str, short_hash: &str) -> Result<Msg> {
|
||||||
|
|
|
@ -197,7 +197,7 @@ impl<'a> Backend<'a> for NotmuchBackend<'a> {
|
||||||
Ok(envelopes)
|
Ok(envelopes)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_msg(&mut self, _: &str, msg: &[u8], tags: &str) -> Result<Box<dyn ToString>> {
|
fn add_msg(&mut self, _: &str, msg: &[u8], tags: &str) -> Result<String> {
|
||||||
info!(">> add notmuch envelopes");
|
info!(">> add notmuch envelopes");
|
||||||
debug!("tags: {:?}", tags);
|
debug!("tags: {:?}", tags);
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ impl<'a> Backend<'a> for NotmuchBackend<'a> {
|
||||||
.with_context(|| format!("cannot add flags to notmuch message {:?}", id))?;
|
.with_context(|| format!("cannot add flags to notmuch message {:?}", id))?;
|
||||||
|
|
||||||
info!("<< add notmuch envelopes");
|
info!("<< add notmuch envelopes");
|
||||||
Ok(Box::new(hash))
|
Ok(hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_msg(&mut self, _: &str, short_hash: &str) -> Result<Msg> {
|
fn get_msg(&mut self, _: &str, short_hash: &str) -> Result<Msg> {
|
||||||
|
|
|
@ -120,10 +120,12 @@ mod tests {
|
||||||
Mbox {
|
Mbox {
|
||||||
delim: "/".into(),
|
delim: "/".into(),
|
||||||
name: "INBOX".into(),
|
name: "INBOX".into(),
|
||||||
|
desc: "desc".into(),
|
||||||
},
|
},
|
||||||
Mbox {
|
Mbox {
|
||||||
delim: "/".into(),
|
delim: "/".into(),
|
||||||
name: "Sent".into(),
|
name: "Sent".into(),
|
||||||
|
desc: "desc".into(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
@ -144,7 +146,7 @@ mod tests {
|
||||||
) -> Result<Box<dyn Envelopes>> {
|
) -> Result<Box<dyn Envelopes>> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
fn add_msg(&mut self, _: &str, _: &[u8], _: &str) -> Result<Box<dyn ToString>> {
|
fn add_msg(&mut self, _: &str, _: &[u8], _: &str) -> Result<String> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
fn get_msg(&mut self, _: &str, _: &str) -> Result<Msg> {
|
fn get_msg(&mut self, _: &str, _: &str) -> Result<Msg> {
|
||||||
|
@ -179,9 +181,9 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
concat![
|
concat![
|
||||||
"\n",
|
"\n",
|
||||||
"DELIM │NAME │ATTRIBUTES \n",
|
"DELIM │NAME │DESC \n",
|
||||||
"/ │INBOX │NoSelect \n",
|
"/ │INBOX │desc \n",
|
||||||
"/ │Sent │NoInferiors, HasNoChildren \n",
|
"/ │Sent │desc \n",
|
||||||
"\n"
|
"\n"
|
||||||
],
|
],
|
||||||
printer.writer.content
|
printer.writer.content
|
||||||
|
|
Loading…
Reference in a new issue