aboutsummaryrefslogtreecommitdiff
path: root/src/mail
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-01-06 11:33:56 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-01-06 11:33:56 +0100
commit53dbf82cbce3cb17cbcffd09558677faf8702f54 (patch)
treeb78cca747e5c2bc004cb93b93536623f7abb6ef5 /src/mail
parent1ca6cd5de0656910213425e1d8f05256af820f21 (diff)
downloadaerogramme-53dbf82cbce3cb17cbcffd09558677faf8702f54.tar.gz
aerogramme-53dbf82cbce3cb17cbcffd09558677faf8702f54.zip
Format code again
Diffstat (limited to 'src/mail')
-rw-r--r--src/mail/mod.rs2
-rw-r--r--src/mail/query.rs56
-rw-r--r--src/mail/snapshot.rs16
3 files changed, 48 insertions, 26 deletions
diff --git a/src/mail/mod.rs b/src/mail/mod.rs
index 7371b53..1836052 100644
--- a/src/mail/mod.rs
+++ b/src/mail/mod.rs
@@ -3,8 +3,8 @@ use std::io::Write;
pub mod incoming;
pub mod mailbox;
-pub mod snapshot;
pub mod query;
+pub mod snapshot;
pub mod uidindex;
pub mod unique_ident;
pub mod user;
diff --git a/src/mail/query.rs b/src/mail/query.rs
index 7b26cb9..8de73e6 100644
--- a/src/mail/query.rs
+++ b/src/mail/query.rs
@@ -1,13 +1,13 @@
-use anyhow::{Result, anyhow};
use super::mailbox::MailMeta;
use super::snapshot::FrozenMailbox;
-use super::unique_ident::UniqueIdent;
use super::uidindex::IndexEntry;
+use super::unique_ident::UniqueIdent;
+use anyhow::{anyhow, Result};
use futures::stream::{FuturesUnordered, StreamExt};
/// Query is in charge of fetching efficiently
/// requested data for a list of emails
-pub struct Query<'a,'b> {
+pub struct Query<'a, 'b> {
pub frozen: &'a FrozenMailbox,
pub emails: &'b [UniqueIdent],
pub scope: QueryScope,
@@ -20,7 +20,7 @@ pub enum QueryScope {
Full,
}
-impl<'a,'b> Query<'a,'b> {
+impl<'a, 'b> Query<'a, 'b> {
pub async fn fetch(&self) -> Result<Vec<QueryResult<'a>>> {
match self.scope {
QueryScope::Index => self.index(),
@@ -32,12 +32,10 @@ impl<'a,'b> Query<'a,'b> {
// --- functions below are private *for reasons*
fn index(&self) -> Result<Vec<QueryResult<'a>>> {
- self
- .emails
+ self.emails
.iter()
.map(|uuid| {
- self
- .frozen
+ self.frozen
.snapshot
.table
.get(uuid)
@@ -52,7 +50,11 @@ impl<'a,'b> Query<'a,'b> {
let result = meta
.into_iter()
.zip(self.index()?)
- .map(|(metadata, index)| index.into_partial(metadata).expect("index to be IndexResult"))
+ .map(|(metadata, index)| {
+ index
+ .into_partial(metadata)
+ .expect("index to be IndexResult")
+ })
.collect::<Vec<_>>();
Ok(result)
}
@@ -65,11 +67,18 @@ impl<'a,'b> Query<'a,'b> {
let meta_list = self.partial().await?;
meta_list
.into_iter()
- .map(|meta| async move {
- let content = self.frozen.mailbox.fetch_full(
- *meta.uuid(),
- &meta.metadata().expect("meta to be PartialResult").message_key
- ).await?;
+ .map(|meta| async move {
+ let content = self
+ .frozen
+ .mailbox
+ .fetch_full(
+ *meta.uuid(),
+ &meta
+ .metadata()
+ .expect("meta to be PartialResult")
+ .message_key,
+ )
+ .await?;
Ok(meta.into_full(content).expect("meta to be PartialResult"))
})
@@ -96,7 +105,7 @@ pub enum QueryResult<'a> {
index: &'a IndexEntry,
metadata: MailMeta,
content: Vec<u8>,
- }
+ },
}
impl<'a> QueryResult<'a> {
pub fn uuid(&self) -> &UniqueIdent {
@@ -134,14 +143,27 @@ impl<'a> QueryResult<'a> {
fn into_partial(self, metadata: MailMeta) -> Option<Self> {
match self {
- Self::IndexResult { uuid, index } => Some(Self::PartialResult { uuid, index, metadata }),
+ Self::IndexResult { uuid, index } => Some(Self::PartialResult {
+ uuid,
+ index,
+ metadata,
+ }),
_ => None,
}
}
fn into_full(self, content: Vec<u8>) -> Option<Self> {
match self {
- Self::PartialResult { uuid, index, metadata } => Some(Self::FullResult { uuid, index, metadata, content }),
+ Self::PartialResult {
+ uuid,
+ index,
+ metadata,
+ } => Some(Self::FullResult {
+ uuid,
+ index,
+ metadata,
+ content,
+ }),
_ => None,
}
}
diff --git a/src/mail/snapshot.rs b/src/mail/snapshot.rs
index c3145b4..0834f09 100644
--- a/src/mail/snapshot.rs
+++ b/src/mail/snapshot.rs
@@ -3,16 +3,16 @@ use std::sync::Arc;
use anyhow::Result;
use super::mailbox::Mailbox;
+use super::query::{Query, QueryScope};
use super::uidindex::UidIndex;
use super::unique_ident::UniqueIdent;
-use super::query::{Query, QueryScope};
/// A Frozen Mailbox has a snapshot of the current mailbox
/// state that is desynchronized with the real mailbox state.
/// It's up to the user to choose when their snapshot must be updated
/// to give useful information to their clients
///
-///
+///
pub struct FrozenMailbox {
pub mailbox: Arc<Mailbox>,
pub snapshot: UidIndex,
@@ -46,17 +46,17 @@ impl FrozenMailbox {
/// Update the FrozenMailbox local snapshot.
/// Returns the old snapshot, so you can build a diff
pub async fn update(&mut self) -> UidIndex {
- let old_snapshot = self.snapshot.clone();
- self.snapshot = self.mailbox.current_uid_index().await;
+ let old_snapshot = self.snapshot.clone();
+ self.snapshot = self.mailbox.current_uid_index().await;
- old_snapshot
+ old_snapshot
}
pub fn query<'a, 'b>(&'a self, uuids: &'b [UniqueIdent], scope: QueryScope) -> Query<'a, 'b> {
Query {
- frozen: self,
- emails: uuids,
- scope,
+ frozen: self,
+ emails: uuids,
+ scope,
}
}
}