mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
refactor: accept &str instead of Option<String> in idle()
This commit is contained in:
@@ -19,7 +19,7 @@ impl Session {
|
|||||||
mut self,
|
mut self,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
idle_interrupt_receiver: Receiver<InterruptInfo>,
|
idle_interrupt_receiver: Receiver<InterruptInfo>,
|
||||||
watch_folder: Option<String>,
|
folder: &str,
|
||||||
) -> Result<(Self, InterruptInfo)> {
|
) -> Result<(Self, InterruptInfo)> {
|
||||||
use futures::future::FutureExt;
|
use futures::future::FutureExt;
|
||||||
|
|
||||||
@@ -33,13 +33,12 @@ impl Session {
|
|||||||
|
|
||||||
let mut info = Default::default();
|
let mut info = Default::default();
|
||||||
|
|
||||||
self.select_folder(context, watch_folder.as_deref()).await?;
|
self.select_folder(context, Some(folder)).await?;
|
||||||
|
|
||||||
if self.server_sent_unsolicited_exists(context)? {
|
if self.server_sent_unsolicited_exists(context)? {
|
||||||
return Ok((self, info));
|
return Ok((self, info));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(folder) = watch_folder.as_ref() {
|
|
||||||
// Despite checking for unsolicited EXISTS above,
|
// Despite checking for unsolicited EXISTS above,
|
||||||
// we may have missed EXISTS if the message was
|
// we may have missed EXISTS if the message was
|
||||||
// received when the folder was not selected.
|
// received when the folder was not selected.
|
||||||
@@ -62,7 +61,6 @@ impl Session {
|
|||||||
warn!(context, "STATUS {folder} (UIDNEXT) did not return UIDNEXT");
|
warn!(context, "STATUS {folder} (UIDNEXT) did not return UIDNEXT");
|
||||||
// Go to IDLE anyway if STATUS is broken.
|
// Go to IDLE anyway if STATUS is broken.
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(info) = idle_interrupt_receiver.try_recv() {
|
if let Ok(info) = idle_interrupt_receiver.try_recv() {
|
||||||
info!(context, "skip idle, got interrupt {:?}", info);
|
info!(context, "skip idle, got interrupt {:?}", info);
|
||||||
@@ -86,11 +84,7 @@ impl Session {
|
|||||||
Interrupt(InterruptInfo),
|
Interrupt(InterruptInfo),
|
||||||
}
|
}
|
||||||
|
|
||||||
let folder_name = watch_folder.as_deref().unwrap_or("None");
|
info!(context, "{folder}: Idle entering wait-on-remote state");
|
||||||
info!(
|
|
||||||
context,
|
|
||||||
"{}: Idle entering wait-on-remote state", folder_name
|
|
||||||
);
|
|
||||||
let fut = idle_wait.map(|ev| ev.map(Event::IdleResponse)).race(async {
|
let fut = idle_wait.map(|ev| ev.map(Event::IdleResponse)).race(async {
|
||||||
let info = idle_interrupt_receiver.recv().await;
|
let info = idle_interrupt_receiver.recv().await;
|
||||||
|
|
||||||
@@ -102,36 +96,27 @@ impl Session {
|
|||||||
|
|
||||||
match fut.await {
|
match fut.await {
|
||||||
Ok(Event::IdleResponse(IdleResponse::NewData(x))) => {
|
Ok(Event::IdleResponse(IdleResponse::NewData(x))) => {
|
||||||
info!(context, "{}: Idle has NewData {:?}", folder_name, x);
|
info!(context, "{folder}: Idle has NewData {:?}", x);
|
||||||
}
|
}
|
||||||
Ok(Event::IdleResponse(IdleResponse::Timeout)) => {
|
Ok(Event::IdleResponse(IdleResponse::Timeout)) => {
|
||||||
info!(
|
info!(context, "{folder}: Idle-wait timeout or interruption");
|
||||||
context,
|
|
||||||
"{}: Idle-wait timeout or interruption", folder_name
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Ok(Event::IdleResponse(IdleResponse::ManualInterrupt)) => {
|
Ok(Event::IdleResponse(IdleResponse::ManualInterrupt)) => {
|
||||||
info!(
|
info!(context, "{folder}: Idle wait was interrupted manually");
|
||||||
context,
|
|
||||||
"{}: Idle wait was interrupted manually", folder_name
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Ok(Event::Interrupt(i)) => {
|
Ok(Event::Interrupt(i)) => {
|
||||||
info!(
|
info!(context, "{folder}: Idle wait was interrupted: {:?}", &i);
|
||||||
context,
|
|
||||||
"{}: Idle wait was interrupted: {:?}", folder_name, &i
|
|
||||||
);
|
|
||||||
info = i;
|
info = i;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!(context, "{}: Idle wait errored: {:?}", folder_name, err);
|
warn!(context, "{folder}: Idle wait errored: {err:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut session = tokio::time::timeout(Duration::from_secs(15), handle.done())
|
let mut session = tokio::time::timeout(Duration::from_secs(15), handle.done())
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("{folder_name}: IMAP IDLE protocol timed out"))?
|
.with_context(|| format!("{folder}: IMAP IDLE protocol timed out"))?
|
||||||
.with_context(|| format!("{folder_name}: IMAP IDLE failed"))?;
|
.with_context(|| format!("{folder}: IMAP IDLE failed"))?;
|
||||||
session.as_mut().set_read_timeout(Some(IMAP_TIMEOUT));
|
session.as_mut().set_read_timeout(Some(IMAP_TIMEOUT));
|
||||||
self.inner = session;
|
self.inner = session;
|
||||||
|
|
||||||
|
|||||||
@@ -620,7 +620,7 @@ async fn fetch_idle(
|
|||||||
.idle(
|
.idle(
|
||||||
ctx,
|
ctx,
|
||||||
connection.idle_interrupt_receiver.clone(),
|
connection.idle_interrupt_receiver.clone(),
|
||||||
Some(watch_folder),
|
&watch_folder,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.context("idle")
|
.context("idle")
|
||||||
|
|||||||
Reference in New Issue
Block a user