aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-01-08 11:14:34 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-01-08 11:14:34 +0100
commit72f9a221ed2318d8ca3452b6574c900be923d3d5 (patch)
treebc2701eabcd6c86a3cc5ade0483e788b5113de49
parent558e32fbd27be9a81144571b4baf318293be1344 (diff)
downloadaerogramme-72f9a221ed2318d8ca3452b6574c900be923d3d5.tar.gz
aerogramme-72f9a221ed2318d8ca3452b6574c900be923d3d5.zip
Formatting & tests
-rw-r--r--src/imap/index.rs40
-rw-r--r--src/imap/mail_view.rs5
-rw-r--r--src/imap/mailbox_view.rs2
3 files changed, 36 insertions, 11 deletions
diff --git a/src/imap/index.rs b/src/imap/index.rs
index 9adf8b2..3ca5562 100644
--- a/src/imap/index.rs
+++ b/src/imap/index.rs
@@ -6,7 +6,7 @@ use imap_codec::imap_types::sequence::{self, SeqOrUid, Sequence, SequenceSet};
use crate::mail::uidindex::{ImapUid, UidIndex};
use crate::mail::unique_ident::UniqueIdent;
-pub struct Index<'a> {
+pub struct Index<'a> {
pub imap_index: Vec<MailIndex<'a>>,
pub internal: &'a UidIndex,
}
@@ -17,19 +17,32 @@ impl<'a> Index<'a> {
.iter()
.enumerate()
.map(|(i_enum, (&uid, &uuid))| {
- let flags = internal.table.get(&uuid).ok_or(anyhow!("mail is missing from index"))?.1.as_ref();
+ let flags = internal
+ .table
+ .get(&uuid)
+ .ok_or(anyhow!("mail is missing from index"))?
+ .1
+ .as_ref();
let i_int: u32 = (i_enum + 1).try_into()?;
let i: NonZeroU32 = i_int.try_into()?;
- Ok(MailIndex { i, uid, uuid, flags })
+ Ok(MailIndex {
+ i,
+ uid,
+ uuid,
+ flags,
+ })
})
.collect::<Result<Vec<_>>>()?;
- Ok(Self { imap_index, internal })
+ Ok(Self {
+ imap_index,
+ internal,
+ })
}
pub fn last(&'a self) -> Option<&'a MailIndex<'a>> {
- self.imap_index.last()
+ self.imap_index.last()
}
/// Fetch mail descriptors based on a sequence of UID
@@ -62,10 +75,15 @@ impl<'a> Index<'a> {
// Quickly jump to the right point in the mailbox vector O(log m) instead
// of iterating one by one O(m). Works only because both unroll_seq & imap_index are sorted per uid.
let mut imap_idx = {
- let start_idx = self.imap_index.partition_point(|mail_idx| &mail_idx.uid < start_seq);
+ let start_idx = self
+ .imap_index
+ .partition_point(|mail_idx| &mail_idx.uid < start_seq);
&self.imap_index[start_idx..]
};
- println!("win: {:?}", imap_idx.iter().map(|midx| midx.uid).collect::<Vec<_>>());
+ println!(
+ "win: {:?}",
+ imap_idx.iter().map(|midx| midx.uid).collect::<Vec<_>>()
+ );
let mut acc = vec![];
for wanted_uid in unroll_seq.iter() {
@@ -91,10 +109,14 @@ impl<'a> Index<'a> {
};
sequence_set
.iter(iter_strat)
- .map(|wanted_id| self.imap_index.get((wanted_id.get() as usize) - 1).ok_or(anyhow!("Mail not found")))
+ .map(|wanted_id| {
+ self.imap_index
+ .get((wanted_id.get() as usize) - 1)
+ .ok_or(anyhow!("Mail not found"))
+ })
.collect::<Result<Vec<_>>>()
}
-
+
pub fn fetch(
self: &'a Index<'a>,
sequence_set: &SequenceSet,
diff --git a/src/imap/mail_view.rs b/src/imap/mail_view.rs
index 8dd68b5..7da21c4 100644
--- a/src/imap/mail_view.rs
+++ b/src/imap/mail_view.rs
@@ -32,7 +32,10 @@ pub struct MailView<'a> {
}
impl<'a> MailView<'a> {
- pub fn new(query_result: &'a QueryResult<'a>, in_idx: &'a MailIndex<'a>) -> Result<MailView<'a>> {
+ pub fn new(
+ query_result: &'a QueryResult<'a>,
+ in_idx: &'a MailIndex<'a>,
+ ) -> Result<MailView<'a>> {
Ok(Self {
in_idx,
query_result,
diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs
index 62ea6d2..77fe7f7 100644
--- a/src/imap/mailbox_view.rs
+++ b/src/imap/mailbox_view.rs
@@ -526,7 +526,7 @@ mod tests {
content: rfc822.to_vec(),
};
- let mv = MailView::new(&qr, mail_in_idx)?;
+ let mv = MailView::new(&qr, &mail_in_idx)?;
let (res_body, _seen) = mv.filter(&ap)?;
let fattr = match res_body {