mirror of
https://github.com/soywod/himalaya.git
synced 2024-09-05 18:41:11 +00:00
impl notmuch get_envelopes
This commit is contained in:
parent
b855c44508
commit
8766d8862a
|
@ -1,6 +1,6 @@
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backends::Backend,
|
backends::Backend,
|
||||||
|
@ -36,7 +36,7 @@ impl<'a> NotmuchBackend<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Backend<'a> for NotmuchBackend<'a> {
|
impl<'a> Backend<'a> for NotmuchBackend<'a> {
|
||||||
fn add_mbox(&mut self, mdir: &str) -> Result<()> {
|
fn add_mbox(&mut self, _mbox: &str) -> Result<()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,70 +44,108 @@ impl<'a> Backend<'a> for NotmuchBackend<'a> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn del_mbox(&mut self, mdir: &str) -> Result<()> {
|
fn del_mbox(&mut self, _mbox: &str) -> Result<()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_envelopes(
|
fn get_envelopes(
|
||||||
&mut self,
|
&mut self,
|
||||||
mdir: &str,
|
mbox: &str,
|
||||||
page_size: usize,
|
page_size: usize,
|
||||||
page: usize,
|
page: usize,
|
||||||
) -> Result<Box<dyn Envelopes>> {
|
) -> Result<Box<dyn Envelopes>> {
|
||||||
unimplemented!();
|
let query = self
|
||||||
}
|
.account_config
|
||||||
|
.mailboxes
|
||||||
fn find_envelopes(
|
.get(mbox)
|
||||||
&mut self,
|
.map(|s| s.as_str())
|
||||||
_mdir: &str,
|
.unwrap_or("all");
|
||||||
query: &str,
|
|
||||||
_sort: &str,
|
|
||||||
_page_size: usize,
|
|
||||||
_page: usize,
|
|
||||||
) -> Result<Box<dyn Envelopes>> {
|
|
||||||
let query_builder = self
|
let query_builder = self
|
||||||
.db
|
.db
|
||||||
.create_query(query)
|
.create_query(query)
|
||||||
.context("cannot create notmuch query")?;
|
.context("cannot create notmuch query")?;
|
||||||
let msgs: NotmuchEnvelopes = query_builder
|
let mut envelopes: NotmuchEnvelopes = query_builder
|
||||||
.search_messages()
|
.search_messages()
|
||||||
.context(format!(
|
.context(format!(
|
||||||
"cannot find notmuch envelopes with query {:?}",
|
"cannot find notmuch envelopes with query {:?}",
|
||||||
query
|
query
|
||||||
))?
|
))?
|
||||||
.try_into()?;
|
.try_into()?;
|
||||||
Ok(Box::new(msgs))
|
envelopes.sort_by(|a, b| b.date.partial_cmp(&a.date).unwrap());
|
||||||
|
let page_begin = page * page_size;
|
||||||
|
if page_begin > envelopes.len() {
|
||||||
|
return Err(anyhow!(format!(
|
||||||
|
"cannot find notmuch envelopes at page {:?} (out of bounds)",
|
||||||
|
page_begin + 1,
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
let page_end = envelopes.len().min(page_begin + page_size);
|
||||||
|
envelopes.0 = envelopes[page_begin..page_end].to_owned();
|
||||||
|
Ok(Box::new(envelopes))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_msg(&mut self, mdir: &str, msg: &[u8], flags: &str) -> Result<Box<dyn ToString>> {
|
fn find_envelopes(
|
||||||
|
&mut self,
|
||||||
|
_mbox: &str,
|
||||||
|
query: &str,
|
||||||
|
_sort: &str,
|
||||||
|
page_size: usize,
|
||||||
|
page: usize,
|
||||||
|
) -> Result<Box<dyn Envelopes>> {
|
||||||
|
let query_builder = self
|
||||||
|
.db
|
||||||
|
.create_query(query)
|
||||||
|
.context("cannot create notmuch query")?;
|
||||||
|
let mut envelopes: NotmuchEnvelopes = query_builder
|
||||||
|
.search_messages()
|
||||||
|
.context(format!(
|
||||||
|
"cannot find notmuch envelopes with query {:?}",
|
||||||
|
query
|
||||||
|
))?
|
||||||
|
.try_into()?;
|
||||||
|
// TODO: use sort from parameters instead
|
||||||
|
envelopes.sort_by(|a, b| b.date.partial_cmp(&a.date).unwrap());
|
||||||
|
let page_begin = page * page_size;
|
||||||
|
if page_begin > envelopes.len() {
|
||||||
|
return Err(anyhow!(format!(
|
||||||
|
"cannot find notmuch envelopes at page {:?} (out of bounds)",
|
||||||
|
page_begin + 1,
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
let page_end = envelopes.len().min(page_begin + page_size);
|
||||||
|
envelopes.0 = envelopes[page_begin..page_end].to_owned();
|
||||||
|
Ok(Box::new(envelopes))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_msg(&mut self, _mbox: &str, _msg: &[u8], _flags: &str) -> Result<Box<dyn ToString>> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_msg(&mut self, mdir: &str, id: &str) -> Result<Msg> {
|
fn get_msg(&mut self, _mbox: &str, _id: &str) -> Result<Msg> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_msg(&mut self, mdir_src: &str, mdir_dst: &str, id: &str) -> Result<()> {
|
fn copy_msg(&mut self, _mbox_src: &str, _mbox_dst: &str, _id: &str) -> Result<()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_msg(&mut self, mdir_src: &str, mdir_dst: &str, id: &str) -> Result<()> {
|
fn move_msg(&mut self, _mbox_src: &str, _mbox_dst: &str, _id: &str) -> Result<()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn del_msg(&mut self, mdir: &str, id: &str) -> Result<()> {
|
fn del_msg(&mut self, _mbox: &str, _id: &str) -> Result<()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_flags(&mut self, mdir: &str, id: &str, flags_str: &str) -> Result<()> {
|
fn add_flags(&mut self, _mbox: &str, _id: &str, _flags_str: &str) -> Result<()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_flags(&mut self, mdir: &str, id: &str, flags_str: &str) -> Result<()> {
|
fn set_flags(&mut self, _mbox: &str, _id: &str, _flags_str: &str) -> Result<()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn del_flags(&mut self, mdir: &str, id: &str, flags_str: &str) -> Result<()> {
|
fn del_flags(&mut self, _mbox: &str, _id: &str, _flags_str: &str) -> Result<()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue