melib/backends: cleanup MailBackend trait definition

memfd
Manos Pitsidianakis 2020-08-20 21:25:12 +03:00
parent 3eadaba34e
commit 94433cfc40
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
8 changed files with 69 additions and 115 deletions

View File

@ -304,24 +304,17 @@ pub type ResultFuture<T> = Result<Pin<Box<dyn Future<Output = Result<T>> + Send
pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
fn capabilities(&self) -> MailBackendCapabilities;
fn is_online(&self) -> ResultFuture<()> {
Err(MeliError::new("Unimplemented."))
Ok(Box::pin(async { Ok(()) }))
}
//fn fetch(&mut self, mailbox_hash: MailboxHash) -> Result<Async<Result<Vec<Envelope>>>>;
fn fetch(
&mut self,
_mailbox_hash: MailboxHash,
) -> Result<Pin<Box<dyn Stream<Item = Result<Vec<Envelope>>> + Send + 'static>>> {
Err(MeliError::new("Unimplemented."))
}
fn refresh(&mut self, _mailbox_hash: MailboxHash) -> ResultFuture<()> {
Err(MeliError::new("Unimplemented."))
}
fn watch(&self) -> ResultFuture<()> {
Err(MeliError::new("Unimplemented."))
}
fn mailboxes(&self) -> ResultFuture<HashMap<MailboxHash, Mailbox>> {
Err(MeliError::new("Unimplemented."))
}
mailbox_hash: MailboxHash,
) -> Result<Pin<Box<dyn Stream<Item = Result<Vec<Envelope>>> + Send + 'static>>>;
fn refresh(&mut self, mailbox_hash: MailboxHash) -> ResultFuture<()>;
fn watch(&self) -> ResultFuture<()>;
fn mailboxes(&self) -> ResultFuture<HashMap<MailboxHash, Mailbox>>;
fn operation(&self, hash: EnvelopeHash) -> Result<Box<dyn BackendOp>>;
fn save(
@ -362,10 +355,7 @@ pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
None
}
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any {
unimplemented!()
}
fn as_any_mut(&mut self) -> &mut dyn Any;
fn create_mailbox(
&mut self,
@ -553,65 +543,6 @@ pub trait BackendMailbox: Debug {
fn count(&self) -> Result<(usize, usize)>;
}
#[derive(Debug)]
struct DummyMailbox {
v: Vec<MailboxHash>,
}
impl BackendMailbox for DummyMailbox {
fn hash(&self) -> MailboxHash {
0
}
fn name(&self) -> &str {
""
}
fn path(&self) -> &str {
""
}
fn change_name(&mut self, _s: &str) {}
fn clone(&self) -> Mailbox {
mailbox_default()
}
fn special_usage(&self) -> SpecialUsageMailbox {
SpecialUsageMailbox::Normal
}
fn children(&self) -> &[MailboxHash] {
&self.v
}
fn parent(&self) -> Option<MailboxHash> {
None
}
fn permissions(&self) -> MailboxPermissions {
MailboxPermissions::default()
}
fn is_subscribed(&self) -> bool {
true
}
fn set_is_subscribed(&mut self, _new_val: bool) -> Result<()> {
Ok(())
}
fn set_special_usage(&mut self, _new_val: SpecialUsageMailbox) -> Result<()> {
Ok(())
}
fn count(&self) -> Result<(usize, usize)> {
Ok((0, 0))
}
}
pub fn mailbox_default() -> Mailbox {
Box::new(DummyMailbox {
v: Vec::with_capacity(0),
})
}
pub type AccountHash = u64;
pub type MailboxHash = u64;
pub type Mailbox = Box<dyn BackendMailbox + Send + Sync>;
@ -622,12 +553,6 @@ impl Clone for Mailbox {
}
}
impl Default for Mailbox {
fn default() -> Self {
mailbox_default()
}
}
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub struct MailboxPermissions {
pub create_messages: bool,

View File

@ -709,14 +709,6 @@ impl MailBackend for ImapType {
}))
}
fn as_any(&self) -> &dyn ::std::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn ::std::any::Any {
self
}
fn tags(&self) -> Option<Arc<RwLock<BTreeMap<u64, String>>>> {
if *self.can_create_flags.lock().unwrap() {
Some(self.uid_store.tag_index.clone())
@ -725,6 +717,14 @@ impl MailBackend for ImapType {
}
}
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn create_mailbox(
&mut self,
mut path: String,

View File

@ -242,10 +242,12 @@ impl MailBackend for JmapType {
}))
}
fn refresh(&mut self, _mailbox_hash: MailboxHash) -> ResultFuture<()> {
Err(MeliError::new("Unimplemented."))
}
fn watch(&self) -> ResultFuture<()> {
Ok(Box::pin(async move {
Err(MeliError::from("JMAP watch for updates is unimplemented"))
}))
Err(MeliError::from("JMAP watch for updates is unimplemented"))
}
fn mailboxes(&self) -> ResultFuture<HashMap<MailboxHash, Mailbox>> {
@ -288,12 +290,16 @@ impl MailBackend for JmapType {
Err(MeliError::new("Unimplemented."))
}
fn as_any(&self) -> &dyn ::std::any::Any {
fn tags(&self) -> Option<Arc<RwLock<BTreeMap<u64, String>>>> {
Some(self.tag_index.clone())
}
fn as_any(&self) -> &dyn Any {
self
}
fn tags(&self) -> Option<Arc<RwLock<BTreeMap<u64, String>>>> {
Some(self.tag_index.clone())
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn search(

View File

@ -812,10 +812,6 @@ impl MailBackend for MaildirType {
}))
}
fn as_any(&self) -> &dyn ::std::any::Any {
self
}
fn create_mailbox(
&mut self,
new_path: String,
@ -892,6 +888,14 @@ impl MailBackend for MaildirType {
) -> ResultFuture<()> {
Err(MeliError::new("Unimplemented."))
}
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
impl MaildirType {

View File

@ -808,6 +808,10 @@ impl MailBackend for MboxType {
}))
}
fn refresh(&mut self, _mailbox_hash: MailboxHash) -> ResultFuture<()> {
Err(MeliError::new("Unimplemented."))
}
fn watch(&self) -> ResultFuture<()> {
let sender = self.event_consumer.clone();
let (tx, rx) = channel();
@ -1004,7 +1008,11 @@ impl MailBackend for MboxType {
Err(MeliError::new("Unimplemented."))
}
fn as_any(&self) -> &dyn ::std::any::Any {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}

View File

@ -298,18 +298,18 @@ impl MailBackend for NntpType {
Err(MeliError::new("Unimplemented."))
}
fn as_any(&self) -> &dyn ::std::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn ::std::any::Any {
self
}
fn tags(&self) -> Option<Arc<RwLock<BTreeMap<u64, String>>>> {
None
}
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn create_mailbox(
&mut self,
_path: String,

View File

@ -462,6 +462,13 @@ impl MailBackend for NotmuchDb {
}))
}
fn refresh(&mut self, _mailbox_hash: MailboxHash) -> ResultFuture<()> {
Err(MeliError::new("Unimplemented."))
}
fn watch(&self) -> ResultFuture<()> {
Err(MeliError::new("Unimplemented."))
}
/*
fn watch(&self) -> ResultFuture<()> {
extern crate notify;
@ -835,12 +842,16 @@ impl MailBackend for NotmuchDb {
Ok(Box::pin(async { Ok(()) }))
}
fn as_any(&self) -> &dyn ::std::any::Any {
fn tags(&self) -> Option<Arc<RwLock<BTreeMap<u64, String>>>> {
Some(self.tag_index.clone())
}
fn as_any(&self) -> &dyn Any {
self
}
fn tags(&self) -> Option<Arc<RwLock<BTreeMap<u64, String>>>> {
Some(self.tag_index.clone())
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}

View File

@ -233,7 +233,7 @@ impl State {
let input_thread = unbounded();
let input_thread_pipe = nix::unistd::pipe()
.map_err(|err| Box::new(err) as Box<dyn std::error::Error + Send + Sync + 'static>)?;
let mut backends = Backends::new();
let backends = Backends::new();
let settings = if let Some(settings) = settings {
settings
} else {