Merge pull request 'bug/thunderbird' (#68) from bug/thunderbird into main
Reviewed-on: #68
This commit is contained in:
commit
356776cba3
9 changed files with 147 additions and 111 deletions
|
@ -152,7 +152,7 @@ impl<S: BayouState> Bayou<S> {
|
||||||
match &val[0] {
|
match &val[0] {
|
||||||
storage::Alternative::Value(v) => {
|
storage::Alternative::Value(v) => {
|
||||||
let op = open_deserialize::<S::Op>(v, &self.key)?;
|
let op = open_deserialize::<S::Op>(v, &self.key)?;
|
||||||
debug!("(sync) operation {}: {:?}", sort_key, op);
|
tracing::trace!("(sync) operation {}: {:?}", sort_key, op);
|
||||||
ops.push((ts, op));
|
ops.push((ts, op));
|
||||||
}
|
}
|
||||||
storage::Alternative::Tombstone => {
|
storage::Alternative::Tombstone => {
|
||||||
|
|
|
@ -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,25 @@ 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!(
|
match x {
|
||||||
x,
|
|
||||||
MessageDataItemName::Body
|
MessageDataItemName::Body
|
||||||
| MessageDataItemName::BodyExt { .. }
|
|
||||||
| MessageDataItemName::Rfc822
|
| MessageDataItemName::Rfc822
|
||||||
| MessageDataItemName::Rfc822Text
|
| MessageDataItemName::Rfc822Text
|
||||||
| MessageDataItemName::BodyStructure
|
| MessageDataItemName::BodyStructure => true,
|
||||||
)
|
|
||||||
|
MessageDataItemName::BodyExt {
|
||||||
|
section: Some(section),
|
||||||
|
partial: _,
|
||||||
|
peek: _,
|
||||||
|
} => match section {
|
||||||
|
Section::Header(None)
|
||||||
|
| Section::HeaderFields(None, _)
|
||||||
|
| Section::HeaderFieldsNot(None, _) => false,
|
||||||
|
_ => true,
|
||||||
|
},
|
||||||
|
MessageDataItemName::BodyExt { .. } => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use imap_codec::imap_types::sequence::{self, SeqOrUid, Sequence, SequenceSet};
|
use imap_codec::imap_types::sequence::{self, SeqOrUid, Sequence, SequenceSet};
|
||||||
|
|
||||||
use crate::mail::uidindex::{ImapUid, UidIndex};
|
use crate::mail::uidindex::{ImapUid, UidIndex};
|
||||||
|
@ -62,7 +62,7 @@ impl<'a> Index<'a> {
|
||||||
return vec![];
|
return vec![];
|
||||||
}
|
}
|
||||||
let iter_strat = sequence::Strategy::Naive {
|
let iter_strat = sequence::Strategy::Naive {
|
||||||
largest: self.last().expect("imap index is not empty").uid,
|
largest: self.last().expect("The mailbox is not empty").uid,
|
||||||
};
|
};
|
||||||
let mut unroll_seq = sequence_set.iter(iter_strat).collect::<Vec<_>>();
|
let mut unroll_seq = sequence_set.iter(iter_strat).collect::<Vec<_>>();
|
||||||
unroll_seq.sort();
|
unroll_seq.sort();
|
||||||
|
@ -80,10 +80,6 @@ impl<'a> Index<'a> {
|
||||||
.partition_point(|mail_idx| &mail_idx.uid < start_seq);
|
.partition_point(|mail_idx| &mail_idx.uid < start_seq);
|
||||||
&self.imap_index[start_idx..]
|
&self.imap_index[start_idx..]
|
||||||
};
|
};
|
||||||
println!(
|
|
||||||
"win: {:?}",
|
|
||||||
imap_idx.iter().map(|midx| midx.uid).collect::<Vec<_>>()
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut acc = vec![];
|
let mut acc = vec![];
|
||||||
for wanted_uid in unroll_seq.iter() {
|
for wanted_uid in unroll_seq.iter() {
|
||||||
|
@ -104,17 +100,25 @@ impl<'a> Index<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fetch_on_id(&'a self, sequence_set: &SequenceSet) -> Result<Vec<&'a MailIndex<'a>>> {
|
pub fn fetch_on_id(&'a self, sequence_set: &SequenceSet) -> Result<Vec<&'a MailIndex<'a>>> {
|
||||||
|
if self.imap_index.is_empty() {
|
||||||
|
return Ok(vec![]);
|
||||||
|
}
|
||||||
let iter_strat = sequence::Strategy::Naive {
|
let iter_strat = sequence::Strategy::Naive {
|
||||||
largest: self.last().context("The mailbox is empty")?.uid,
|
largest: NonZeroU32::try_from(self.imap_index.len() as u32)?,
|
||||||
};
|
};
|
||||||
sequence_set
|
let mut acc = sequence_set
|
||||||
.iter(iter_strat)
|
.iter(iter_strat)
|
||||||
.map(|wanted_id| {
|
.map(|wanted_id| {
|
||||||
self.imap_index
|
self.imap_index
|
||||||
.get((wanted_id.get() as usize) - 1)
|
.get((wanted_id.get() as usize) - 1)
|
||||||
.ok_or(anyhow!("Mail not found"))
|
.ok_or(anyhow!("Mail not found"))
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>>>()
|
.collect::<Result<Vec<_>>>()?;
|
||||||
|
|
||||||
|
// Sort the result to be consistent with UID
|
||||||
|
acc.sort_by(|a, b| a.i.cmp(&b.i));
|
||||||
|
|
||||||
|
Ok(acc)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fetch(
|
pub fn fetch(
|
||||||
|
|
|
@ -27,15 +27,12 @@ use crate::imap::response::Body;
|
||||||
|
|
||||||
pub struct MailView<'a> {
|
pub struct MailView<'a> {
|
||||||
pub in_idx: &'a MailIndex<'a>,
|
pub in_idx: &'a MailIndex<'a>,
|
||||||
pub query_result: &'a QueryResult<'a>,
|
pub query_result: &'a QueryResult,
|
||||||
pub content: FetchedMail<'a>,
|
pub content: FetchedMail<'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<'a>,
|
|
||||||
in_idx: &'a MailIndex<'a>,
|
|
||||||
) -> Result<MailView<'a>> {
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
in_idx,
|
in_idx,
|
||||||
query_result,
|
query_result,
|
||||||
|
@ -74,7 +71,12 @@ impl<'a> MailView<'a> {
|
||||||
MessageDataItemName::Rfc822Size => self.rfc_822_size(),
|
MessageDataItemName::Rfc822Size => self.rfc_822_size(),
|
||||||
MessageDataItemName::Rfc822Header => self.rfc_822_header(),
|
MessageDataItemName::Rfc822Header => self.rfc_822_header(),
|
||||||
MessageDataItemName::Rfc822Text => self.rfc_822_text(),
|
MessageDataItemName::Rfc822Text => self.rfc_822_text(),
|
||||||
MessageDataItemName::Rfc822 => self.rfc822(),
|
MessageDataItemName::Rfc822 => {
|
||||||
|
if self.is_not_yet_seen() {
|
||||||
|
seen = SeenFlag::MustAdd;
|
||||||
|
}
|
||||||
|
self.rfc822()
|
||||||
|
}
|
||||||
MessageDataItemName::Envelope => Ok(self.envelope()),
|
MessageDataItemName::Envelope => Ok(self.envelope()),
|
||||||
MessageDataItemName::Body => self.body(),
|
MessageDataItemName::Body => self.body(),
|
||||||
MessageDataItemName::BodyStructure => self.body_structure(),
|
MessageDataItemName::BodyStructure => self.body_structure(),
|
||||||
|
@ -180,15 +182,22 @@ impl<'a> MailView<'a> {
|
||||||
fn body(&self) -> Result<MessageDataItem<'static>> {
|
fn body(&self) -> Result<MessageDataItem<'static>> {
|
||||||
Ok(MessageDataItem::Body(mime_view::bodystructure(
|
Ok(MessageDataItem::Body(mime_view::bodystructure(
|
||||||
self.content.as_msg()?.child.as_ref(),
|
self.content.as_msg()?.child.as_ref(),
|
||||||
|
false,
|
||||||
)?))
|
)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn body_structure(&self) -> Result<MessageDataItem<'static>> {
|
fn body_structure(&self) -> Result<MessageDataItem<'static>> {
|
||||||
Ok(MessageDataItem::Body(mime_view::bodystructure(
|
Ok(MessageDataItem::BodyStructure(mime_view::bodystructure(
|
||||||
self.content.as_msg()?.child.as_ref(),
|
self.content.as_msg()?.child.as_ref(),
|
||||||
|
true,
|
||||||
)?))
|
)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_not_yet_seen(&self) -> bool {
|
||||||
|
let seen_flag = Flag::Seen.to_string();
|
||||||
|
!self.in_idx.flags.iter().any(|x| *x == seen_flag)
|
||||||
|
}
|
||||||
|
|
||||||
/// maps to BODY[<section>]<<partial>> and BODY.PEEK[<section>]<<partial>>
|
/// maps to BODY[<section>]<<partial>> and BODY.PEEK[<section>]<<partial>>
|
||||||
/// peek does not implicitly set the \Seen flag
|
/// peek does not implicitly set the \Seen flag
|
||||||
/// eg. BODY[HEADER.FIELDS (DATE FROM)]
|
/// eg. BODY[HEADER.FIELDS (DATE FROM)]
|
||||||
|
@ -201,8 +210,7 @@ impl<'a> MailView<'a> {
|
||||||
) -> Result<(MessageDataItem<'static>, SeenFlag)> {
|
) -> Result<(MessageDataItem<'static>, SeenFlag)> {
|
||||||
// Manage Seen flag
|
// Manage Seen flag
|
||||||
let mut seen = SeenFlag::DoNothing;
|
let mut seen = SeenFlag::DoNothing;
|
||||||
let seen_flag = Flag::Seen.to_string();
|
if !peek && self.is_not_yet_seen() {
|
||||||
if !peek && !self.in_idx.flags.iter().any(|x| *x == seen_flag) {
|
|
||||||
// Add \Seen flag
|
// Add \Seen flag
|
||||||
//self.mailbox.add_flags(uuid, &[seen_flag]).await?;
|
//self.mailbox.add_flags(uuid, &[seen_flag]).await?;
|
||||||
seen = SeenFlag::MustAdd;
|
seen = SeenFlag::MustAdd;
|
||||||
|
|
|
@ -130,6 +130,8 @@ impl MailboxView {
|
||||||
data.extend(self.flags_status()?.into_iter());
|
data.extend(self.flags_status()?.into_iter());
|
||||||
data.push(self.uidvalidity_status()?);
|
data.push(self.uidvalidity_status()?);
|
||||||
data.push(self.uidnext_status()?);
|
data.push(self.uidnext_status()?);
|
||||||
|
self.unseen_first_status()?
|
||||||
|
.map(|unseen_status| data.push(unseen_status));
|
||||||
|
|
||||||
Ok(data)
|
Ok(data)
|
||||||
}
|
}
|
||||||
|
@ -257,6 +259,7 @@ impl MailboxView {
|
||||||
true => QueryScope::Full,
|
true => QueryScope::Full,
|
||||||
_ => QueryScope::Partial,
|
_ => QueryScope::Partial,
|
||||||
};
|
};
|
||||||
|
tracing::debug!("Query scope {:?}", query_scope);
|
||||||
let idx = self.index()?;
|
let idx = self.index()?;
|
||||||
let mail_idx_list = idx.fetch(sequence_set, *is_uid_fetch)?;
|
let mail_idx_list = idx.fetch(sequence_set, *is_uid_fetch)?;
|
||||||
|
|
||||||
|
@ -400,6 +403,27 @@ impl MailboxView {
|
||||||
Ok(Body::Data(Data::Recent(self.recent()?)))
|
Ok(Body::Data(Data::Recent(self.recent()?)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn unseen_first_status(&self) -> Result<Option<Body<'static>>> {
|
||||||
|
Ok(self
|
||||||
|
.unseen_first()?
|
||||||
|
.map(|unseen_id| {
|
||||||
|
Status::ok(None, Some(Code::Unseen(unseen_id)), "First unseen.").map(Body::Status)
|
||||||
|
})
|
||||||
|
.transpose()?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unseen_first(&self) -> Result<Option<NonZeroU32>> {
|
||||||
|
Ok(self
|
||||||
|
.0
|
||||||
|
.snapshot
|
||||||
|
.table
|
||||||
|
.values()
|
||||||
|
.enumerate()
|
||||||
|
.find(|(_i, (_imap_uid, flags))| !flags.contains(&"\\Seen".to_string()))
|
||||||
|
.map(|(i, _)| NonZeroU32::try_from(i as u32 + 1))
|
||||||
|
.transpose()?)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn recent(&self) -> Result<u32> {
|
pub(crate) fn recent(&self) -> Result<u32> {
|
||||||
let recent = self
|
let recent = self
|
||||||
.0
|
.0
|
||||||
|
@ -521,7 +545,6 @@ mod tests {
|
||||||
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 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 {
|
let qr = QueryResult::FullResult {
|
||||||
uuid: mail_in_idx.uuid.clone(),
|
uuid: mail_in_idx.uuid.clone(),
|
||||||
index: &index_entry,
|
|
||||||
metadata: meta,
|
metadata: meta,
|
||||||
content: rfc822.to_vec(),
|
content: rfc822.to_vec(),
|
||||||
};
|
};
|
||||||
|
@ -596,6 +619,7 @@ mod tests {
|
||||||
seq: NonZeroU32::new(1).unwrap(),
|
seq: NonZeroU32::new(1).unwrap(),
|
||||||
items: NonEmptyVec::from(MessageDataItem::Body(mime_view::bodystructure(
|
items: NonEmptyVec::from(MessageDataItem::Body(mime_view::bodystructure(
|
||||||
&message.child,
|
&message.child,
|
||||||
|
false,
|
||||||
)?)),
|
)?)),
|
||||||
});
|
});
|
||||||
let test_bytes = ResponseCodec::new().encode(&test_repr).dump();
|
let test_bytes = ResponseCodec::new().encode(&test_repr).dump();
|
||||||
|
|
|
@ -4,7 +4,10 @@ use std::num::NonZeroU32;
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, Result};
|
use anyhow::{anyhow, bail, Result};
|
||||||
|
|
||||||
use imap_codec::imap_types::body::{BasicFields, Body as FetchBody, BodyStructure, SpecificFields};
|
use imap_codec::imap_types::body::{
|
||||||
|
BasicFields, Body as FetchBody, BodyStructure, MultiPartExtensionData, SinglePartExtensionData,
|
||||||
|
SpecificFields,
|
||||||
|
};
|
||||||
use imap_codec::imap_types::core::{AString, IString, NString, NonEmptyVec};
|
use imap_codec::imap_types::core::{AString, IString, NString, NonEmptyVec};
|
||||||
use imap_codec::imap_types::fetch::{Part as FetchPart, Section as FetchSection};
|
use imap_codec::imap_types::fetch::{Part as FetchPart, Section as FetchSection};
|
||||||
|
|
||||||
|
@ -78,8 +81,8 @@ pub fn body_ext<'a>(
|
||||||
/// | parameter list
|
/// | parameter list
|
||||||
/// b OK Fetch completed (0.001 + 0.000 secs).
|
/// b OK Fetch completed (0.001 + 0.000 secs).
|
||||||
/// ```
|
/// ```
|
||||||
pub fn bodystructure(part: &AnyPart) -> Result<BodyStructure<'static>> {
|
pub fn bodystructure(part: &AnyPart, is_ext: bool) -> Result<BodyStructure<'static>> {
|
||||||
NodeMime(part).structure()
|
NodeMime(part).structure(is_ext)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// NodeMime
|
/// NodeMime
|
||||||
|
@ -118,12 +121,12 @@ impl<'a> NodeMime<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn structure(&self) -> Result<BodyStructure<'static>> {
|
fn structure(&self, is_ext: bool) -> Result<BodyStructure<'static>> {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
AnyPart::Txt(x) => NodeTxt(self, x).structure(),
|
AnyPart::Txt(x) => NodeTxt(self, x).structure(is_ext),
|
||||||
AnyPart::Bin(x) => NodeBin(self, x).structure(),
|
AnyPart::Bin(x) => NodeBin(self, x).structure(is_ext),
|
||||||
AnyPart::Mult(x) => NodeMult(self, x).structure(),
|
AnyPart::Mult(x) => NodeMult(self, x).structure(is_ext),
|
||||||
AnyPart::Msg(x) => NodeMsg(self, x).structure(),
|
AnyPart::Msg(x) => NodeMsg(self, x).structure(is_ext),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -359,7 +362,7 @@ impl<'a> SelectedMime<'a> {
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
struct NodeMsg<'a>(&'a NodeMime<'a>, &'a composite::Message<'a>);
|
struct NodeMsg<'a>(&'a NodeMime<'a>, &'a composite::Message<'a>);
|
||||||
impl<'a> NodeMsg<'a> {
|
impl<'a> NodeMsg<'a> {
|
||||||
fn structure(&self) -> Result<BodyStructure<'static>> {
|
fn structure(&self, is_ext: bool) -> Result<BodyStructure<'static>> {
|
||||||
let basic = SelectedMime(self.0 .0).basic_fields()?;
|
let basic = SelectedMime(self.0 .0).basic_fields()?;
|
||||||
|
|
||||||
Ok(BodyStructure::Single {
|
Ok(BodyStructure::Single {
|
||||||
|
@ -367,17 +370,23 @@ impl<'a> NodeMsg<'a> {
|
||||||
basic,
|
basic,
|
||||||
specific: SpecificFields::Message {
|
specific: SpecificFields::Message {
|
||||||
envelope: Box::new(ImfView(&self.1.imf).message_envelope()),
|
envelope: Box::new(ImfView(&self.1.imf).message_envelope()),
|
||||||
body_structure: Box::new(NodeMime(&self.1.child).structure()?),
|
body_structure: Box::new(NodeMime(&self.1.child).structure(is_ext)?),
|
||||||
number_of_lines: nol(self.1.raw_part),
|
number_of_lines: nol(self.1.raw_part),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
extension_data: None,
|
extension_data: match is_ext {
|
||||||
|
true => Some(SinglePartExtensionData {
|
||||||
|
md5: NString(None),
|
||||||
|
tail: None,
|
||||||
|
}),
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
struct NodeMult<'a>(&'a NodeMime<'a>, &'a composite::Multipart<'a>);
|
struct NodeMult<'a>(&'a NodeMime<'a>, &'a composite::Multipart<'a>);
|
||||||
impl<'a> NodeMult<'a> {
|
impl<'a> NodeMult<'a> {
|
||||||
fn structure(&self) -> Result<BodyStructure<'static>> {
|
fn structure(&self, is_ext: bool) -> Result<BodyStructure<'static>> {
|
||||||
let itype = &self.1.mime.interpreted_type;
|
let itype = &self.1.mime.interpreted_type;
|
||||||
let subtype = IString::try_from(itype.subtype.to_string())
|
let subtype = IString::try_from(itype.subtype.to_string())
|
||||||
.unwrap_or(unchecked_istring("alternative"));
|
.unwrap_or(unchecked_istring("alternative"));
|
||||||
|
@ -386,7 +395,7 @@ impl<'a> NodeMult<'a> {
|
||||||
.1
|
.1
|
||||||
.children
|
.children
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|inner| NodeMime(&inner).structure().ok())
|
.filter_map(|inner| NodeMime(&inner).structure(is_ext).ok())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
NonEmptyVec::validate(&inner_bodies)?;
|
NonEmptyVec::validate(&inner_bodies)?;
|
||||||
|
@ -395,20 +404,22 @@ impl<'a> NodeMult<'a> {
|
||||||
Ok(BodyStructure::Multi {
|
Ok(BodyStructure::Multi {
|
||||||
bodies,
|
bodies,
|
||||||
subtype,
|
subtype,
|
||||||
extension_data: None,
|
extension_data: match is_ext {
|
||||||
/*Some(MultipartExtensionData {
|
true => Some(MultiPartExtensionData {
|
||||||
parameter_list: vec![],
|
parameter_list: vec![(
|
||||||
disposition: None,
|
IString::try_from("boundary").unwrap(),
|
||||||
language: None,
|
IString::try_from(self.1.mime.interpreted_type.boundary.to_string())?,
|
||||||
location: None,
|
)],
|
||||||
extension: vec![],
|
tail: None,
|
||||||
})*/
|
}),
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
struct NodeTxt<'a>(&'a NodeMime<'a>, &'a discrete::Text<'a>);
|
struct NodeTxt<'a>(&'a NodeMime<'a>, &'a discrete::Text<'a>);
|
||||||
impl<'a> NodeTxt<'a> {
|
impl<'a> NodeTxt<'a> {
|
||||||
fn structure(&self) -> Result<BodyStructure<'static>> {
|
fn structure(&self, is_ext: bool) -> Result<BodyStructure<'static>> {
|
||||||
let mut basic = SelectedMime(self.0 .0).basic_fields()?;
|
let mut basic = SelectedMime(self.0 .0).basic_fields()?;
|
||||||
|
|
||||||
// Get the interpreted content type, set it
|
// Get the interpreted content type, set it
|
||||||
|
@ -435,14 +446,20 @@ impl<'a> NodeTxt<'a> {
|
||||||
number_of_lines: nol(self.1.body),
|
number_of_lines: nol(self.1.body),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
extension_data: None,
|
extension_data: match is_ext {
|
||||||
|
true => Some(SinglePartExtensionData {
|
||||||
|
md5: NString(None),
|
||||||
|
tail: None,
|
||||||
|
}),
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NodeBin<'a>(&'a NodeMime<'a>, &'a discrete::Binary<'a>);
|
struct NodeBin<'a>(&'a NodeMime<'a>, &'a discrete::Binary<'a>);
|
||||||
impl<'a> NodeBin<'a> {
|
impl<'a> NodeBin<'a> {
|
||||||
fn structure(&self) -> Result<BodyStructure<'static>> {
|
fn structure(&self, is_ext: bool) -> Result<BodyStructure<'static>> {
|
||||||
let basic = SelectedMime(self.0 .0).basic_fields()?;
|
let basic = SelectedMime(self.0 .0).basic_fields()?;
|
||||||
|
|
||||||
let default = mime::r#type::NaiveType {
|
let default = mime::r#type::NaiveType {
|
||||||
|
@ -465,7 +482,13 @@ impl<'a> NodeBin<'a> {
|
||||||
basic,
|
basic,
|
||||||
specific: SpecificFields::Basic { r#type, subtype },
|
specific: SpecificFields::Basic { r#type, subtype },
|
||||||
},
|
},
|
||||||
extension_data: None,
|
extension_data: match is_ext {
|
||||||
|
true => Some(SinglePartExtensionData {
|
||||||
|
md5: NString(None),
|
||||||
|
tail: None,
|
||||||
|
}),
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,7 +134,7 @@ impl<'a> Criteria<'a> {
|
||||||
pub fn filter_on_query<'b>(
|
pub fn filter_on_query<'b>(
|
||||||
&self,
|
&self,
|
||||||
midx_list: &[&'b MailIndex<'b>],
|
midx_list: &[&'b MailIndex<'b>],
|
||||||
query_result: &'b Vec<QueryResult<'b>>,
|
query_result: &'b Vec<QueryResult>,
|
||||||
) -> Result<Vec<&'b MailIndex<'b>>> {
|
) -> Result<Vec<&'b MailIndex<'b>>> {
|
||||||
Ok(midx_list
|
Ok(midx_list
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -486,7 +486,7 @@ fn dump(uid_index: &Bayou<UidIndex>) {
|
||||||
|
|
||||||
/// The metadata of a message that is stored in K2V
|
/// The metadata of a message that is stored in K2V
|
||||||
/// at pk = mail/<mailbox uuid>, sk = <message uuid>
|
/// at pk = mail/<mailbox uuid>, sk = <message uuid>
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct MailMeta {
|
pub struct MailMeta {
|
||||||
/// INTERNALDATE field (milliseconds since epoch)
|
/// INTERNALDATE field (milliseconds since epoch)
|
||||||
pub internaldate: u64,
|
pub internaldate: u64,
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use super::mailbox::MailMeta;
|
use super::mailbox::MailMeta;
|
||||||
use super::snapshot::FrozenMailbox;
|
use super::snapshot::FrozenMailbox;
|
||||||
use super::uidindex::IndexEntry;
|
|
||||||
use super::unique_ident::UniqueIdent;
|
use super::unique_ident::UniqueIdent;
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::Result;
|
||||||
use futures::stream::{FuturesUnordered, StreamExt};
|
use futures::stream::{FuturesOrdered, StreamExt};
|
||||||
|
|
||||||
/// Query is in charge of fetching efficiently
|
/// Query is in charge of fetching efficiently
|
||||||
/// requested data for a list of emails
|
/// requested data for a list of emails
|
||||||
|
@ -13,7 +12,7 @@ pub struct Query<'a, 'b> {
|
||||||
pub scope: QueryScope,
|
pub scope: QueryScope,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[derive(Debug)]
|
||||||
pub enum QueryScope {
|
pub enum QueryScope {
|
||||||
Index,
|
Index,
|
||||||
Partial,
|
Partial,
|
||||||
|
@ -30,9 +29,13 @@ impl QueryScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> Query<'a, 'b> {
|
impl<'a, 'b> Query<'a, 'b> {
|
||||||
pub async fn fetch(&self) -> Result<Vec<QueryResult<'a>>> {
|
pub async fn fetch(&self) -> Result<Vec<QueryResult>> {
|
||||||
match self.scope {
|
match self.scope {
|
||||||
QueryScope::Index => self.index(),
|
QueryScope::Index => Ok(self
|
||||||
|
.emails
|
||||||
|
.iter()
|
||||||
|
.map(|&uuid| QueryResult::IndexResult { uuid })
|
||||||
|
.collect()),
|
||||||
QueryScope::Partial => self.partial().await,
|
QueryScope::Partial => self.partial().await,
|
||||||
QueryScope::Full => self.full().await,
|
QueryScope::Full => self.full().await,
|
||||||
}
|
}
|
||||||
|
@ -40,31 +43,14 @@ impl<'a, 'b> Query<'a, 'b> {
|
||||||
|
|
||||||
// --- functions below are private *for reasons*
|
// --- functions below are private *for reasons*
|
||||||
|
|
||||||
fn index(&self) -> Result<Vec<QueryResult<'a>>> {
|
async fn partial(&self) -> Result<Vec<QueryResult>> {
|
||||||
self.emails
|
|
||||||
.iter()
|
|
||||||
.map(|uuid| {
|
|
||||||
self.frozen
|
|
||||||
.snapshot
|
|
||||||
.table
|
|
||||||
.get(uuid)
|
|
||||||
.map(|index| QueryResult::IndexResult { uuid: *uuid, index })
|
|
||||||
.ok_or(anyhow!("missing email in index"))
|
|
||||||
})
|
|
||||||
.collect::<Result<Vec<_>, _>>()
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn partial(&self) -> Result<Vec<QueryResult<'a>>> {
|
|
||||||
let meta = self.frozen.mailbox.fetch_meta(self.emails).await?;
|
let meta = self.frozen.mailbox.fetch_meta(self.emails).await?;
|
||||||
let result = meta
|
let result = meta
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(self.index()?)
|
.zip(self.emails.iter())
|
||||||
.map(|(metadata, index)| {
|
.map(|(metadata, &uuid)| QueryResult::PartialResult { uuid, metadata })
|
||||||
index
|
|
||||||
.into_partial(metadata)
|
|
||||||
.expect("index to be IndexResult")
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +58,7 @@ impl<'a, 'b> Query<'a, 'b> {
|
||||||
/// AND GENERATE SO MUCH NETWORK TRAFFIC.
|
/// AND GENERATE SO MUCH NETWORK TRAFFIC.
|
||||||
/// THIS FUNCTION SHOULD BE REWRITTEN, FOR EXAMPLE WITH
|
/// THIS FUNCTION SHOULD BE REWRITTEN, FOR EXAMPLE WITH
|
||||||
/// SOMETHING LIKE AN ITERATOR
|
/// SOMETHING LIKE AN ITERATOR
|
||||||
async fn full(&self) -> Result<Vec<QueryResult<'a>>> {
|
async fn full(&self) -> Result<Vec<QueryResult>> {
|
||||||
let meta_list = self.partial().await?;
|
let meta_list = self.partial().await?;
|
||||||
meta_list
|
meta_list
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -91,7 +77,7 @@ impl<'a, 'b> Query<'a, 'b> {
|
||||||
|
|
||||||
Ok(meta.into_full(content).expect("meta to be PartialResult"))
|
Ok(meta.into_full(content).expect("meta to be PartialResult"))
|
||||||
})
|
})
|
||||||
.collect::<FuturesUnordered<_>>()
|
.collect::<FuturesOrdered<_>>()
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await
|
.await
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -99,24 +85,22 @@ impl<'a, 'b> Query<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum QueryResult<'a> {
|
#[derive(Debug)]
|
||||||
|
pub enum QueryResult {
|
||||||
IndexResult {
|
IndexResult {
|
||||||
uuid: UniqueIdent,
|
uuid: UniqueIdent,
|
||||||
index: &'a IndexEntry,
|
|
||||||
},
|
},
|
||||||
PartialResult {
|
PartialResult {
|
||||||
uuid: UniqueIdent,
|
uuid: UniqueIdent,
|
||||||
index: &'a IndexEntry,
|
|
||||||
metadata: MailMeta,
|
metadata: MailMeta,
|
||||||
},
|
},
|
||||||
FullResult {
|
FullResult {
|
||||||
uuid: UniqueIdent,
|
uuid: UniqueIdent,
|
||||||
index: &'a IndexEntry,
|
|
||||||
metadata: MailMeta,
|
metadata: MailMeta,
|
||||||
content: Vec<u8>,
|
content: Vec<u8>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
impl<'a> QueryResult<'a> {
|
impl QueryResult {
|
||||||
pub fn uuid(&self) -> &UniqueIdent {
|
pub fn uuid(&self) -> &UniqueIdent {
|
||||||
match self {
|
match self {
|
||||||
Self::IndexResult { uuid, .. } => uuid,
|
Self::IndexResult { uuid, .. } => uuid,
|
||||||
|
@ -125,16 +109,7 @@ impl<'a> QueryResult<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
pub fn metadata(&self) -> Option<&MailMeta> {
|
||||||
pub fn index(&self) -> &IndexEntry {
|
|
||||||
match self {
|
|
||||||
Self::IndexResult { index, .. } => index,
|
|
||||||
Self::PartialResult { index, .. } => index,
|
|
||||||
Self::FullResult { index, .. } => index,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn metadata(&'a self) -> Option<&'a MailMeta> {
|
|
||||||
match self {
|
match self {
|
||||||
Self::IndexResult { .. } => None,
|
Self::IndexResult { .. } => None,
|
||||||
Self::PartialResult { metadata, .. } => Some(metadata),
|
Self::PartialResult { metadata, .. } => Some(metadata),
|
||||||
|
@ -143,7 +118,7 @@ impl<'a> QueryResult<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn content(&'a self) -> Option<&'a [u8]> {
|
pub fn content(&self) -> Option<&[u8]> {
|
||||||
match self {
|
match self {
|
||||||
Self::FullResult { content, .. } => Some(content),
|
Self::FullResult { content, .. } => Some(content),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -152,24 +127,15 @@ impl<'a> QueryResult<'a> {
|
||||||
|
|
||||||
fn into_partial(self, metadata: MailMeta) -> Option<Self> {
|
fn into_partial(self, metadata: MailMeta) -> Option<Self> {
|
||||||
match self {
|
match self {
|
||||||
Self::IndexResult { uuid, index } => Some(Self::PartialResult {
|
Self::IndexResult { uuid } => Some(Self::PartialResult { uuid, metadata }),
|
||||||
uuid,
|
|
||||||
index,
|
|
||||||
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,
|
uuid,
|
||||||
index,
|
|
||||||
metadata,
|
|
||||||
} => Some(Self::FullResult {
|
|
||||||
uuid,
|
|
||||||
index,
|
|
||||||
metadata,
|
metadata,
|
||||||
content,
|
content,
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in a new issue