diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2020-09-11 00:15:11 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2020-09-11 17:02:27 +0300 |
commit | d00055fdb12690818a8997c24fc125f7937eb6ca (patch) | |
tree | df0989a7e0356fe6d32c2cceebddf545b6160c0a /melib/src/backends | |
parent | 1751509739a6e6aaa986759a315b937e832c94d3 (diff) |
melib/imap: update online instant only on server read IO
Diffstat (limited to 'melib/src/backends')
-rw-r--r-- | melib/src/backends/imap/connection.rs | 9 | ||||
-rw-r--r-- | melib/src/backends/imap/untagged.rs | 9 | ||||
-rw-r--r-- | melib/src/backends/imap/watch.rs | 2 |
3 files changed, 7 insertions, 13 deletions
diff --git a/melib/src/backends/imap/connection.rs b/melib/src/backends/imap/connection.rs index a9c010ff..444e2b1f 100644 --- a/melib/src/backends/imap/connection.rs +++ b/melib/src/backends/imap/connection.rs @@ -521,17 +521,17 @@ impl ImapConnection { Box::pin(async move { if let (instant, ref mut status @ Ok(())) = *self.uid_store.is_online.lock().unwrap() { if Instant::now().duration_since(instant) >= Duration::new(60 * 30, 0) { - *status = Err(MeliError::new("Connection timed out")); - self.stream = Err(MeliError::new("Connection timed out")); + let err = MeliError::new("Connection timed out").set_kind(ErrorKind::Timeout); + *status = Err(err.clone()); + self.stream = Err(err); } } if self.stream.is_ok() { - self.uid_store.is_online.lock().unwrap().0 = Instant::now(); return Ok(()); } let new_stream = debug!(ImapStream::new_connection(&self.server_conf).await); if let Err(err) = new_stream.as_ref() { - *self.uid_store.is_online.lock().unwrap() = (Instant::now(), Err(err.clone())); + self.uid_store.is_online.lock().unwrap().1 = Err(err.clone()); } else { *self.uid_store.is_online.lock().unwrap() = (Instant::now(), Ok(())); } @@ -616,6 +616,7 @@ impl ImapConnection { let mut response = String::new(); ret.clear(); self.stream.as_mut()?.read_response(&mut response).await?; + *self.uid_store.is_online.lock().unwrap() = (Instant::now(), Ok(())); match self.server_conf.protocol { ImapProtocol::IMAP { .. } => { diff --git a/melib/src/backends/imap/untagged.rs b/melib/src/backends/imap/untagged.rs index 6f32c2b2..38f7fb2e 100644 --- a/melib/src/backends/imap/untagged.rs +++ b/melib/src/backends/imap/untagged.rs @@ -31,17 +31,13 @@ use crate::backends::{ use crate::email::Envelope; use crate::error::*; use std::convert::TryInto; -use std::time::Instant; impl ImapConnection { pub async fn process_untagged(&mut self, line: &str) -> Result<bool> { macro_rules! try_fail { ($mailbox_hash: expr, $($result:expr)+) => { $(if let Err(err) = $result { - *self.uid_store.is_online.lock().unwrap() = ( - Instant::now(), - Err(err.clone()), - ); + self.uid_store.is_online.lock().unwrap().1 = Err(err.clone()); debug!("failure: {}", err.to_string()); self.add_refresh_event(RefreshEvent { account_hash: self.uid_store.account_hash, @@ -73,8 +69,7 @@ impl ImapConnection { }; match untagged_response { UntaggedResponse::Bye { reason } => { - *self.uid_store.is_online.lock().unwrap() = - (std::time::Instant::now(), Err(reason.into())); + self.uid_store.is_online.lock().unwrap().1 = Err(reason.into()); } UntaggedResponse::Expunge(n) => { if self diff --git a/melib/src/backends/imap/watch.rs b/melib/src/backends/imap/watch.rs index 1a28e8b0..dfa220bd 100644 --- a/melib/src/backends/imap/watch.rs +++ b/melib/src/backends/imap/watch.rs @@ -180,7 +180,6 @@ pub async fn idle(kit: ImapWatchKit) -> Result<()> { } blockn.conn.send_command(b"IDLE").await?; } - *uid_store.is_online.lock().unwrap() = (Instant::now(), Ok(())); } debug!("IDLE connection dropped"); let err: &str = blockn.err().unwrap_or("Unknown reason."); @@ -222,7 +221,6 @@ pub async fn examine_updates( .examine_mailbox(mailbox_hash, &mut response, true) .await? .unwrap(); - *uid_store.is_online.lock().unwrap() = (Instant::now(), Ok(())); debug!(&select_response); { let mut uidvalidities = uid_store.uidvalidity.lock().unwrap(); |