melib/MailBackend: add connect() method
parent
10368612ab
commit
d2b4057b7b
|
@ -246,6 +246,7 @@ type NewFolderName = String;
|
|||
|
||||
pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
|
||||
fn is_online(&self) -> Result<()>;
|
||||
fn connect(&mut self) {}
|
||||
fn get(&mut self, folder: &Folder) -> Async<Result<Vec<Envelope>>>;
|
||||
fn watch(
|
||||
&self,
|
||||
|
|
|
@ -139,6 +139,17 @@ impl MailBackend for ImapType {
|
|||
fn is_online(&self) -> Result<()> {
|
||||
self.online.lock().unwrap().1.clone()
|
||||
}
|
||||
|
||||
fn connect(&mut self) {
|
||||
if self.is_online().is_err() {
|
||||
if Instant::now().duration_since(self.online.lock().unwrap().0)
|
||||
>= std::time::Duration::new(2, 0)
|
||||
{
|
||||
let _ = self.folders();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get(&mut self, folder: &Folder) -> Async<Result<Vec<Envelope>>> {
|
||||
macro_rules! exit_on_error {
|
||||
($tx:expr,$($result:expr)+) => {
|
||||
|
|
|
@ -196,6 +196,17 @@ impl MailBackend for JmapType {
|
|||
fn is_online(&self) -> Result<()> {
|
||||
self.online.lock().unwrap().1.clone()
|
||||
}
|
||||
|
||||
fn connect(&mut self) {
|
||||
if self.is_online().is_err() {
|
||||
if Instant::now().duration_since(self.online.lock().unwrap().0)
|
||||
>= std::time::Duration::new(2, 0)
|
||||
{
|
||||
let _ = self.folders();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get(&mut self, folder: &Folder) -> Async<Result<Vec<Envelope>>> {
|
||||
let mut w = AsyncBuilder::new();
|
||||
let folders = self.folders.clone();
|
||||
|
|
|
@ -992,6 +992,10 @@ impl Account {
|
|||
/* Call only in Context::is_online, since only Context can launch the watcher threads if an
|
||||
* account goes from offline to online. */
|
||||
pub fn is_online(&mut self) -> Result<()> {
|
||||
if !self.is_online {
|
||||
self.backend.write().unwrap().connect();
|
||||
}
|
||||
|
||||
let ret = self.backend.read().unwrap().is_online();
|
||||
if ret.is_ok() != self.is_online && ret.is_ok() {
|
||||
self.init();
|
||||
|
|
Loading…
Reference in New Issue