melib/backends: cleanup MailBackend trait definition
parent
3eadaba34e
commit
94433cfc40
|
@ -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 {
|
pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
|
||||||
fn capabilities(&self) -> MailBackendCapabilities;
|
fn capabilities(&self) -> MailBackendCapabilities;
|
||||||
fn is_online(&self) -> ResultFuture<()> {
|
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(
|
fn fetch(
|
||||||
&mut self,
|
&mut self,
|
||||||
_mailbox_hash: MailboxHash,
|
mailbox_hash: MailboxHash,
|
||||||
) -> Result<Pin<Box<dyn Stream<Item = Result<Vec<Envelope>>> + Send + 'static>>> {
|
) -> Result<Pin<Box<dyn Stream<Item = Result<Vec<Envelope>>> + Send + 'static>>>;
|
||||||
Err(MeliError::new("Unimplemented."))
|
|
||||||
}
|
fn refresh(&mut self, mailbox_hash: MailboxHash) -> ResultFuture<()>;
|
||||||
fn refresh(&mut self, _mailbox_hash: MailboxHash) -> ResultFuture<()> {
|
fn watch(&self) -> ResultFuture<()>;
|
||||||
Err(MeliError::new("Unimplemented."))
|
fn mailboxes(&self) -> ResultFuture<HashMap<MailboxHash, Mailbox>>;
|
||||||
}
|
|
||||||
fn watch(&self) -> ResultFuture<()> {
|
|
||||||
Err(MeliError::new("Unimplemented."))
|
|
||||||
}
|
|
||||||
fn mailboxes(&self) -> ResultFuture<HashMap<MailboxHash, Mailbox>> {
|
|
||||||
Err(MeliError::new("Unimplemented."))
|
|
||||||
}
|
|
||||||
fn operation(&self, hash: EnvelopeHash) -> Result<Box<dyn BackendOp>>;
|
fn operation(&self, hash: EnvelopeHash) -> Result<Box<dyn BackendOp>>;
|
||||||
|
|
||||||
fn save(
|
fn save(
|
||||||
|
@ -362,10 +355,7 @@ pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn as_any(&self) -> &dyn Any;
|
fn as_any(&self) -> &dyn Any;
|
||||||
|
fn as_any_mut(&mut self) -> &mut dyn Any;
|
||||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn create_mailbox(
|
fn create_mailbox(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -553,65 +543,6 @@ pub trait BackendMailbox: Debug {
|
||||||
fn count(&self) -> Result<(usize, usize)>;
|
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 AccountHash = u64;
|
||||||
pub type MailboxHash = u64;
|
pub type MailboxHash = u64;
|
||||||
pub type Mailbox = Box<dyn BackendMailbox + Send + Sync>;
|
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)]
|
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
||||||
pub struct MailboxPermissions {
|
pub struct MailboxPermissions {
|
||||||
pub create_messages: bool,
|
pub create_messages: bool,
|
||||||
|
|
|
@ -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>>>> {
|
fn tags(&self) -> Option<Arc<RwLock<BTreeMap<u64, String>>>> {
|
||||||
if *self.can_create_flags.lock().unwrap() {
|
if *self.can_create_flags.lock().unwrap() {
|
||||||
Some(self.uid_store.tag_index.clone())
|
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(
|
fn create_mailbox(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut path: String,
|
mut path: String,
|
||||||
|
|
|
@ -242,10 +242,12 @@ impl MailBackend for JmapType {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn refresh(&mut self, _mailbox_hash: MailboxHash) -> ResultFuture<()> {
|
||||||
|
Err(MeliError::new("Unimplemented."))
|
||||||
|
}
|
||||||
|
|
||||||
fn watch(&self) -> ResultFuture<()> {
|
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>> {
|
fn mailboxes(&self) -> ResultFuture<HashMap<MailboxHash, Mailbox>> {
|
||||||
|
@ -288,12 +290,16 @@ impl MailBackend for JmapType {
|
||||||
Err(MeliError::new("Unimplemented."))
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tags(&self) -> Option<Arc<RwLock<BTreeMap<u64, String>>>> {
|
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||||
Some(self.tag_index.clone())
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search(
|
fn search(
|
||||||
|
|
|
@ -812,10 +812,6 @@ impl MailBackend for MaildirType {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_any(&self) -> &dyn ::std::any::Any {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn create_mailbox(
|
fn create_mailbox(
|
||||||
&mut self,
|
&mut self,
|
||||||
new_path: String,
|
new_path: String,
|
||||||
|
@ -892,6 +888,14 @@ impl MailBackend for MaildirType {
|
||||||
) -> ResultFuture<()> {
|
) -> ResultFuture<()> {
|
||||||
Err(MeliError::new("Unimplemented."))
|
Err(MeliError::new("Unimplemented."))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn as_any(&self) -> &dyn Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MaildirType {
|
impl MaildirType {
|
||||||
|
|
|
@ -808,6 +808,10 @@ impl MailBackend for MboxType {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn refresh(&mut self, _mailbox_hash: MailboxHash) -> ResultFuture<()> {
|
||||||
|
Err(MeliError::new("Unimplemented."))
|
||||||
|
}
|
||||||
|
|
||||||
fn watch(&self) -> ResultFuture<()> {
|
fn watch(&self) -> ResultFuture<()> {
|
||||||
let sender = self.event_consumer.clone();
|
let sender = self.event_consumer.clone();
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
|
@ -1004,7 +1008,11 @@ impl MailBackend for MboxType {
|
||||||
Err(MeliError::new("Unimplemented."))
|
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
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,18 +298,18 @@ impl MailBackend for NntpType {
|
||||||
Err(MeliError::new("Unimplemented."))
|
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>>>> {
|
fn tags(&self) -> Option<Arc<RwLock<BTreeMap<u64, String>>>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn as_any(&self) -> &dyn Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
fn create_mailbox(
|
fn create_mailbox(
|
||||||
&mut self,
|
&mut self,
|
||||||
_path: String,
|
_path: String,
|
||||||
|
|
|
@ -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<()> {
|
fn watch(&self) -> ResultFuture<()> {
|
||||||
extern crate notify;
|
extern crate notify;
|
||||||
|
@ -835,12 +842,16 @@ impl MailBackend for NotmuchDb {
|
||||||
Ok(Box::pin(async { Ok(()) }))
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tags(&self) -> Option<Arc<RwLock<BTreeMap<u64, String>>>> {
|
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||||
Some(self.tag_index.clone())
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -233,7 +233,7 @@ impl State {
|
||||||
let input_thread = unbounded();
|
let input_thread = unbounded();
|
||||||
let input_thread_pipe = nix::unistd::pipe()
|
let input_thread_pipe = nix::unistd::pipe()
|
||||||
.map_err(|err| Box::new(err) as Box<dyn std::error::Error + Send + Sync + 'static>)?;
|
.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 {
|
let settings = if let Some(settings) = settings {
|
||||||
settings
|
settings
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue