mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
fix: always exit fake IDLE after at most 60 seconds
Do not call `fetch_new_messages`, always exit and let the IMAP loop prepare the connection properly and run all pending tasks.
This commit is contained in:
@@ -9,7 +9,6 @@ use tokio::time::timeout;
|
|||||||
use super::session::Session;
|
use super::session::Session;
|
||||||
use super::Imap;
|
use super::Imap;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::imap::FolderMeaning;
|
|
||||||
use crate::net::TIMEOUT;
|
use crate::net::TIMEOUT;
|
||||||
use crate::tools::{self, time_elapsed};
|
use crate::tools::{self, time_elapsed};
|
||||||
|
|
||||||
@@ -109,37 +108,16 @@ impl Imap {
|
|||||||
pub(crate) async fn fake_idle(
|
pub(crate) async fn fake_idle(
|
||||||
&mut self,
|
&mut self,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
session: &mut Session,
|
|
||||||
watch_folder: String,
|
watch_folder: String,
|
||||||
folder_meaning: FolderMeaning,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let fake_idle_start_time = tools::Time::now();
|
let fake_idle_start_time = tools::Time::now();
|
||||||
|
|
||||||
info!(context, "IMAP-fake-IDLEing folder={:?}", watch_folder);
|
info!(context, "IMAP-fake-IDLEing folder={:?}", watch_folder);
|
||||||
|
|
||||||
// Loop until we are interrupted or until we fetch something.
|
// Wait for 60 seconds or until we are interrupted.
|
||||||
loop {
|
|
||||||
match timeout(Duration::from_secs(60), self.idle_interrupt_receiver.recv()).await {
|
match timeout(Duration::from_secs(60), self.idle_interrupt_receiver.recv()).await {
|
||||||
Err(_) => {
|
Err(_) => info!(context, "Fake IDLE finished."),
|
||||||
// Let's see if fetching messages results
|
Ok(_) => info!(context, "Fake IDLE interrupted."),
|
||||||
// in anything. If so, we behave as if IDLE had data but
|
|
||||||
// will have already fetched the messages so perform_*_fetch
|
|
||||||
// will not find any new.
|
|
||||||
let res = self
|
|
||||||
.fetch_new_messages(context, session, &watch_folder, folder_meaning, false)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
info!(context, "fetch_new_messages returned {:?}", res);
|
|
||||||
|
|
||||||
if res {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(_) => {
|
|
||||||
info!(context, "Fake IDLE interrupted.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
|
|||||||
@@ -655,9 +655,7 @@ async fn fetch_idle(
|
|||||||
ctx,
|
ctx,
|
||||||
"IMAP session does not support IDLE, going to fake idle."
|
"IMAP session does not support IDLE, going to fake idle."
|
||||||
);
|
);
|
||||||
connection
|
connection.fake_idle(ctx, watch_folder).await?;
|
||||||
.fake_idle(ctx, &mut session, watch_folder, folder_meaning)
|
|
||||||
.await?;
|
|
||||||
return Ok(session);
|
return Ok(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -669,9 +667,7 @@ async fn fetch_idle(
|
|||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
{
|
{
|
||||||
info!(ctx, "IMAP IDLE is disabled, going to fake idle.");
|
info!(ctx, "IMAP IDLE is disabled, going to fake idle.");
|
||||||
connection
|
connection.fake_idle(ctx, watch_folder).await?;
|
||||||
.fake_idle(ctx, &mut session, watch_folder, folder_meaning)
|
|
||||||
.await?;
|
|
||||||
return Ok(session);
|
return Ok(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user