Fetch BODYSTRUCTURE now returns a BODYSTRUCTURE
This commit is contained in:
parent
8b5eb25c0c
commit
07e2e50928
3 changed files with 66 additions and 35 deletions
|
@ -79,7 +79,7 @@ impl<'a> MailView<'a> {
|
||||||
seen = SeenFlag::MustAdd;
|
seen = SeenFlag::MustAdd;
|
||||||
}
|
}
|
||||||
self.rfc822()
|
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(),
|
||||||
|
@ -185,12 +185,14 @@ 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::Body(mime_view::bodystructure(
|
||||||
self.content.as_msg()?.child.as_ref(),
|
self.content.as_msg()?.child.as_ref(),
|
||||||
|
true,
|
||||||
)?))
|
)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::{anyhow, Error, Context, Result};
|
use anyhow::{anyhow, Context, Error, Result};
|
||||||
|
|
||||||
use futures::stream::{FuturesOrdered, StreamExt};
|
use futures::stream::{FuturesOrdered, StreamExt};
|
||||||
|
|
||||||
|
@ -130,7 +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));
|
self.unseen_first_status()?
|
||||||
|
.map(|unseen_status| data.push(unseen_status));
|
||||||
|
|
||||||
Ok(data)
|
Ok(data)
|
||||||
}
|
}
|
||||||
|
@ -402,18 +403,23 @@ impl MailboxView {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unseen_first_status(&self) -> Result<Option<Body<'static>>> {
|
fn unseen_first_status(&self) -> Result<Option<Body<'static>>> {
|
||||||
Ok(self.unseen_first()?.map(|unseen_id| {
|
Ok(self
|
||||||
|
.unseen_first()?
|
||||||
|
.map(|unseen_id| {
|
||||||
Status::ok(None, Some(Code::Unseen(unseen_id)), "First unseen.").map(Body::Status)
|
Status::ok(None, Some(Code::Unseen(unseen_id)), "First unseen.").map(Body::Status)
|
||||||
}).transpose()?)
|
})
|
||||||
|
.transpose()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unseen_first(&self) -> Result<Option<NonZeroU32>> {
|
fn unseen_first(&self) -> Result<Option<NonZeroU32>> {
|
||||||
Ok(self.0.snapshot.table
|
Ok(self
|
||||||
|
.0
|
||||||
|
.snapshot
|
||||||
|
.table
|
||||||
.values()
|
.values()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.find(|(_i, (_imap_uid, flags))| {
|
.find(|(_i, (_imap_uid, flags))| !flags.contains(&"\\Seen".to_string()))
|
||||||
!flags.contains(&"\\Seen".to_string())
|
.map(|(i, _)| NonZeroU32::try_from(i as u32 + 1))
|
||||||
}).map(|(i, _)| NonZeroU32::try_from(i as u32 + 1))
|
|
||||||
.transpose()?)
|
.transpose()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue