From 5dfa02e381154c03adee33262e247797d9a2f8ff Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 9 Jan 2024 16:53:32 +0100 Subject: Disable UNSEEN again as it was a volunteer decision to not implement it --- src/imap/mailbox_view.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/imap/mailbox_view.rs') diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs index 513567f..e9f85a6 100644 --- a/src/imap/mailbox_view.rs +++ b/src/imap/mailbox_view.rs @@ -130,8 +130,8 @@ impl MailboxView { data.extend(self.flags_status()?.into_iter()); data.push(self.uidvalidity_status()?); data.push(self.uidnext_status()?); - self.unseen_first_status()? - .map(|unseen_status| data.push(unseen_status)); + /*self.unseen_first_status()? + .map(|unseen_status| data.push(unseen_status));*/ Ok(data) } @@ -403,6 +403,7 @@ impl MailboxView { Ok(Body::Data(Data::Recent(self.recent()?))) } + #[allow(dead_code)] fn unseen_first_status(&self) -> Result>> { Ok(self .unseen_first()? @@ -412,6 +413,7 @@ impl MailboxView { .transpose()?) } + #[allow(dead_code)] fn unseen_first(&self) -> Result> { Ok(self .0 -- cgit v1.2.3 From 6e798b90f590e21bb68535f0431fc547e5e2390c Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 9 Jan 2024 17:40:23 +0100 Subject: prepare condstore --- src/imap/mailbox_view.rs | 71 ++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 27 deletions(-) (limited to 'src/imap/mailbox_view.rs') diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs index e9f85a6..046acfa 100644 --- a/src/imap/mailbox_view.rs +++ b/src/imap/mailbox_view.rs @@ -8,7 +8,7 @@ use futures::stream::{FuturesOrdered, StreamExt}; use imap_codec::imap_types::core::Charset; use imap_codec::imap_types::fetch::{MacroOrMessageDataItemNames, MessageDataItem}; use imap_codec::imap_types::flag::{Flag, FlagFetch, FlagPerm, StoreResponse, StoreType}; -use imap_codec::imap_types::response::{Code, Data, Status}; +use imap_codec::imap_types::response::{Code, CodeOther, Data, Status}; use imap_codec::imap_types::search::SearchKey; use imap_codec::imap_types::sequence::SequenceSet; @@ -39,12 +39,18 @@ const DEFAULT_FLAGS: [Flag; 5] = [ /// To do this, it keeps a variable `known_state` that corresponds to /// what the client knows, and produces IMAP messages to be sent to the /// client that go along updates to `known_state`. -pub struct MailboxView(pub FrozenMailbox); +pub struct MailboxView { + pub internal: FrozenMailbox, + pub is_condstore: bool, +} impl MailboxView { /// Creates a new IMAP view into a mailbox. - pub async fn new(mailbox: Arc) -> Self { - Self(mailbox.frozen().await) + pub async fn new(mailbox: Arc, is_cond: bool) -> Self { + Self { + internal: mailbox.frozen().await, + is_condstore: is_cond, + } } /// Create an updated view, useful to make a diff @@ -54,8 +60,8 @@ impl MailboxView { /// This does NOT trigger a sync, it bases itself on what is currently /// loaded in RAM by Bayou. pub async fn update(&mut self) -> Result>> { - let old_snapshot = self.0.update().await; - let new_snapshot = &self.0.snapshot; + let old_snapshot = self.internal.update().await; + let new_snapshot = &self.internal.snapshot; let mut data = Vec::::new(); @@ -130,6 +136,9 @@ impl MailboxView { data.extend(self.flags_status()?.into_iter()); data.push(self.uidvalidity_status()?); data.push(self.uidnext_status()?); + if self.is_condstore { + data.push(self.highestmodseq_status()?); + } /*self.unseen_first_status()? .map(|unseen_status| data.push(unseen_status));*/ @@ -144,7 +153,7 @@ impl MailboxView { flags: &[Flag<'a>], is_uid_store: &bool, ) -> Result>> { - self.0.sync().await?; + self.internal.sync().await?; let flags = flags.iter().map(|x| x.to_string()).collect::>(); @@ -153,13 +162,13 @@ impl MailboxView { for mi in mails.iter() { match kind { StoreType::Add => { - self.0.mailbox.add_flags(mi.uuid, &flags[..]).await?; + self.internal.mailbox.add_flags(mi.uuid, &flags[..]).await?; } StoreType::Remove => { - self.0.mailbox.del_flags(mi.uuid, &flags[..]).await?; + self.internal.mailbox.del_flags(mi.uuid, &flags[..]).await?; } StoreType::Replace => { - self.0.mailbox.set_flags(mi.uuid, &flags[..]).await?; + self.internal.mailbox.set_flags(mi.uuid, &flags[..]).await?; } } } @@ -169,8 +178,8 @@ impl MailboxView { } pub async fn expunge(&mut self) -> Result>> { - self.0.sync().await?; - let state = self.0.peek().await; + self.internal.sync().await?; + let state = self.internal.peek().await; let deleted_flag = Flag::Deleted.to_string(); let msgs = state @@ -180,7 +189,7 @@ impl MailboxView { .map(|(uuid, _)| *uuid); for msg in msgs { - self.0.mailbox.delete(msg).await?; + self.internal.mailbox.delete(msg).await?; } self.update().await @@ -197,7 +206,7 @@ impl MailboxView { let mut new_uuids = vec![]; for mi in mails.iter() { - new_uuids.push(to.copy_from(&self.0.mailbox, mi.uuid).await?); + new_uuids.push(to.copy_from(&self.internal.mailbox, mi.uuid).await?); } let mut ret = vec![]; @@ -224,7 +233,7 @@ impl MailboxView { let mails = idx.fetch(sequence_set, *is_uid_copy)?; for mi in mails.iter() { - to.move_from(&self.0.mailbox, mi.uuid).await?; + to.move_from(&self.internal.mailbox, mi.uuid).await?; } let mut ret = vec![]; @@ -268,7 +277,7 @@ impl MailboxView { .iter() .map(|midx| midx.uuid) .collect::>(); - let query_result = self.0.query(&uuids, query_scope).fetch().await?; + let query_result = self.internal.query(&uuids, query_scope).fetch().await?; // [3/6] Derive an IMAP-specific view from the results, apply the filters let views = query_result @@ -294,7 +303,7 @@ impl MailboxView { .filter(|(_mv, seen)| matches!(seen, SeenFlag::MustAdd)) .map(|(mv, _seen)| async move { let seen_flag = Flag::Seen.to_string(); - self.0 + self.internal .mailbox .add_flags(*mv.query_result.uuid(), &[seen_flag]) .await?; @@ -332,7 +341,7 @@ impl MailboxView { // 4. Fetch additional info about the emails let query_scope = crit.query_scope(); let uuids = to_fetch.iter().map(|midx| midx.uuid).collect::>(); - let query_result = self.0.query(&uuids, query_scope).fetch().await?; + let query_result = self.internal.query(&uuids, query_scope).fetch().await?; // 5. If needed, filter the selection based on the body let kept_query = crit.filter_on_query(&to_fetch, &query_result)?; @@ -354,7 +363,7 @@ impl MailboxView { /// It's not trivial to refactor the code to do that, so we are doing /// some useless computation for now... fn index<'a>(&'a self) -> Result> { - Index::new(&self.0.snapshot) + Index::new(&self.internal.snapshot) } /// Produce an OK [UIDVALIDITY _] message corresponding to `known_state` @@ -369,7 +378,7 @@ impl MailboxView { } pub(crate) fn uidvalidity(&self) -> ImapUidvalidity { - self.0.snapshot.uidvalidity + self.internal.snapshot.uidvalidity } /// Produce an OK [UIDNEXT _] message corresponding to `known_state` @@ -384,7 +393,15 @@ impl MailboxView { } pub(crate) fn uidnext(&self) -> ImapUid { - self.0.snapshot.uidnext + self.internal.snapshot.uidnext + } + + pub(crate) fn highestmodseq_status(&self) -> Result> { + Ok(Body::Status(Status::ok( + None, + Some(Code::Other(CodeOther::unvalidated(format!("HIGHESTMODSEQ {}", 0).into_bytes()))), + "Highest", + )?)) } /// Produce an EXISTS message corresponding to the number of mails @@ -394,7 +411,7 @@ impl MailboxView { } pub(crate) fn exists(&self) -> Result { - Ok(u32::try_from(self.0.snapshot.idx_by_uid.len())?) + Ok(u32::try_from(self.internal.snapshot.idx_by_uid.len())?) } /// Produce a RECENT message corresponding to the number of @@ -416,7 +433,7 @@ impl MailboxView { #[allow(dead_code)] fn unseen_first(&self) -> Result> { Ok(self - .0 + .internal .snapshot .table .values() @@ -428,7 +445,7 @@ impl MailboxView { pub(crate) fn recent(&self) -> Result { let recent = self - .0 + .internal .snapshot .idx_by_flag .get(&"\\Recent".to_string()) @@ -445,7 +462,7 @@ impl MailboxView { // 1. Collecting all the possible flags in the mailbox // 1.a Fetch them from our index let mut known_flags: Vec = self - .0 + .internal .snapshot .idx_by_flag .flags() @@ -485,9 +502,9 @@ impl MailboxView { } pub(crate) fn unseen_count(&self) -> usize { - let total = self.0.snapshot.table.len(); + let total = self.internal.snapshot.table.len(); let seen = self - .0 + .internal .snapshot .idx_by_flag .get(&Flag::Seen.to_string()) -- cgit v1.2.3 From 51510c97f7b76a73a2032eb089552cf9a13e9274 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 10 Jan 2024 12:55:38 +0100 Subject: fix some logic error in the internals --- src/imap/mailbox_view.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/imap/mailbox_view.rs') diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs index 046acfa..90cfc70 100644 --- a/src/imap/mailbox_view.rs +++ b/src/imap/mailbox_view.rs @@ -108,7 +108,7 @@ impl MailboxView { let old_mail = old_snapshot.table.get(uuid); let new_mail = new_snapshot.table.get(uuid); if old_mail.is_some() && old_mail != new_mail { - if let Some((uid, flags)) = new_mail { + if let Some((uid, _modseq, flags)) = new_mail { data.push(Body::Data(Data::Fetch { seq: NonZeroU32::try_from((i + 1) as u32).unwrap(), items: vec![ @@ -185,7 +185,7 @@ impl MailboxView { let msgs = state .table .iter() - .filter(|(_uuid, (_uid, flags))| flags.iter().any(|x| *x == deleted_flag)) + .filter(|(_uuid, (_uid, _modseq, flags))| flags.iter().any(|x| *x == deleted_flag)) .map(|(uuid, _)| *uuid); for msg in msgs { @@ -438,7 +438,7 @@ impl MailboxView { .table .values() .enumerate() - .find(|(_i, (_imap_uid, flags))| !flags.contains(&"\\Seen".to_string())) + .find(|(_i, (_imap_uid, _modseq, flags))| !flags.contains(&"\\Seen".to_string())) .map(|(i, _)| NonZeroU32::try_from(i as u32 + 1)) .transpose()?) } -- cgit v1.2.3 From 20193aa023b3f6a6d24d8127f1d8dcb81a43aa3b Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 10 Jan 2024 13:59:43 +0100 Subject: Return highestmodseq in select+examine --- src/imap/mailbox_view.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/imap/mailbox_view.rs') diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs index 90cfc70..a3d56f0 100644 --- a/src/imap/mailbox_view.rs +++ b/src/imap/mailbox_view.rs @@ -399,7 +399,7 @@ impl MailboxView { pub(crate) fn highestmodseq_status(&self) -> Result> { Ok(Body::Status(Status::ok( None, - Some(Code::Other(CodeOther::unvalidated(format!("HIGHESTMODSEQ {}", 0).into_bytes()))), + Some(Code::Other(CodeOther::unvalidated(format!("HIGHESTMODSEQ {}", self.internal.snapshot.highestmodseq).into_bytes()))), "Highest", )?)) } -- cgit v1.2.3 From 9cec7803d28617f1bfd1ac1621c2eda9582201d4 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 10 Jan 2024 17:07:07 +0100 Subject: Implement HIGHESTMODSEQ for STATUS --- src/imap/mailbox_view.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/imap/mailbox_view.rs') diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs index a3d56f0..b3848b2 100644 --- a/src/imap/mailbox_view.rs +++ b/src/imap/mailbox_view.rs @@ -15,7 +15,7 @@ use imap_codec::imap_types::sequence::SequenceSet; use crate::mail::mailbox::Mailbox; use crate::mail::query::QueryScope; use crate::mail::snapshot::FrozenMailbox; -use crate::mail::uidindex::{ImapUid, ImapUidvalidity}; +use crate::mail::uidindex::{ImapUid, ImapUidvalidity, ModSeq}; use crate::imap::attributes::AttributesProxy; use crate::imap::flags; @@ -399,11 +399,15 @@ impl MailboxView { pub(crate) fn highestmodseq_status(&self) -> Result> { Ok(Body::Status(Status::ok( None, - Some(Code::Other(CodeOther::unvalidated(format!("HIGHESTMODSEQ {}", self.internal.snapshot.highestmodseq).into_bytes()))), + Some(Code::Other(CodeOther::unvalidated(format!("HIGHESTMODSEQ {}", self.highestmodseq()).into_bytes()))), "Highest", )?)) } + pub(crate) fn highestmodseq(&self) -> ModSeq { + self.internal.snapshot.highestmodseq + } + /// Produce an EXISTS message corresponding to the number of mails /// in `known_state` fn exists_status(&self) -> Result> { -- cgit v1.2.3 From f4cbf665496640f4ac7cf4ac63ab2beced674978 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 10 Jan 2024 18:38:21 +0100 Subject: Fecth MODSEQ now enables the CONDSTORE capability --- src/imap/mailbox_view.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/imap/mailbox_view.rs') diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs index b3848b2..61beed5 100644 --- a/src/imap/mailbox_view.rs +++ b/src/imap/mailbox_view.rs @@ -259,7 +259,7 @@ impl MailboxView { sequence_set: &SequenceSet, attributes: &'b MacroOrMessageDataItemNames<'static>, is_uid_fetch: &bool, - ) -> Result>> { + ) -> Result<(Vec>, bool)> { // [1/6] Pre-compute data // a. what are the uuids of the emails we want? // b. do we need to fetch the full body? @@ -316,7 +316,7 @@ impl MailboxView { .collect::>()?; // [6/6] Build the final result that will be sent to the client. - Ok(imap_ret) + Ok((imap_ret, ap.is_enabling_condstore())) } /// A naive search implementation... -- cgit v1.2.3 From fbf2e9aa9670c991f5384350b2c78ad38dc3baf8 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 11 Jan 2024 11:48:02 +0100 Subject: Enable CONDSTORE if SEARCH MODSEQ is queried --- src/imap/mailbox_view.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/imap/mailbox_view.rs') diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs index 61beed5..ecdd745 100644 --- a/src/imap/mailbox_view.rs +++ b/src/imap/mailbox_view.rs @@ -325,7 +325,7 @@ impl MailboxView { _charset: &Option>, search_key: &SearchKey<'a>, uid: bool, - ) -> Result>> { + ) -> Result<(Vec>, bool)> { // 1. Compute the subset of sequence identifiers we need to fetch // based on the search query let crit = search::Criteria(search_key); @@ -354,7 +354,10 @@ impl MailboxView { _ => final_selection.map(|in_idx| in_idx.i).collect(), }; - Ok(vec![Body::Data(Data::Search(selection_fmt))]) + // 7. Add the modseq entry if needed + let is_modseq = crit.is_modseq(); + + Ok((vec![Body::Data(Data::Search(selection_fmt))], is_modseq)) } // ---- -- cgit v1.2.3 From a9d33c67080fd08b057501c36a07fade351bd83d Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 11 Jan 2024 11:55:40 +0100 Subject: MODSEQ is now returned on non empty search results --- src/imap/mailbox_view.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/imap/mailbox_view.rs') diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs index ecdd745..9e9e785 100644 --- a/src/imap/mailbox_view.rs +++ b/src/imap/mailbox_view.rs @@ -1,4 +1,4 @@ -use std::num::NonZeroU32; +use std::num::{NonZeroU32, NonZeroU64}; use std::sync::Arc; use anyhow::{anyhow, Error, Result}; @@ -348,7 +348,7 @@ impl MailboxView { // 6. Format the result according to the client's taste: // either return UID or ID. - let final_selection = kept_idx.into_iter().chain(kept_query.into_iter()); + let final_selection = kept_idx.iter().chain(kept_query.iter()); let selection_fmt = match uid { true => final_selection.map(|in_idx| in_idx.uid).collect(), _ => final_selection.map(|in_idx| in_idx.i).collect(), @@ -356,8 +356,15 @@ impl MailboxView { // 7. Add the modseq entry if needed let is_modseq = crit.is_modseq(); + let maybe_modseq = match is_modseq { + true => { + let final_selection = kept_idx.iter().chain(kept_query.iter()); + final_selection.map(|in_idx| in_idx.modseq).max().map(|r| NonZeroU64::try_from(r)).transpose()? + }, + _ => None, + }; - Ok((vec![Body::Data(Data::Search(selection_fmt))], is_modseq)) + Ok((vec![Body::Data(Data::Search(selection_fmt, maybe_modseq))], is_modseq)) } // ---- -- cgit v1.2.3 From d24eb9918e3ab0c69af05c8cb92424ecaba903f3 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 11 Jan 2024 17:13:59 +0100 Subject: Enable CONDSTORE on STORE/FETCH modifier --- src/imap/mailbox_view.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/imap/mailbox_view.rs') diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs index 9e9e785..c3900cf 100644 --- a/src/imap/mailbox_view.rs +++ b/src/imap/mailbox_view.rs @@ -6,7 +6,7 @@ use anyhow::{anyhow, Error, Result}; use futures::stream::{FuturesOrdered, StreamExt}; use imap_codec::imap_types::core::Charset; -use imap_codec::imap_types::fetch::{MacroOrMessageDataItemNames, MessageDataItem}; +use imap_codec::imap_types::fetch::MessageDataItem; use imap_codec::imap_types::flag::{Flag, FlagFetch, FlagPerm, StoreResponse, StoreType}; use imap_codec::imap_types::response::{Code, CodeOther, Data, Status}; use imap_codec::imap_types::search::SearchKey; @@ -257,13 +257,13 @@ impl MailboxView { pub async fn fetch<'b>( &self, sequence_set: &SequenceSet, - attributes: &'b MacroOrMessageDataItemNames<'static>, + ap: &AttributesProxy, is_uid_fetch: &bool, - ) -> Result<(Vec>, bool)> { + ) -> Result>> { // [1/6] Pre-compute data // a. what are the uuids of the emails we want? // b. do we need to fetch the full body? - let ap = AttributesProxy::new(attributes, *is_uid_fetch); + //let ap = AttributesProxy::new(attributes, *is_uid_fetch); let query_scope = match ap.need_body() { true => QueryScope::Full, _ => QueryScope::Partial, @@ -316,7 +316,7 @@ impl MailboxView { .collect::>()?; // [6/6] Build the final result that will be sent to the client. - Ok((imap_ret, ap.is_enabling_condstore())) + Ok(imap_ret) } /// A naive search implementation... -- cgit v1.2.3 From 3c7186ab5ac5a66f782a038d937b6679780df458 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 11 Jan 2024 23:02:03 +0100 Subject: Finalize implementation of CONDSTORE --- src/imap/mailbox_view.rs | 91 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 18 deletions(-) (limited to 'src/imap/mailbox_view.rs') diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs index c3900cf..683e209 100644 --- a/src/imap/mailbox_view.rs +++ b/src/imap/mailbox_view.rs @@ -1,5 +1,6 @@ use std::num::{NonZeroU32, NonZeroU64}; use std::sync::Arc; +use std::collections::HashSet; use anyhow::{anyhow, Error, Result}; @@ -12,6 +13,7 @@ use imap_codec::imap_types::response::{Code, CodeOther, Data, Status}; use imap_codec::imap_types::search::SearchKey; use imap_codec::imap_types::sequence::SequenceSet; +use crate::mail::unique_ident::UniqueIdent; use crate::mail::mailbox::Mailbox; use crate::mail::query::QueryScope; use crate::mail::snapshot::FrozenMailbox; @@ -32,6 +34,21 @@ const DEFAULT_FLAGS: [Flag; 5] = [ Flag::Draft, ]; +pub struct UpdateParameters { + pub silence: HashSet, + pub with_modseq: bool, + pub with_uid: bool, +} +impl Default for UpdateParameters { + fn default() -> Self { + Self { + silence: HashSet::new(), + with_modseq: false, + with_uid: false, + } + } +} + /// A MailboxView is responsible for giving the client the information /// it needs about a mailbox, such as an initial summary of the mailbox's /// content and continuous updates indicating when the content @@ -59,7 +76,7 @@ impl MailboxView { /// what the client knows and what is actually in the mailbox. /// This does NOT trigger a sync, it bases itself on what is currently /// loaded in RAM by Bayou. - pub async fn update(&mut self) -> Result>> { + pub async fn update(&mut self, params: UpdateParameters) -> Result>> { let old_snapshot = self.internal.update().await; let new_snapshot = &self.internal.snapshot; @@ -105,19 +122,31 @@ impl MailboxView { } else { // - if flags changed for existing mails, tell client for (i, (_uid, uuid)) in new_snapshot.idx_by_uid.iter().enumerate() { + if params.silence.contains(uuid) { + continue; + } + let old_mail = old_snapshot.table.get(uuid); let new_mail = new_snapshot.table.get(uuid); if old_mail.is_some() && old_mail != new_mail { - if let Some((uid, _modseq, flags)) = new_mail { + if let Some((uid, modseq, flags)) = new_mail { + let mut items = vec![ + MessageDataItem::Flags( + flags.iter().filter_map(|f| flags::from_str(f)).collect(), + ), + ]; + + if params.with_uid { + items.push(MessageDataItem::Uid(*uid)); + } + + if params.with_modseq { + items.push(MessageDataItem::ModSeq(*modseq)); + } + data.push(Body::Data(Data::Fetch { seq: NonZeroU32::try_from((i + 1) as u32).unwrap(), - items: vec![ - MessageDataItem::Uid(*uid), - MessageDataItem::Flags( - flags.iter().filter_map(|f| flags::from_str(f)).collect(), - ), - ] - .try_into()?, + items: items.try_into()?, })); } } @@ -149,17 +178,20 @@ impl MailboxView { &mut self, sequence_set: &SequenceSet, kind: &StoreType, - _response: &StoreResponse, + response: &StoreResponse, flags: &[Flag<'a>], + unchanged_since: Option, is_uid_store: &bool, - ) -> Result>> { + ) -> Result<(Vec>, Vec)> { self.internal.sync().await?; let flags = flags.iter().map(|x| x.to_string()).collect::>(); let idx = self.index()?; - let mails = idx.fetch(sequence_set, *is_uid_store)?; - for mi in mails.iter() { + let (editable, in_conflict) = idx + .fetch_unchanged_since(sequence_set, unchanged_since, *is_uid_store)?; + + for mi in editable.iter() { match kind { StoreType::Add => { self.internal.mailbox.add_flags(mi.uuid, &flags[..]).await?; @@ -173,8 +205,23 @@ impl MailboxView { } } - // @TODO: handle _response - self.update().await + let silence = match response { + StoreResponse::Answer => HashSet::new(), + StoreResponse::Silent => editable.iter().map(|midx| midx.uuid).collect(), + }; + + let conflict_id_or_uid = match is_uid_store { + true => in_conflict.into_iter().map(|midx| midx.uid).collect(), + _ => in_conflict.into_iter().map(|midx| midx.i).collect(), + }; + + let summary = self.update(UpdateParameters { + with_uid: *is_uid_store, + with_modseq: unchanged_since.is_some(), + silence, + }).await?; + + Ok((summary, conflict_id_or_uid)) } pub async fn expunge(&mut self) -> Result>> { @@ -192,7 +239,7 @@ impl MailboxView { self.internal.mailbox.delete(msg).await?; } - self.update().await + self.update(UpdateParameters::default()).await } pub async fn copy( @@ -247,7 +294,10 @@ impl MailboxView { ret.push((mi.uid, dest_uid)); } - let update = self.update().await?; + let update = self.update(UpdateParameters { + with_uid: *is_uid_copy, + ..UpdateParameters::default() + }).await?; Ok((to_state.uidvalidity, ret, update)) } @@ -258,6 +308,7 @@ impl MailboxView { &self, sequence_set: &SequenceSet, ap: &AttributesProxy, + changed_since: Option, is_uid_fetch: &bool, ) -> Result>> { // [1/6] Pre-compute data @@ -270,7 +321,11 @@ impl MailboxView { }; tracing::debug!("Query scope {:?}", query_scope); let idx = self.index()?; - let mail_idx_list = idx.fetch(sequence_set, *is_uid_fetch)?; + let mail_idx_list = idx.fetch_changed_since( + sequence_set, + changed_since, + *is_uid_fetch + )?; // [2/6] Fetch the emails let uuids = mail_idx_list -- cgit v1.2.3 From 69632879865bb351373c86daa1585942b8505618 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 12 Jan 2024 09:54:58 +0100 Subject: Fix unit tests --- src/imap/mailbox_view.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/imap/mailbox_view.rs') diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs index 683e209..07fa3ad 100644 --- a/src/imap/mailbox_view.rs +++ b/src/imap/mailbox_view.rs @@ -612,6 +612,7 @@ mod tests { peek: false, }, ]), + &[], false, ); @@ -623,12 +624,13 @@ mod tests { rfc822_size: 8usize, }; - let index_entry = (NonZeroU32::MIN, vec![]); + let index_entry = (NonZeroU32::MIN, NonZeroU64::MIN, vec![]); let mail_in_idx = MailIndex { i: NonZeroU32::MIN, uid: index_entry.0, + modseq: index_entry.1, uuid: unique_ident::gen_ident(), - flags: &index_entry.1, + flags: &index_entry.2, }; 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 { -- cgit v1.2.3