melib/imap: update online instant only on server read IO

master
Manos Pitsidianakis 2020-09-11 00:15:11 +03:00
parent 1751509739
commit d00055fdb1
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 7 additions and 13 deletions

View File

@ -521,17 +521,17 @@ impl ImapConnection {
Box::pin(async move { Box::pin(async move {
if let (instant, ref mut status @ Ok(())) = *self.uid_store.is_online.lock().unwrap() { 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) { if Instant::now().duration_since(instant) >= Duration::new(60 * 30, 0) {
*status = Err(MeliError::new("Connection timed out")); let err = MeliError::new("Connection timed out").set_kind(ErrorKind::Timeout);
self.stream = Err(MeliError::new("Connection timed out")); *status = Err(err.clone());
self.stream = Err(err);
} }
} }
if self.stream.is_ok() { if self.stream.is_ok() {
self.uid_store.is_online.lock().unwrap().0 = Instant::now();
return Ok(()); return Ok(());
} }
let new_stream = debug!(ImapStream::new_connection(&self.server_conf).await); let new_stream = debug!(ImapStream::new_connection(&self.server_conf).await);
if let Err(err) = new_stream.as_ref() { 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 { } else {
*self.uid_store.is_online.lock().unwrap() = (Instant::now(), Ok(())); *self.uid_store.is_online.lock().unwrap() = (Instant::now(), Ok(()));
} }
@ -616,6 +616,7 @@ impl ImapConnection {
let mut response = String::new(); let mut response = String::new();
ret.clear(); ret.clear();
self.stream.as_mut()?.read_response(&mut response).await?; self.stream.as_mut()?.read_response(&mut response).await?;
*self.uid_store.is_online.lock().unwrap() = (Instant::now(), Ok(()));
match self.server_conf.protocol { match self.server_conf.protocol {
ImapProtocol::IMAP { .. } => { ImapProtocol::IMAP { .. } => {

View File

@ -31,17 +31,13 @@ use crate::backends::{
use crate::email::Envelope; use crate::email::Envelope;
use crate::error::*; use crate::error::*;
use std::convert::TryInto; use std::convert::TryInto;
use std::time::Instant;
impl ImapConnection { impl ImapConnection {
pub async fn process_untagged(&mut self, line: &str) -> Result<bool> { pub async fn process_untagged(&mut self, line: &str) -> Result<bool> {
macro_rules! try_fail { macro_rules! try_fail {
($mailbox_hash: expr, $($result:expr)+) => { ($mailbox_hash: expr, $($result:expr)+) => {
$(if let Err(err) = $result { $(if let Err(err) = $result {
*self.uid_store.is_online.lock().unwrap() = ( self.uid_store.is_online.lock().unwrap().1 = Err(err.clone());
Instant::now(),
Err(err.clone()),
);
debug!("failure: {}", err.to_string()); debug!("failure: {}", err.to_string());
self.add_refresh_event(RefreshEvent { self.add_refresh_event(RefreshEvent {
account_hash: self.uid_store.account_hash, account_hash: self.uid_store.account_hash,
@ -73,8 +69,7 @@ impl ImapConnection {
}; };
match untagged_response { match untagged_response {
UntaggedResponse::Bye { reason } => { UntaggedResponse::Bye { reason } => {
*self.uid_store.is_online.lock().unwrap() = self.uid_store.is_online.lock().unwrap().1 = Err(reason.into());
(std::time::Instant::now(), Err(reason.into()));
} }
UntaggedResponse::Expunge(n) => { UntaggedResponse::Expunge(n) => {
if self if self

View File

@ -180,7 +180,6 @@ pub async fn idle(kit: ImapWatchKit) -> Result<()> {
} }
blockn.conn.send_command(b"IDLE").await?; blockn.conn.send_command(b"IDLE").await?;
} }
*uid_store.is_online.lock().unwrap() = (Instant::now(), Ok(()));
} }
debug!("IDLE connection dropped"); debug!("IDLE connection dropped");
let err: &str = blockn.err().unwrap_or("Unknown reason."); 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) .examine_mailbox(mailbox_hash, &mut response, true)
.await? .await?
.unwrap(); .unwrap();
*uid_store.is_online.lock().unwrap() = (Instant::now(), Ok(()));
debug!(&select_response); debug!(&select_response);
{ {
let mut uidvalidities = uid_store.uidvalidity.lock().unwrap(); let mut uidvalidities = uid_store.uidvalidity.lock().unwrap();