Better choose wether or not a body is required
This commit is contained in:
parent
a90f425d32
commit
056f8ea14c
3 changed files with 30 additions and 25 deletions
|
@ -1,4 +1,4 @@
|
||||||
use imap_codec::imap_types::fetch::{MacroOrMessageDataItemNames, MessageDataItemName};
|
use imap_codec::imap_types::fetch::{MacroOrMessageDataItemNames, MessageDataItemName, Section};
|
||||||
|
|
||||||
/// Internal decisions based on fetched attributes
|
/// Internal decisions based on fetched attributes
|
||||||
/// passed by the client
|
/// passed by the client
|
||||||
|
@ -36,14 +36,26 @@ impl AttributesProxy {
|
||||||
|
|
||||||
pub fn need_body(&self) -> bool {
|
pub fn need_body(&self) -> bool {
|
||||||
self.attrs.iter().any(|x| {
|
self.attrs.iter().any(|x| {
|
||||||
matches!(
|
println!("item is: {:?}", x);
|
||||||
x,
|
match x {
|
||||||
MessageDataItemName::Body
|
MessageDataItemName::Body
|
||||||
| MessageDataItemName::BodyExt { .. }
|
| MessageDataItemName::Rfc822
|
||||||
| MessageDataItemName::Rfc822
|
| MessageDataItemName::Rfc822Text
|
||||||
| MessageDataItemName::Rfc822Text
|
| MessageDataItemName::BodyStructure => true,
|
||||||
| MessageDataItemName::BodyStructure
|
|
||||||
)
|
MessageDataItemName::BodyExt {
|
||||||
|
section: Some(section),
|
||||||
|
partial: _,
|
||||||
|
peek: _,
|
||||||
|
} => match section {
|
||||||
|
Section::Header(None)
|
||||||
|
| Section::HeaderFields(None, _)
|
||||||
|
| Section::HeaderFieldsNot(None, _) => false,
|
||||||
|
_ => true,
|
||||||
|
},
|
||||||
|
MessageDataItemName::BodyExt { .. } => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,10 +32,7 @@ pub struct MailView<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> MailView<'a> {
|
impl<'a> MailView<'a> {
|
||||||
pub fn new(
|
pub fn new(query_result: &'a QueryResult, in_idx: &'a MailIndex<'a>) -> Result<MailView<'a>> {
|
||||||
query_result: &'a QueryResult,
|
|
||||||
in_idx: &'a MailIndex<'a>,
|
|
||||||
) -> Result<MailView<'a>> {
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
in_idx,
|
in_idx,
|
||||||
query_result,
|
query_result,
|
||||||
|
|
|
@ -31,8 +31,12 @@ impl QueryScope {
|
||||||
impl<'a, 'b> Query<'a, 'b> {
|
impl<'a, 'b> Query<'a, 'b> {
|
||||||
pub async fn fetch(&self) -> Result<Vec<QueryResult>> {
|
pub async fn fetch(&self) -> Result<Vec<QueryResult>> {
|
||||||
match self.scope {
|
match self.scope {
|
||||||
QueryScope::Index => Ok(self.emails.iter().map(|&uuid| QueryResult::IndexResult { uuid }).collect()),
|
QueryScope::Index => Ok(self
|
||||||
QueryScope::Partial =>self.partial().await,
|
.emails
|
||||||
|
.iter()
|
||||||
|
.map(|&uuid| QueryResult::IndexResult { uuid })
|
||||||
|
.collect()),
|
||||||
|
QueryScope::Partial => self.partial().await,
|
||||||
QueryScope::Full => self.full().await,
|
QueryScope::Full => self.full().await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,9 +48,7 @@ impl<'a, 'b> Query<'a, 'b> {
|
||||||
let result = meta
|
let result = meta
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(self.emails.iter())
|
.zip(self.emails.iter())
|
||||||
.map(|(metadata, &uuid)| {
|
.map(|(metadata, &uuid)| QueryResult::PartialResult { uuid, metadata })
|
||||||
QueryResult::PartialResult { uuid, metadata }
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
|
@ -125,20 +127,14 @@ impl QueryResult {
|
||||||
|
|
||||||
fn into_partial(self, metadata: MailMeta) -> Option<Self> {
|
fn into_partial(self, metadata: MailMeta) -> Option<Self> {
|
||||||
match self {
|
match self {
|
||||||
Self::IndexResult { uuid } => Some(Self::PartialResult {
|
Self::IndexResult { uuid } => Some(Self::PartialResult { uuid, metadata }),
|
||||||
uuid,
|
|
||||||
metadata,
|
|
||||||
}),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_full(self, content: Vec<u8>) -> Option<Self> {
|
fn into_full(self, content: Vec<u8>) -> Option<Self> {
|
||||||
match self {
|
match self {
|
||||||
Self::PartialResult {
|
Self::PartialResult { uuid, metadata } => Some(Self::FullResult {
|
||||||
uuid,
|
|
||||||
metadata,
|
|
||||||
} => Some(Self::FullResult {
|
|
||||||
uuid,
|
uuid,
|
||||||
metadata,
|
metadata,
|
||||||
content,
|
content,
|
||||||
|
|
Loading…
Reference in a new issue