Browse Source

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

master
Manos Pitsidianakis 2 years ago
parent
commit
d00055fdb1
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 9
      melib/src/backends/imap/connection.rs
  2. 9
      melib/src/backends/imap/untagged.rs
  3. 2
      melib/src/backends/imap/watch.rs

9
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 { .. } => {

9
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

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

Loading…
Cancel
Save