Browse Source

melib/imap: build uid<>msn cache in {select,examine}_mailbox()

master
Manos Pitsidianakis 2 years ago
parent
commit
be2d268a20
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 1
      melib/src/backends/imap/cache/sync.rs
  2. 29
      melib/src/backends/imap/connection.rs
  3. 16
      melib/src/backends/imap/untagged.rs

1
melib/src/backends/imap/cache/sync.rs

@ -686,7 +686,6 @@ impl ImapConnection {
)
};
self.create_uid_msn_cache(mailbox_hash, 1).await?;
/* first SELECT the mailbox to get READ/WRITE permissions (because EXAMINE only
* returns READ-ONLY for both cases) */
let mut select_response = self

29
melib/src/backends/imap/connection.rs

@ -771,6 +771,18 @@ impl ImapConnection {
permissions.delete_messages = !select_response.read_only;
}
self.stream.as_mut()?.current_mailbox = MailboxSelection::Select(mailbox_hash);
if self
.uid_store
.msn_index
.lock()
.unwrap()
.get(&mailbox_hash)
.map(|i| i.is_empty())
.unwrap_or(true)
{
self.create_uid_msn_cache(mailbox_hash, 1, &select_response)
.await?;
}
Ok(Some(select_response))
}
@ -798,6 +810,18 @@ impl ImapConnection {
debug!("examine response {}", ret);
let select_response = protocol_parser::select_response(&ret)?;
self.stream.as_mut()?.current_mailbox = MailboxSelection::Examine(mailbox_hash);
if !self
.uid_store
.msn_index
.lock()
.unwrap()
.get(&mailbox_hash)
.map(|i| i.is_empty())
.unwrap_or(true)
{
self.create_uid_msn_cache(mailbox_hash, 1, &select_response)
.await?;
}
Ok(Some(select_response))
}
@ -853,15 +877,14 @@ impl ImapConnection {
);
}
pub async fn create_uid_msn_cache(
async fn create_uid_msn_cache(
&mut self,
mailbox_hash: MailboxHash,
low: usize,
_select_response: &SelectResponse,
) -> Result<()> {
debug_assert!(low > 0);
let mut response = String::new();
self.examine_mailbox(mailbox_hash, &mut response, false)
.await?;
self.send_command(format!("UID SEARCH {}:*", low).as_bytes())
.await?;
self.read_response(&mut response, RequiredResponses::SEARCH)

16
melib/src/backends/imap/untagged.rs

@ -73,6 +73,22 @@ impl ImapConnection {
(std::time::Instant::now(), Err(reason.into()));
}
UntaggedResponse::Expunge(n) => {
if self
.uid_store
.msn_index
.lock()
.unwrap()
.get(&mailbox_hash)
.map(|i| i.len() < n)
.unwrap_or(true)
{
debug!(
"Received expunge {} but mailbox msn index is {:?}",
n,
self.uid_store.msn_index.lock().unwrap().get(&mailbox_hash)
);
return Ok(true);
}
let deleted_uid = self
.uid_store
.msn_index

Loading…
Cancel
Save