refactor(imap): move fetch_metadata() to Session

This commit is contained in:
link2xt
2024-02-28 22:42:54 +00:00
parent 8b9f19be70
commit 30432d8fa5
2 changed files with 8 additions and 5 deletions

View File

@@ -1415,15 +1415,16 @@ impl Imap {
Ok((last_uid, received_msgs)) Ok((last_uid, received_msgs))
} }
}
impl Session {
/// Retrieves server metadata if it is supported. /// Retrieves server metadata if it is supported.
/// ///
/// We get [`/shared/comment`](https://www.rfc-editor.org/rfc/rfc5464#section-6.2.1) /// We get [`/shared/comment`](https://www.rfc-editor.org/rfc/rfc5464#section-6.2.1)
/// and [`/shared/admin`](https://www.rfc-editor.org/rfc/rfc5464#section-6.2.2) /// and [`/shared/admin`](https://www.rfc-editor.org/rfc/rfc5464#section-6.2.2)
/// metadata. /// metadata.
pub(crate) async fn fetch_metadata(&mut self, context: &Context) -> Result<()> { pub(crate) async fn fetch_metadata(&mut self, context: &Context) -> Result<()> {
let session = self.session.as_mut().context("no session")?; if !self.can_metadata() {
if !session.can_metadata() {
return Ok(()); return Ok(());
} }
@@ -1442,7 +1443,7 @@ impl Imap {
let mailbox = ""; let mailbox = "";
let options = ""; let options = "";
let metadata = session let metadata = self
.get_metadata(mailbox, options, "(/shared/comment /shared/admin)") .get_metadata(mailbox, options, "(/shared/comment /shared/admin)")
.await?; .await?;
for m in metadata { for m in metadata {

View File

@@ -473,9 +473,11 @@ async fn inbox_loop(
warn!(ctx, "Failed to download messages: {:#}", err); warn!(ctx, "Failed to download messages: {:#}", err);
} }
if let Err(err) = connection.fetch_metadata(&ctx).await { if let Some(session) = connection.session.as_mut() {
if let Err(err) = session.fetch_metadata(&ctx).await {
warn!(ctx, "Failed to fetch metadata: {err:#}."); warn!(ctx, "Failed to fetch metadata: {err:#}.");
} }
}
fetch_idle(&ctx, &mut connection, FolderMeaning::Inbox).await; fetch_idle(&ctx, &mut connection, FolderMeaning::Inbox).await;
} }