reformat cargo
This commit is contained in:
parent
cd74ae5e63
commit
ac8fb89d56
9 changed files with 129 additions and 120 deletions
|
@ -1,6 +1,4 @@
|
||||||
use imap_codec::imap_types::fetch::{
|
use imap_codec::imap_types::fetch::{MacroOrMessageDataItemNames, MessageDataItemName};
|
||||||
MacroOrMessageDataItemNames, MessageDataItemName,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Internal decisions based on fetched attributes
|
/// Internal decisions based on fetched attributes
|
||||||
/// passed by the client
|
/// passed by the client
|
||||||
|
|
|
@ -95,4 +95,3 @@ pub fn convert_mbx(addr: &imf::mailbox::MailboxRef) -> Address<'static> {
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ use std::num::NonZeroU32;
|
||||||
use anyhow::{anyhow, bail, Result};
|
use anyhow::{anyhow, bail, Result};
|
||||||
use chrono::{Offset, TimeZone, Utc};
|
use chrono::{Offset, TimeZone, Utc};
|
||||||
|
|
||||||
|
|
||||||
use imap_codec::imap_types::core::{IString, NString};
|
use imap_codec::imap_types::core::{IString, NString};
|
||||||
use imap_codec::imap_types::datetime::DateTime;
|
use imap_codec::imap_types::datetime::DateTime;
|
||||||
use imap_codec::imap_types::fetch::{
|
use imap_codec::imap_types::fetch::{
|
||||||
|
@ -17,13 +16,13 @@ use eml_codec::{
|
||||||
part::{composite::Message, AnyPart},
|
part::{composite::Message, AnyPart},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::imap::response::Body;
|
|
||||||
use crate::imap::mime_view;
|
|
||||||
use crate::imap::flags;
|
|
||||||
use crate::imap::attributes::AttributesProxy;
|
use crate::imap::attributes::AttributesProxy;
|
||||||
use crate::mail::mailbox::MailMeta;
|
use crate::imap::flags;
|
||||||
use crate::imap::mailbox_view::MailIdentifiers;
|
|
||||||
use crate::imap::imf_view::message_envelope;
|
use crate::imap::imf_view::message_envelope;
|
||||||
|
use crate::imap::mailbox_view::MailIdentifiers;
|
||||||
|
use crate::imap::mime_view;
|
||||||
|
use crate::imap::response::Body;
|
||||||
|
use crate::mail::mailbox::MailMeta;
|
||||||
|
|
||||||
pub struct MailView<'a> {
|
pub struct MailView<'a> {
|
||||||
pub ids: &'a MailIdentifiers,
|
pub ids: &'a MailIdentifiers,
|
||||||
|
@ -121,10 +120,11 @@ impl<'a> MailView<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process message
|
// Process message
|
||||||
let (text, origin) = match mime_view::body_ext(self.content.as_anypart()?, section, partial)? {
|
let (text, origin) =
|
||||||
mime_view::BodySection::Full(body) => (body, None),
|
match mime_view::body_ext(self.content.as_anypart()?, section, partial)? {
|
||||||
mime_view::BodySection::Slice { body, origin_octet } => (body, Some(origin_octet)),
|
mime_view::BodySection::Full(body) => (body, None),
|
||||||
};
|
mime_view::BodySection::Slice { body, origin_octet } => (body, Some(origin_octet)),
|
||||||
|
};
|
||||||
|
|
||||||
let data = NString(text.to_vec().try_into().ok().map(IString::Literal));
|
let data = NString(text.to_vec().try_into().ok().map(IString::Literal));
|
||||||
|
|
||||||
|
@ -185,14 +185,12 @@ impl<'a> MailView<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub enum SeenFlag {
|
pub enum SeenFlag {
|
||||||
DoNothing,
|
DoNothing,
|
||||||
MustAdd,
|
MustAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------
|
||||||
// -------------------
|
|
||||||
|
|
||||||
pub enum FetchedMail<'a> {
|
pub enum FetchedMail<'a> {
|
||||||
Partial(imf::Imf<'a>),
|
Partial(imf::Imf<'a>),
|
||||||
|
@ -229,4 +227,3 @@ impl<'a> FetchedMail<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,18 +5,16 @@ use anyhow::{anyhow, bail, Error, Result};
|
||||||
|
|
||||||
use futures::stream::{FuturesOrdered, StreamExt};
|
use futures::stream::{FuturesOrdered, StreamExt};
|
||||||
|
|
||||||
use imap_codec::imap_types::fetch::{
|
use imap_codec::imap_types::fetch::{MacroOrMessageDataItemNames, MessageDataItem};
|
||||||
MacroOrMessageDataItemNames, MessageDataItem
|
|
||||||
};
|
|
||||||
use imap_codec::imap_types::flag::{Flag, FlagFetch, FlagPerm, StoreResponse, StoreType};
|
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::response::{Code, Data, Status};
|
||||||
use imap_codec::imap_types::sequence::{self, SequenceSet};
|
use imap_codec::imap_types::sequence::{self, SequenceSet};
|
||||||
|
|
||||||
use crate::imap::flags;
|
|
||||||
use crate::imap::response::Body;
|
|
||||||
use crate::imap::attributes::AttributesProxy;
|
use crate::imap::attributes::AttributesProxy;
|
||||||
use crate::imap::selectors::MailSelectionBuilder;
|
use crate::imap::flags;
|
||||||
use crate::imap::mail_view::SeenFlag;
|
use crate::imap::mail_view::SeenFlag;
|
||||||
|
use crate::imap::response::Body;
|
||||||
|
use crate::imap::selectors::MailSelectionBuilder;
|
||||||
use crate::mail::mailbox::Mailbox;
|
use crate::mail::mailbox::Mailbox;
|
||||||
use crate::mail::uidindex::{ImapUid, ImapUidvalidity, UidIndex};
|
use crate::mail::uidindex::{ImapUid, ImapUidvalidity, UidIndex};
|
||||||
use crate::mail::unique_ident::UniqueIdent;
|
use crate::mail::unique_ident::UniqueIdent;
|
||||||
|
@ -519,7 +517,6 @@ impl MailboxView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub struct MailIdentifiers {
|
pub struct MailIdentifiers {
|
||||||
pub i: NonZeroU32,
|
pub i: NonZeroU32,
|
||||||
pub uid: ImapUid,
|
pub uid: ImapUid,
|
||||||
|
@ -536,22 +533,19 @@ impl MailIdentifiersList {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use imap_codec::imap_types::fetch::{
|
|
||||||
MacroOrMessageDataItemNames, MessageDataItemName,
|
|
||||||
};
|
|
||||||
use imap_codec::encode::Encoder;
|
use imap_codec::encode::Encoder;
|
||||||
use imap_codec::imap_types::core::NonEmptyVec;
|
use imap_codec::imap_types::core::NonEmptyVec;
|
||||||
use imap_codec::imap_types::fetch::Section;
|
use imap_codec::imap_types::fetch::Section;
|
||||||
|
use imap_codec::imap_types::fetch::{MacroOrMessageDataItemNames, MessageDataItemName};
|
||||||
use imap_codec::imap_types::response::Response;
|
use imap_codec::imap_types::response::Response;
|
||||||
use imap_codec::ResponseCodec;
|
use imap_codec::ResponseCodec;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
|
|
||||||
use crate::cryptoblob;
|
use crate::cryptoblob;
|
||||||
use crate::mail::unique_ident;
|
use crate::imap::mail_view::{FetchedMail, MailView};
|
||||||
use crate::mail::mailbox::MailMeta;
|
|
||||||
use crate::imap::mail_view::{MailView, FetchedMail};
|
|
||||||
use crate::imap::mime_view;
|
use crate::imap::mime_view;
|
||||||
|
use crate::mail::mailbox::MailMeta;
|
||||||
|
use crate::mail::unique_ident;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mailview_body_ext() -> Result<()> {
|
fn mailview_body_ext() -> Result<()> {
|
||||||
|
@ -673,4 +667,3 @@ mod tests {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,28 +1,23 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::num::NonZeroU32;
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
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, 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::{
|
use imap_codec::imap_types::fetch::{Part as FetchPart, Section as FetchSection};
|
||||||
Section as FetchSection, Part as FetchPart
|
|
||||||
};
|
|
||||||
|
|
||||||
use eml_codec::{
|
use eml_codec::{
|
||||||
header, mime,
|
header, mime, mime::r#type::Deductible, part::composite, part::discrete, part::AnyPart,
|
||||||
mime::r#type::Deductible,
|
|
||||||
part::AnyPart, part::composite, part::discrete,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::imap::imf_view::message_envelope;
|
use crate::imap::imf_view::message_envelope;
|
||||||
|
|
||||||
|
|
||||||
pub enum BodySection<'a> {
|
pub enum BodySection<'a> {
|
||||||
Full(Cow<'a, [u8]>),
|
Full(Cow<'a, [u8]>),
|
||||||
Slice {
|
Slice {
|
||||||
body: Cow<'a, [u8]>,
|
body: Cow<'a, [u8]>,
|
||||||
origin_octet: u32,
|
origin_octet: u32,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -57,9 +52,9 @@ pub enum BodySection<'a> {
|
||||||
/// 4.2.2.2 TEXT/RICHTEXT
|
/// 4.2.2.2 TEXT/RICHTEXT
|
||||||
/// ```
|
/// ```
|
||||||
pub fn body_ext<'a>(
|
pub fn body_ext<'a>(
|
||||||
part: &'a AnyPart<'a>,
|
part: &'a AnyPart<'a>,
|
||||||
section: &'a Option<FetchSection<'a>>,
|
section: &'a Option<FetchSection<'a>>,
|
||||||
partial: &'a Option<(u32, NonZeroU32)>
|
partial: &'a Option<(u32, NonZeroU32)>,
|
||||||
) -> Result<BodySection<'a>> {
|
) -> Result<BodySection<'a>> {
|
||||||
let root_mime = NodeMime(part);
|
let root_mime = NodeMime(part);
|
||||||
let (extractor, path) = SubsettedSection::from(section);
|
let (extractor, path) = SubsettedSection::from(section);
|
||||||
|
@ -88,12 +83,12 @@ pub fn bodystructure(part: &AnyPart) -> Result<BodyStructure<'static>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// NodeMime
|
/// NodeMime
|
||||||
///
|
///
|
||||||
/// Used for recursive logic on MIME.
|
/// Used for recursive logic on MIME.
|
||||||
/// See SelectedMime for inspection.
|
/// See SelectedMime for inspection.
|
||||||
struct NodeMime<'a>(&'a AnyPart<'a>);
|
struct NodeMime<'a>(&'a AnyPart<'a>);
|
||||||
impl<'a> NodeMime<'a> {
|
impl<'a> NodeMime<'a> {
|
||||||
/// A MIME object is a tree of elements.
|
/// A MIME object is a tree of elements.
|
||||||
/// The path indicates which element must be picked.
|
/// The path indicates which element must be picked.
|
||||||
/// This function returns the picked element as the new view
|
/// This function returns the picked element as the new view
|
||||||
fn subset(self, path: Option<&'a FetchPart>) -> Result<SelectedMime<'a>> {
|
fn subset(self, path: Option<&'a FetchPart>) -> Result<SelectedMime<'a>> {
|
||||||
|
@ -138,7 +133,7 @@ impl<'a> NodeMime<'a> {
|
||||||
/// A FetchSection must be handled in 2 times:
|
/// A FetchSection must be handled in 2 times:
|
||||||
/// - First we must extract the MIME part
|
/// - First we must extract the MIME part
|
||||||
/// - Then we must process it as desired
|
/// - Then we must process it as desired
|
||||||
/// The given struct mixes both work, so
|
/// The given struct mixes both work, so
|
||||||
/// we separate this work here.
|
/// we separate this work here.
|
||||||
enum SubsettedSection<'a> {
|
enum SubsettedSection<'a> {
|
||||||
Part,
|
Part,
|
||||||
|
@ -153,8 +148,12 @@ impl<'a> SubsettedSection<'a> {
|
||||||
match section {
|
match section {
|
||||||
Some(FetchSection::Text(maybe_part)) => (Self::Text, maybe_part.as_ref()),
|
Some(FetchSection::Text(maybe_part)) => (Self::Text, maybe_part.as_ref()),
|
||||||
Some(FetchSection::Header(maybe_part)) => (Self::Header, maybe_part.as_ref()),
|
Some(FetchSection::Header(maybe_part)) => (Self::Header, maybe_part.as_ref()),
|
||||||
Some(FetchSection::HeaderFields(maybe_part, fields)) => (Self::HeaderFields(fields), maybe_part.as_ref()),
|
Some(FetchSection::HeaderFields(maybe_part, fields)) => {
|
||||||
Some(FetchSection::HeaderFieldsNot(maybe_part, fields)) => (Self::HeaderFieldsNot(fields), maybe_part.as_ref()),
|
(Self::HeaderFields(fields), maybe_part.as_ref())
|
||||||
|
}
|
||||||
|
Some(FetchSection::HeaderFieldsNot(maybe_part, fields)) => {
|
||||||
|
(Self::HeaderFieldsNot(fields), maybe_part.as_ref())
|
||||||
|
}
|
||||||
Some(FetchSection::Mime(part)) => (Self::Mime, Some(part)),
|
Some(FetchSection::Mime(part)) => (Self::Mime, Some(part)),
|
||||||
Some(FetchSection::Part(part)) => (Self::Part, Some(part)),
|
Some(FetchSection::Part(part)) => (Self::Part, Some(part)),
|
||||||
None => (Self::Part, None),
|
None => (Self::Part, None),
|
||||||
|
@ -212,17 +211,24 @@ impl<'a> SelectedMime<'a> {
|
||||||
/// returned by HEADER.FIELDS.NOT contains only the header fields
|
/// returned by HEADER.FIELDS.NOT contains only the header fields
|
||||||
/// with a non-matching field-name. The field-matching is
|
/// with a non-matching field-name. The field-matching is
|
||||||
/// case-insensitive but otherwise exact.
|
/// case-insensitive but otherwise exact.
|
||||||
fn header_fields(&self, fields: &'a NonEmptyVec<AString<'a>>, invert: bool) -> Result<ExtractedFull<'a>> {
|
fn header_fields(
|
||||||
|
&self,
|
||||||
|
fields: &'a NonEmptyVec<AString<'a>>,
|
||||||
|
invert: bool,
|
||||||
|
) -> Result<ExtractedFull<'a>> {
|
||||||
// Build a lowercase ascii hashset with the fields to fetch
|
// Build a lowercase ascii hashset with the fields to fetch
|
||||||
let index = fields
|
let index = fields
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| match x {
|
.map(|x| {
|
||||||
AString::Atom(a) => a.inner().as_bytes(),
|
match x {
|
||||||
AString::String(IString::Literal(l)) => l.as_ref(),
|
AString::Atom(a) => a.inner().as_bytes(),
|
||||||
AString::String(IString::Quoted(q)) => q.inner().as_bytes(),
|
AString::String(IString::Literal(l)) => l.as_ref(),
|
||||||
}.to_ascii_lowercase())
|
AString::String(IString::Quoted(q)) => q.inner().as_bytes(),
|
||||||
.collect::<HashSet<_>>();
|
}
|
||||||
|
.to_ascii_lowercase()
|
||||||
|
})
|
||||||
|
.collect::<HashSet<_>>();
|
||||||
|
|
||||||
// Extract MIME headers
|
// Extract MIME headers
|
||||||
let mime = match &self.0 {
|
let mime = match &self.0 {
|
||||||
|
@ -234,7 +240,9 @@ impl<'a> SelectedMime<'a> {
|
||||||
// 1. Keep only the correctly formatted headers
|
// 1. Keep only the correctly formatted headers
|
||||||
// 2. Keep only based on the index presence or absence
|
// 2. Keep only based on the index presence or absence
|
||||||
// 3. Reduce as a byte vector
|
// 3. Reduce as a byte vector
|
||||||
let buffer = mime.kv.iter()
|
let buffer = mime
|
||||||
|
.kv
|
||||||
|
.iter()
|
||||||
.filter_map(|field| match field {
|
.filter_map(|field| match field {
|
||||||
header::Field::Good(header::Kv2(k, v)) => Some((k, v)),
|
header::Field::Good(header::Kv2(k, v)) => Some((k, v)),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -257,13 +265,19 @@ impl<'a> SelectedMime<'a> {
|
||||||
/// HEADER ([RFC-2822] header of the message)
|
/// HEADER ([RFC-2822] header of the message)
|
||||||
/// ```
|
/// ```
|
||||||
fn header(&self) -> Result<ExtractedFull<'a>> {
|
fn header(&self) -> Result<ExtractedFull<'a>> {
|
||||||
let msg = self.0.as_message().ok_or(anyhow!("Selected part must be a message/rfc822"))?;
|
let msg = self
|
||||||
|
.0
|
||||||
|
.as_message()
|
||||||
|
.ok_or(anyhow!("Selected part must be a message/rfc822"))?;
|
||||||
Ok(ExtractedFull(msg.raw_headers.into()))
|
Ok(ExtractedFull(msg.raw_headers.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The TEXT part specifier refers to the text body of the message, omitting the [RFC-2822] header.
|
/// The TEXT part specifier refers to the text body of the message, omitting the [RFC-2822] header.
|
||||||
fn text(&self) -> Result<ExtractedFull<'a>> {
|
fn text(&self) -> Result<ExtractedFull<'a>> {
|
||||||
let msg = self.0.as_message().ok_or(anyhow!("Selected part must be a message/rfc822"))?;
|
let msg = self
|
||||||
|
.0
|
||||||
|
.as_message()
|
||||||
|
.ok_or(anyhow!("Selected part must be a message/rfc822"))?;
|
||||||
Ok(ExtractedFull(msg.raw_body.into()))
|
Ok(ExtractedFull(msg.raw_body.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,34 +303,36 @@ impl<'a> SelectedMime<'a> {
|
||||||
(
|
(
|
||||||
IString::try_from(String::from_utf8_lossy(p.name).to_string()),
|
IString::try_from(String::from_utf8_lossy(p.name).to_string()),
|
||||||
IString::try_from(p.value.to_string()),
|
IString::try_from(p.value.to_string()),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.filter(|(k, v)| k.is_ok() && v.is_ok())
|
.filter(|(k, v)| k.is_ok() && v.is_ok())
|
||||||
.map(|(k, v)| (k.unwrap(), v.unwrap()))
|
.map(|(k, v)| (k.unwrap(), v.unwrap()))
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
.unwrap_or(vec![]);
|
.unwrap_or(vec![]);
|
||||||
|
|
||||||
Ok(BasicFields {
|
Ok(BasicFields {
|
||||||
parameter_list,
|
parameter_list,
|
||||||
id: NString(
|
id: NString(
|
||||||
m.id.as_ref()
|
m.id.as_ref()
|
||||||
.and_then(|ci| IString::try_from(ci.to_string()).ok()),
|
.and_then(|ci| IString::try_from(ci.to_string()).ok()),
|
||||||
),
|
),
|
||||||
description: NString(
|
description: NString(
|
||||||
m.description
|
m.description
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|cd| IString::try_from(cd.to_string()).ok()),
|
.and_then(|cd| IString::try_from(cd.to_string()).ok()),
|
||||||
),
|
),
|
||||||
content_transfer_encoding: match m.transfer_encoding {
|
content_transfer_encoding: match m.transfer_encoding {
|
||||||
mime::mechanism::Mechanism::_8Bit => unchecked_istring("8bit"),
|
mime::mechanism::Mechanism::_8Bit => unchecked_istring("8bit"),
|
||||||
mime::mechanism::Mechanism::Binary => unchecked_istring("binary"),
|
mime::mechanism::Mechanism::Binary => unchecked_istring("binary"),
|
||||||
mime::mechanism::Mechanism::QuotedPrintable => unchecked_istring("quoted-printable"),
|
mime::mechanism::Mechanism::QuotedPrintable => {
|
||||||
mime::mechanism::Mechanism::Base64 => unchecked_istring("base64"),
|
unchecked_istring("quoted-printable")
|
||||||
_ => unchecked_istring("7bit"),
|
}
|
||||||
},
|
mime::mechanism::Mechanism::Base64 => unchecked_istring("base64"),
|
||||||
// @FIXME we can't compute the size of the message currently...
|
_ => unchecked_istring("7bit"),
|
||||||
size: u32::try_from(sz)?,
|
},
|
||||||
|
// @FIXME we can't compute the size of the message currently...
|
||||||
|
size: u32::try_from(sz)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,7 +341,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) -> 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 {
|
||||||
body: FetchBody {
|
body: FetchBody {
|
||||||
|
@ -347,7 +363,8 @@ impl<'a> NodeMult<'a> {
|
||||||
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"));
|
||||||
|
|
||||||
let inner_bodies = self.1
|
let inner_bodies = self
|
||||||
|
.1
|
||||||
.children
|
.children
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|inner| NodeMime(&inner).structure().ok())
|
.filter_map(|inner| NodeMime(&inner).structure().ok())
|
||||||
|
@ -361,19 +378,19 @@ impl<'a> NodeMult<'a> {
|
||||||
subtype,
|
subtype,
|
||||||
extension_data: None,
|
extension_data: None,
|
||||||
/*Some(MultipartExtensionData {
|
/*Some(MultipartExtensionData {
|
||||||
parameter_list: vec![],
|
parameter_list: vec![],
|
||||||
disposition: None,
|
disposition: None,
|
||||||
language: None,
|
language: None,
|
||||||
location: None,
|
location: None,
|
||||||
extension: vec![],
|
extension: vec![],
|
||||||
})*/
|
})*/
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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) -> 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
|
||||||
let itype = match &self.1.mime.interpreted_type {
|
let itype = match &self.1.mime.interpreted_type {
|
||||||
|
@ -407,7 +424,7 @@ impl<'a> NodeTxt<'a> {
|
||||||
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) -> 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 {
|
||||||
main: &b"application"[..],
|
main: &b"application"[..],
|
||||||
|
@ -416,15 +433,13 @@ impl<'a> NodeBin<'a> {
|
||||||
};
|
};
|
||||||
let ct = self.1.mime.fields.ctype.as_ref().unwrap_or(&default);
|
let ct = self.1.mime.fields.ctype.as_ref().unwrap_or(&default);
|
||||||
|
|
||||||
let r#type =
|
let r#type = IString::try_from(String::from_utf8_lossy(ct.main).to_string()).or(Err(
|
||||||
IString::try_from(String::from_utf8_lossy(ct.main).to_string()).or(Err(
|
anyhow!("Unable to build IString from given Content-Type type given"),
|
||||||
anyhow!("Unable to build IString from given Content-Type type given"),
|
))?;
|
||||||
))?;
|
|
||||||
|
|
||||||
let subtype =
|
let subtype = IString::try_from(String::from_utf8_lossy(ct.sub).to_string()).or(Err(
|
||||||
IString::try_from(String::from_utf8_lossy(ct.sub).to_string()).or(Err(anyhow!(
|
anyhow!("Unable to build IString from given Content-Type subtype given"),
|
||||||
"Unable to build IString from given Content-Type subtype given"
|
))?;
|
||||||
)))?;
|
|
||||||
|
|
||||||
Ok(BodyStructure::Single {
|
Ok(BodyStructure::Single {
|
||||||
body: FetchBody {
|
body: FetchBody {
|
||||||
|
@ -473,8 +488,8 @@ impl<'a> ExtractedFull<'a> {
|
||||||
return BodySection::Slice {
|
return BodySection::Slice {
|
||||||
body: Cow::Borrowed(&[][..]),
|
body: Cow::Borrowed(&[][..]),
|
||||||
origin_octet: begin,
|
origin_octet: begin,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asked range is ending after the end of the content,
|
// Asked range is ending after the end of the content,
|
||||||
// slice only the beginning of the buffer
|
// slice only the beginning of the buffer
|
||||||
|
@ -485,15 +500,19 @@ impl<'a> ExtractedFull<'a> {
|
||||||
Cow::Owned(body) => Cow::Owned(body[begin as usize..].to_vec()),
|
Cow::Owned(body) => Cow::Owned(body[begin as usize..].to_vec()),
|
||||||
},
|
},
|
||||||
origin_octet: begin,
|
origin_octet: begin,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Range is included inside the considered content,
|
// Range is included inside the considered content,
|
||||||
// this is the "happy case"
|
// this is the "happy case"
|
||||||
BodySection::Slice {
|
BodySection::Slice {
|
||||||
body: match self.0 {
|
body: match self.0 {
|
||||||
Cow::Borrowed(body) => Cow::Borrowed(&body[begin as usize..(begin + len.get()) as usize]),
|
Cow::Borrowed(body) => {
|
||||||
Cow::Owned(body) => Cow::Owned(body[begin as usize..(begin + len.get()) as usize].to_vec()),
|
Cow::Borrowed(&body[begin as usize..(begin + len.get()) as usize])
|
||||||
|
}
|
||||||
|
Cow::Owned(body) => {
|
||||||
|
Cow::Owned(body[begin as usize..(begin + len.get()) as usize].to_vec())
|
||||||
|
}
|
||||||
},
|
},
|
||||||
origin_octet: begin,
|
origin_octet: begin,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
|
mod attributes;
|
||||||
mod capability;
|
mod capability;
|
||||||
mod command;
|
mod command;
|
||||||
|
mod flags;
|
||||||
mod flow;
|
mod flow;
|
||||||
mod attributes;
|
mod imf_view;
|
||||||
mod mail_view;
|
mod mail_view;
|
||||||
mod mailbox_view;
|
mod mailbox_view;
|
||||||
mod mime_view;
|
mod mime_view;
|
||||||
mod imf_view;
|
|
||||||
mod selectors;
|
|
||||||
mod flags;
|
|
||||||
mod response;
|
mod response;
|
||||||
|
mod selectors;
|
||||||
mod session;
|
mod session;
|
||||||
|
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
|
@ -2,9 +2,8 @@ use std::iter::zip;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
|
|
||||||
|
|
||||||
use crate::cryptoblob::Key;
|
use crate::cryptoblob::Key;
|
||||||
use crate::imap::mail_view::{MailView, FetchedMail};
|
use crate::imap::mail_view::{FetchedMail, MailView};
|
||||||
use crate::imap::mailbox_view::MailIdentifiers;
|
use crate::imap::mailbox_view::MailIdentifiers;
|
||||||
use crate::mail::mailbox::MailMeta;
|
use crate::mail::mailbox::MailMeta;
|
||||||
use crate::mail::unique_ident::UniqueIdent;
|
use crate::mail::unique_ident::UniqueIdent;
|
||||||
|
@ -14,7 +13,6 @@ pub struct BodyIdentifier<'a> {
|
||||||
pub msg_key: &'a Key,
|
pub msg_key: &'a Key,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct MailSelectionBuilder<'a> {
|
pub struct MailSelectionBuilder<'a> {
|
||||||
//attrs: AttributeProxy,
|
//attrs: AttributeProxy,
|
||||||
|
@ -100,4 +98,3 @@ impl<'a> MailSelectionBuilder<'a> {
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,15 +26,18 @@ fn rfc3501_imap4rev1_base() {
|
||||||
lmtp_handshake(lmtp_socket).context("handshake lmtp done")?;
|
lmtp_handshake(lmtp_socket).context("handshake lmtp done")?;
|
||||||
lmtp_deliver_email(lmtp_socket, Email::Multipart).context("mail delivered successfully")?;
|
lmtp_deliver_email(lmtp_socket, Email::Multipart).context("mail delivered successfully")?;
|
||||||
noop_exists(imap_socket).context("noop loop must detect a new email")?;
|
noop_exists(imap_socket).context("noop loop must detect a new email")?;
|
||||||
fetch_rfc822(imap_socket, Selection::FirstId, Email::Multipart).context("fetch rfc822 message, should be our first message")?;
|
fetch_rfc822(imap_socket, Selection::FirstId, Email::Multipart)
|
||||||
copy(imap_socket, Selection::FirstId, Mailbox::Archive).context("copy message to the archive mailbox")?;
|
.context("fetch rfc822 message, should be our first message")?;
|
||||||
|
copy(imap_socket, Selection::FirstId, Mailbox::Archive)
|
||||||
|
.context("copy message to the archive mailbox")?;
|
||||||
append_email(imap_socket, Email::Basic).context("insert email in INBOX")?;
|
append_email(imap_socket, Email::Basic).context("insert email in INBOX")?;
|
||||||
// SEARCH IS NOT IMPLEMENTED YET
|
// SEARCH IS NOT IMPLEMENTED YET
|
||||||
//search(imap_socket).expect("search should return something");
|
//search(imap_socket).expect("search should return something");
|
||||||
add_flags_email(imap_socket, Selection::FirstId, Flag::Deleted)
|
add_flags_email(imap_socket, Selection::FirstId, Flag::Deleted)
|
||||||
.context("should add delete flag to the email")?;
|
.context("should add delete flag to the email")?;
|
||||||
expunge(imap_socket).context("expunge emails")?;
|
expunge(imap_socket).context("expunge emails")?;
|
||||||
rename_mailbox(imap_socket, Mailbox::Archive, Mailbox::Drafts).context("Archive mailbox is renamed Drafts")?;
|
rename_mailbox(imap_socket, Mailbox::Archive, Mailbox::Drafts)
|
||||||
|
.context("Archive mailbox is renamed Drafts")?;
|
||||||
delete_mailbox(imap_socket, Mailbox::Drafts).context("Drafts mailbox is deleted")?;
|
delete_mailbox(imap_socket, Mailbox::Drafts).context("Drafts mailbox is deleted")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
@ -53,13 +56,16 @@ fn rfc3691_imapext_unselect() {
|
||||||
login(imap_socket, Account::Alice).context("login test")?;
|
login(imap_socket, Account::Alice).context("login test")?;
|
||||||
select(imap_socket, Mailbox::Inbox, None).context("select inbox")?;
|
select(imap_socket, Mailbox::Inbox, None).context("select inbox")?;
|
||||||
noop_exists(imap_socket).context("noop loop must detect a new email")?;
|
noop_exists(imap_socket).context("noop loop must detect a new email")?;
|
||||||
add_flags_email(imap_socket, Selection::FirstId, Flag::Deleted).context("add delete flags to the email")?;
|
add_flags_email(imap_socket, Selection::FirstId, Flag::Deleted)
|
||||||
|
.context("add delete flags to the email")?;
|
||||||
unselect(imap_socket)
|
unselect(imap_socket)
|
||||||
.context("unselect inbox while preserving email with the \\Delete flag")?;
|
.context("unselect inbox while preserving email with the \\Delete flag")?;
|
||||||
select(imap_socket, Mailbox::Inbox, Some(1)).context("select inbox again")?;
|
select(imap_socket, Mailbox::Inbox, Some(1)).context("select inbox again")?;
|
||||||
fetch_rfc822(imap_socket, Selection::FirstId, Email::Basic).context("message is still present")?;
|
fetch_rfc822(imap_socket, Selection::FirstId, Email::Basic)
|
||||||
|
.context("message is still present")?;
|
||||||
close(imap_socket).context("close inbox and expunge message")?;
|
close(imap_socket).context("close inbox and expunge message")?;
|
||||||
select(imap_socket, Mailbox::Inbox, Some(0)).context("select inbox again and check it's empty")?;
|
select(imap_socket, Mailbox::Inbox, Some(0))
|
||||||
|
.context("select inbox again and check it's empty")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
@ -94,7 +100,8 @@ fn rfc6851_imapext_move() {
|
||||||
lmtp_deliver_email(lmtp_socket, Email::Basic).context("mail delivered successfully")?;
|
lmtp_deliver_email(lmtp_socket, Email::Basic).context("mail delivered successfully")?;
|
||||||
|
|
||||||
noop_exists(imap_socket).context("noop loop must detect a new email")?;
|
noop_exists(imap_socket).context("noop loop must detect a new email")?;
|
||||||
r#move(imap_socket, Selection::FirstId, Mailbox::Archive).context("message from inbox moved to archive")?;
|
r#move(imap_socket, Selection::FirstId, Mailbox::Archive)
|
||||||
|
.context("message from inbox moved to archive")?;
|
||||||
|
|
||||||
unselect(imap_socket)
|
unselect(imap_socket)
|
||||||
.context("unselect inbox while preserving email with the \\Delete flag")?;
|
.context("unselect inbox while preserving email with the \\Delete flag")?;
|
||||||
|
@ -116,5 +123,6 @@ fn rfc7888_imapext_literal() {
|
||||||
login_with_literal(imap_socket, Account::Alice).context("use literal to connect Alice")?;
|
login_with_literal(imap_socket, Account::Alice).context("use literal to connect Alice")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}).expect("test fully run");
|
})
|
||||||
|
.expect("test fully run");
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ pub enum Mailbox {
|
||||||
|
|
||||||
pub enum Flag {
|
pub enum Flag {
|
||||||
Deleted,
|
Deleted,
|
||||||
Important
|
Important,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Email {
|
pub enum Email {
|
||||||
|
@ -287,8 +287,6 @@ pub fn append_email(imap: &mut TcpStream, content: Email) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub fn add_flags_email(imap: &mut TcpStream, selection: Selection, flag: Flag) -> Result<()> {
|
pub fn add_flags_email(imap: &mut TcpStream, selection: Selection, flag: Flag) -> Result<()> {
|
||||||
let mut buffer: [u8; 1500] = [0; 1500];
|
let mut buffer: [u8; 1500] = [0; 1500];
|
||||||
assert!(matches!(selection, Selection::FirstId));
|
assert!(matches!(selection, Selection::FirstId));
|
||||||
|
@ -390,7 +388,7 @@ pub fn enable(imap: &mut TcpStream, ask: Enable, done: Option<Enable>) -> Result
|
||||||
Some(Enable::Utf8Accept) => {
|
Some(Enable::Utf8Accept) => {
|
||||||
assert_eq!(srv_msg.lines().count(), 2);
|
assert_eq!(srv_msg.lines().count(), 2);
|
||||||
assert!(srv_msg.contains("* ENABLED UTF8=ACCEPT"));
|
assert!(srv_msg.contains("* ENABLED UTF8=ACCEPT"));
|
||||||
},
|
}
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue