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))
}
}
impl Session {
/// Retrieves server metadata if it is supported.
///
/// 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)
/// metadata.
pub(crate) async fn fetch_metadata(&mut self, context: &Context) -> Result<()> {
let session = self.session.as_mut().context("no session")?;
if !session.can_metadata() {
if !self.can_metadata() {
return Ok(());
}
@@ -1442,7 +1443,7 @@ impl Imap {
let mailbox = "";
let options = "";
let metadata = session
let metadata = self
.get_metadata(mailbox, options, "(/shared/comment /shared/admin)")
.await?;
for m in metadata {

View File

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