MailBackend: add is_{async,online} methods

async
Manos Pitsidianakis 2020-07-05 19:11:57 +03:00
parent 94e0aa4fe7
commit 231471fa8c
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
8 changed files with 59 additions and 0 deletions

View File

@ -297,6 +297,8 @@ impl NotifyFn {
pub type ResultFuture<T> = Result<Pin<Box<dyn Future<Output = Result<T>> + Send + 'static>>>; pub type ResultFuture<T> = Result<Pin<Box<dyn Future<Output = Result<T>> + Send + 'static>>>;
pub trait MailBackend: ::std::fmt::Debug + Send + Sync { pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
fn is_async(&self) -> bool;
fn is_remote(&self) -> bool;
fn is_online(&self) -> Result<()>; fn is_online(&self) -> Result<()>;
fn is_online_async(&self) -> ResultFuture<()> { fn is_online_async(&self) -> ResultFuture<()> {
Err(MeliError::new("Unimplemented.")) Err(MeliError::new("Unimplemented."))

View File

@ -185,6 +185,14 @@ pub(self) fn try_lock<T>(
} }
impl MailBackend for ImapType { impl MailBackend for ImapType {
fn is_async(&self) -> bool {
false
}
fn is_remote(&self) -> bool {
true
}
fn is_online(&self) -> Result<()> { fn is_online(&self) -> Result<()> {
//if let Ok(mut g) = try_lock(&self.connection, None) { //if let Ok(mut g) = try_lock(&self.connection, None) {
// let _ = g.connect(); // let _ = g.connect();

View File

@ -174,6 +174,12 @@ pub struct ImapType {
} }
impl MailBackend for ImapType { impl MailBackend for ImapType {
fn is_async(&self) -> bool {
true
}
fn is_remote(&self) -> bool {
true
}
fn get_async( fn get_async(
&mut self, &mut self,
mailbox: &Mailbox, mailbox: &Mailbox,

View File

@ -190,6 +190,14 @@ pub struct JmapType {
} }
impl MailBackend for JmapType { impl MailBackend for JmapType {
fn is_async(&self) -> bool {
false
}
fn is_remote(&self) -> bool {
true
}
fn is_online(&self) -> Result<()> { fn is_online(&self) -> Result<()> {
self.online.lock().unwrap().1.clone() self.online.lock().unwrap().1.clone()
} }

View File

@ -175,6 +175,14 @@ pub fn move_to_cur(p: PathBuf) -> Result<PathBuf> {
} }
impl MailBackend for MaildirType { impl MailBackend for MaildirType {
fn is_async(&self) -> bool {
false
}
fn is_remote(&self) -> bool {
false
}
fn is_online(&self) -> Result<()> { fn is_online(&self) -> Result<()> {
Ok(()) Ok(())
} }

View File

@ -647,6 +647,14 @@ pub struct MboxType {
} }
impl MailBackend for MboxType { impl MailBackend for MboxType {
fn is_async(&self) -> bool {
false
}
fn is_remote(&self) -> bool {
false
}
fn is_online(&self) -> Result<()> { fn is_online(&self) -> Result<()> {
Ok(()) Ok(())
} }

View File

@ -318,9 +318,18 @@ impl NotmuchDb {
} }
impl MailBackend for NotmuchDb { impl MailBackend for NotmuchDb {
fn is_async(&self) -> bool {
false
}
fn is_remote(&self) -> bool {
false
}
fn is_online(&self) -> Result<()> { fn is_online(&self) -> Result<()> {
Ok(()) Ok(())
} }
fn get(&mut self, mailbox: &Mailbox) -> Result<Async<Result<Vec<Envelope>>>> { fn get(&mut self, mailbox: &Mailbox) -> Result<Async<Result<Vec<Envelope>>>> {
let mut w = AsyncBuilder::new(); let mut w = AsyncBuilder::new();
let mailbox_hash = mailbox.hash(); let mailbox_hash = mailbox.hash();

View File

@ -65,6 +65,16 @@ impl Drop for PluginBackend {
} }
impl MailBackend for PluginBackend { impl MailBackend for PluginBackend {
fn is_async(&self) -> bool {
// TODO
false
}
fn is_remote(&self) -> bool {
// TODO
false
}
fn is_online(&self) -> Result<()> { fn is_online(&self) -> Result<()> {
if let Ok(mut is_online) = self.is_online.try_lock() { if let Ok(mut is_online) = self.is_online.try_lock() {
let now = std::time::Instant::now(); let now = std::time::Instant::now();