aboutsummaryrefslogtreecommitdiff
path: root/src/imap
diff options
context:
space:
mode:
Diffstat (limited to 'src/imap')
-rw-r--r--src/imap/index.rs11
-rw-r--r--src/imap/mail_view.rs4
-rw-r--r--src/imap/mailbox_view.rs5
-rw-r--r--src/imap/search.rs2
4 files changed, 14 insertions, 8 deletions
diff --git a/src/imap/index.rs b/src/imap/index.rs
index f9228fe..4853374 100644
--- a/src/imap/index.rs
+++ b/src/imap/index.rs
@@ -104,16 +104,21 @@ impl<'a> Index<'a> {
return Ok(vec![]);
}
let iter_strat = sequence::Strategy::Naive {
- largest: self.last().expect("The mailbox is not empty").uid,
+ largest: NonZeroU32::try_from(self.imap_index.len() as u32)?,
};
- sequence_set
+ let mut acc = sequence_set
.iter(iter_strat)
.map(|wanted_id| {
self.imap_index
.get((wanted_id.get() as usize) - 1)
.ok_or(anyhow!("Mail not found"))
})
- .collect::<Result<Vec<_>>>()
+ .collect::<Result<Vec<_>>>()?;
+
+ // Sort the result to be consistent with UID
+ acc.sort_by(|a, b| a.i.cmp(&b.i));
+
+ Ok(acc)
}
pub fn fetch(
diff --git a/src/imap/mail_view.rs b/src/imap/mail_view.rs
index 879166d..a593b1a 100644
--- a/src/imap/mail_view.rs
+++ b/src/imap/mail_view.rs
@@ -27,13 +27,13 @@ use crate::imap::response::Body;
pub struct MailView<'a> {
pub in_idx: &'a MailIndex<'a>,
- pub query_result: &'a QueryResult<'a>,
+ pub query_result: &'a QueryResult,
pub content: FetchedMail<'a>,
}
impl<'a> MailView<'a> {
pub fn new(
- query_result: &'a QueryResult<'a>,
+ query_result: &'a QueryResult,
in_idx: &'a MailIndex<'a>,
) -> Result<MailView<'a>> {
Ok(Self {
diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs
index 027947f..513567f 100644
--- a/src/imap/mailbox_view.rs
+++ b/src/imap/mailbox_view.rs
@@ -1,7 +1,7 @@
use std::num::NonZeroU32;
use std::sync::Arc;
-use anyhow::{anyhow, Context, Error, Result};
+use anyhow::{anyhow, Error, Result};
use futures::stream::{FuturesOrdered, StreamExt};
@@ -259,6 +259,7 @@ impl MailboxView {
true => QueryScope::Full,
_ => QueryScope::Partial,
};
+ tracing::debug!("Query scope {:?}", query_scope);
let idx = self.index()?;
let mail_idx_list = idx.fetch(sequence_set, *is_uid_fetch)?;
@@ -544,7 +545,6 @@ mod tests {
let rfc822 = b"Subject: hello\r\nFrom: a@a.a\r\nTo: b@b.b\r\nDate: Thu, 12 Oct 2023 08:45:28 +0000\r\n\r\nhello world";
let qr = QueryResult::FullResult {
uuid: mail_in_idx.uuid.clone(),
- index: &index_entry,
metadata: meta,
content: rfc822.to_vec(),
};
@@ -619,6 +619,7 @@ mod tests {
seq: NonZeroU32::new(1).unwrap(),
items: NonEmptyVec::from(MessageDataItem::Body(mime_view::bodystructure(
&message.child,
+ false,
)?)),
});
let test_bytes = ResponseCodec::new().encode(&test_repr).dump();
diff --git a/src/imap/search.rs b/src/imap/search.rs
index 22afd0c..c4888d0 100644
--- a/src/imap/search.rs
+++ b/src/imap/search.rs
@@ -134,7 +134,7 @@ impl<'a> Criteria<'a> {
pub fn filter_on_query<'b>(
&self,
midx_list: &[&'b MailIndex<'b>],
- query_result: &'b Vec<QueryResult<'b>>,
+ query_result: &'b Vec<QueryResult>,
) -> Result<Vec<&'b MailIndex<'b>>> {
Ok(midx_list
.iter()