Add folder name to IMAP IDLE interrupt logs

This commit is contained in:
link2xt
2022-11-13 16:08:50 +00:00
parent 33839b5667
commit 4744f5eecf

View File

@@ -54,10 +54,10 @@ impl Imap {
Interrupt(InterruptInfo), Interrupt(InterruptInfo),
} }
let folder_name = watch_folder.as_deref().unwrap_or("None");
info!( info!(
context, context,
"{}: Idle entering wait-on-remote state", "{}: Idle entering wait-on-remote state", folder_name
watch_folder.as_deref().unwrap_or("None")
); );
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 = self.idle_interrupt.recv().await; let info = self.idle_interrupt.recv().await;
@@ -70,26 +70,35 @@ impl Imap {
match fut.await { match fut.await {
Ok(Event::IdleResponse(IdleResponse::NewData(x))) => { Ok(Event::IdleResponse(IdleResponse::NewData(x))) => {
info!(context, "Idle has NewData {:?}", x); info!(context, "{}: Idle has NewData {:?}", folder_name, x);
} }
Ok(Event::IdleResponse(IdleResponse::Timeout)) => { Ok(Event::IdleResponse(IdleResponse::Timeout)) => {
info!(context, "Idle-wait timeout or interruption"); info!(
context,
"{}: Idle-wait timeout or interruption", folder_name
);
} }
Ok(Event::IdleResponse(IdleResponse::ManualInterrupt)) => { Ok(Event::IdleResponse(IdleResponse::ManualInterrupt)) => {
info!(context, "Idle wait was interrupted"); info!(
context,
"{}: Idle wait was interrupted manually", folder_name
);
} }
Ok(Event::Interrupt(i)) => { Ok(Event::Interrupt(i)) => {
info!(
context,
"{}: Idle wait was interrupted: {:?}", folder_name, &i
);
info = i; info = i;
info!(context, "Idle wait was interrupted");
} }
Err(err) => { Err(err) => {
warn!(context, "Idle wait errored: {:?}", err); warn!(context, "{}: Idle wait errored: {:?}", folder_name, err);
} }
} }
let session = tokio::time::timeout(Duration::from_secs(15), handle.done()) let session = tokio::time::timeout(Duration::from_secs(15), handle.done())
.await? .await?
.context("IMAP IDLE protocol timed out")?; .with_context(|| format!("{}: IMAP IDLE protocol timed out", folder_name))?;
self.session = Some(Session { inner: session }); self.session = Some(Session { inner: session });
} else { } else {
warn!(context, "Attempted to idle without a session"); warn!(context, "Attempted to idle without a session");