melib/MailBackend: add connect() method

memfd
Manos Pitsidianakis 2019-12-14 18:55:08 +02:00
parent 10368612ab
commit d2b4057b7b
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
4 changed files with 27 additions and 0 deletions

View File

@ -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,

View File

@ -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)+) => {

View File

@ -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();

View File

@ -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();