MailBackend: add is_{async,online} methods
parent
94e0aa4fe7
commit
231471fa8c
|
@ -297,6 +297,8 @@ impl NotifyFn {
|
|||
pub type ResultFuture<T> = Result<Pin<Box<dyn Future<Output = Result<T>> + Send + 'static>>>;
|
||||
|
||||
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_async(&self) -> ResultFuture<()> {
|
||||
Err(MeliError::new("Unimplemented."))
|
||||
|
|
|
@ -185,6 +185,14 @@ pub(self) fn try_lock<T>(
|
|||
}
|
||||
|
||||
impl MailBackend for ImapType {
|
||||
fn is_async(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn is_remote(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn is_online(&self) -> Result<()> {
|
||||
//if let Ok(mut g) = try_lock(&self.connection, None) {
|
||||
// let _ = g.connect();
|
||||
|
|
|
@ -174,6 +174,12 @@ pub struct ImapType {
|
|||
}
|
||||
|
||||
impl MailBackend for ImapType {
|
||||
fn is_async(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn is_remote(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn get_async(
|
||||
&mut self,
|
||||
mailbox: &Mailbox,
|
||||
|
|
|
@ -190,6 +190,14 @@ pub struct JmapType {
|
|||
}
|
||||
|
||||
impl MailBackend for JmapType {
|
||||
fn is_async(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn is_remote(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn is_online(&self) -> Result<()> {
|
||||
self.online.lock().unwrap().1.clone()
|
||||
}
|
||||
|
|
|
@ -175,6 +175,14 @@ pub fn move_to_cur(p: PathBuf) -> Result<PathBuf> {
|
|||
}
|
||||
|
||||
impl MailBackend for MaildirType {
|
||||
fn is_async(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn is_remote(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn is_online(&self) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -647,6 +647,14 @@ pub struct MboxType {
|
|||
}
|
||||
|
||||
impl MailBackend for MboxType {
|
||||
fn is_async(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn is_remote(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn is_online(&self) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -318,9 +318,18 @@ impl NotmuchDb {
|
|||
}
|
||||
|
||||
impl MailBackend for NotmuchDb {
|
||||
fn is_async(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn is_remote(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn is_online(&self) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get(&mut self, mailbox: &Mailbox) -> Result<Async<Result<Vec<Envelope>>>> {
|
||||
let mut w = AsyncBuilder::new();
|
||||
let mailbox_hash = mailbox.hash();
|
||||
|
|
|
@ -65,6 +65,16 @@ impl Drop 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<()> {
|
||||
if let Ok(mut is_online) = self.is_online.try_lock() {
|
||||
let now = std::time::Instant::now();
|
||||
|
|
Loading…
Reference in New Issue