aboutsummaryrefslogtreecommitdiff
path: root/src/imap/mailbox_view.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-01-05 12:40:49 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-01-05 12:40:49 +0100
commit35591ff0608096b32d7bab22d719a6ceb8574c2c (patch)
tree362178f0c136610bfab3b1d6de867f0888aef4fa /src/imap/mailbox_view.rs
parentac8fb89d56351fbc0017b8a7a8a4ddf53217ab60 (diff)
downloadaerogramme-35591ff0608096b32d7bab22d719a6ceb8574c2c.tar.gz
aerogramme-35591ff0608096b32d7bab22d719a6ceb8574c2c.zip
search first ultra minimal implementation
Diffstat (limited to 'src/imap/mailbox_view.rs')
-rw-r--r--src/imap/mailbox_view.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs
index f5cf394..5311635 100644
--- a/src/imap/mailbox_view.rs
+++ b/src/imap/mailbox_view.rs
@@ -5,15 +5,18 @@ use anyhow::{anyhow, bail, 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::flag::{Flag, FlagFetch, FlagPerm, StoreResponse, StoreType};
use imap_codec::imap_types::response::{Code, Data, Status};
+use imap_codec::imap_types::search::SearchKey;
use imap_codec::imap_types::sequence::{self, SequenceSet};
use crate::imap::attributes::AttributesProxy;
use crate::imap::flags;
use crate::imap::mail_view::SeenFlag;
use crate::imap::response::Body;
+use crate::imap::search;
use crate::imap::selectors::MailSelectionBuilder;
use crate::mail::mailbox::Mailbox;
use crate::mail::uidindex::{ImapUid, ImapUidvalidity, UidIndex};
@@ -308,6 +311,7 @@ impl MailboxView {
.iter()
.filter_map(|mv| mv.filter(&ap).ok().map(|(body, seen)| (mv, body, seen)))
.collect::<Vec<_>>();
+
// Register seen flags
let future_flags = filtered_view
.iter()
@@ -333,6 +337,22 @@ impl MailboxView {
Ok(command_body)
}
+ /// A very naive search implementation...
+ pub async fn search<'a>(
+ &self,
+ _charset: &Option<Charset<'a>>,
+ search_key: &SearchKey<'a>,
+ uid: bool,
+ ) -> Result<Vec<Body<'static>>> {
+ let (seq_set, seq_type) = search::Criteria(search_key).to_sequence_set();
+ let mailids = MailIdentifiersList(self.get_mail_ids(&seq_set, seq_type.is_uid())?);
+ let mail_u32 = match uid {
+ true => mailids.uids(),
+ _ => mailids.ids(),
+ };
+ Ok(vec![Body::Data(Data::Search(mail_u32))])
+ }
+
// ----
// Gets the IMAP ID, the IMAP UIDs and, the Aerogramme UUIDs of mails identified by a SequenceSet of
@@ -525,6 +545,12 @@ pub struct MailIdentifiers {
pub struct MailIdentifiersList(Vec<MailIdentifiers>);
impl MailIdentifiersList {
+ fn ids(&self) -> Vec<NonZeroU32> {
+ self.0.iter().map(|mi| mi.i).collect()
+ }
+ fn uids(&self) -> Vec<ImapUid> {
+ self.0.iter().map(|mi| mi.uid).collect()
+ }
fn uuids(&self) -> Vec<UniqueIdent> {
self.0.iter().map(|mi| mi.uuid).collect()
}