mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-05 09:05:13 +00:00
implement notmuch get_mboxes
This commit is contained in:
parent
da0e7889a3
commit
00e2524640
|
@ -3,7 +3,7 @@ use std::{convert::TryInto, fs};
|
|||
use anyhow::{anyhow, Context, Result};
|
||||
|
||||
use crate::{
|
||||
backends::{Backend, NotmuchEnvelopes},
|
||||
backends::{Backend, NotmuchEnvelopes, NotmuchMbox, NotmuchMboxes},
|
||||
config::{AccountConfig, NotmuchBackendConfig},
|
||||
mbox::Mboxes,
|
||||
msg::{Envelopes, Msg},
|
||||
|
@ -39,7 +39,14 @@ impl<'a> Backend<'a> for NotmuchBackend<'a> {
|
|||
}
|
||||
|
||||
fn get_mboxes(&mut self) -> Result<Box<dyn Mboxes>> {
|
||||
unimplemented!();
|
||||
let mut mboxes: Vec<_> = self
|
||||
.account_config
|
||||
.mailboxes
|
||||
.iter()
|
||||
.map(|(k, v)| NotmuchMbox::new(k, v))
|
||||
.collect();
|
||||
mboxes.sort_by(|a, b| b.name.partial_cmp(&a.name).unwrap());
|
||||
Ok(Box::new(NotmuchMboxes(mboxes)))
|
||||
}
|
||||
|
||||
fn del_mbox(&mut self, _mbox: &str) -> Result<()> {
|
||||
|
|
80
src/backends/notmuch/notmuch_mbox.rs
Normal file
80
src/backends/notmuch/notmuch_mbox.rs
Normal file
|
@ -0,0 +1,80 @@
|
|||
//! Notmuch mailbox module.
|
||||
//!
|
||||
//! This module provides Notmuch types and conversion utilities
|
||||
//! related to the mailbox
|
||||
|
||||
use anyhow::Result;
|
||||
use std::{
|
||||
fmt::{self, Display},
|
||||
ops::Deref,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
mbox::Mboxes,
|
||||
output::{PrintTable, PrintTableOpts, WriteColor},
|
||||
ui::{Cell, Row, Table},
|
||||
};
|
||||
|
||||
/// Represents a list of Notmuch mailboxes.
|
||||
#[derive(Debug, Default, serde::Serialize)]
|
||||
pub struct NotmuchMboxes(pub Vec<NotmuchMbox>);
|
||||
|
||||
impl Deref for NotmuchMboxes {
|
||||
type Target = Vec<NotmuchMbox>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl PrintTable for NotmuchMboxes {
|
||||
fn print_table(&self, writter: &mut dyn WriteColor, opts: PrintTableOpts) -> Result<()> {
|
||||
writeln!(writter)?;
|
||||
Table::print(writter, self, opts)?;
|
||||
writeln!(writter)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Mboxes for NotmuchMboxes {
|
||||
//
|
||||
}
|
||||
|
||||
/// Represents the notmuch virtual mailbox.
|
||||
#[derive(Debug, Default, PartialEq, Eq, serde::Serialize)]
|
||||
pub struct NotmuchMbox {
|
||||
/// Represents the virtual mailbox name.
|
||||
pub name: String,
|
||||
|
||||
/// Represents the query associated to the virtual mailbox name.
|
||||
pub query: String,
|
||||
}
|
||||
|
||||
impl NotmuchMbox {
|
||||
pub fn new(name: &str, query: &str) -> Self {
|
||||
Self {
|
||||
name: name.into(),
|
||||
query: query.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for NotmuchMbox {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.name)
|
||||
}
|
||||
}
|
||||
|
||||
impl Table for NotmuchMbox {
|
||||
fn head() -> Row {
|
||||
Row::new()
|
||||
.cell(Cell::new("NAME").bold().underline().white())
|
||||
.cell(Cell::new("QUERY").bold().underline().white())
|
||||
}
|
||||
|
||||
fn row(&self) -> Row {
|
||||
Row::new()
|
||||
.cell(Cell::new(&self.name).white())
|
||||
.cell(Cell::new(&self.query).green())
|
||||
}
|
||||
}
|
|
@ -81,6 +81,9 @@ pub mod backends {
|
|||
pub mod notmuch_backend;
|
||||
pub use notmuch_backend::*;
|
||||
|
||||
pub mod notmuch_mbox;
|
||||
pub use notmuch_mbox::*;
|
||||
|
||||
pub mod notmuch_envelope;
|
||||
pub use notmuch_envelope::*;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue