WIP
parent
6c576b2606
commit
456c21cc03
|
@ -559,39 +559,68 @@ pub fn fetch_response(input: &[u8]) -> ImapParseResult<FetchResponse<'_>> {
|
|||
seq_or_uid,
|
||||
attributes,
|
||||
}) => {
|
||||
let attributes = attributes.into_inner();
|
||||
|
||||
let flags = attributes.iter().find_map(|attribute| match attribute {
|
||||
FetchAttributeValue::Flags(flags) => Some((
|
||||
// TODO
|
||||
flags
|
||||
.iter()
|
||||
.map(|flag| crate::Flag::from(flag.clone()))
|
||||
.collect(),
|
||||
// TODO
|
||||
vec![],
|
||||
)),
|
||||
_ => None,
|
||||
});
|
||||
|
||||
let body = attributes
|
||||
.into_iter()
|
||||
.find_map(|attribute| match attribute {
|
||||
FetchAttributeValue::BodyExt { data, .. } => data.into_option(),
|
||||
_ => None,
|
||||
});
|
||||
|
||||
let mut ret = FetchResponse {
|
||||
uid: Some(seq_or_uid.get() as usize), // TODO: Can't be both.
|
||||
uid: None,
|
||||
message_sequence_number: seq_or_uid.get() as usize, // TODO: Can't be both.
|
||||
modseq: None, // TODO: HIGHESTMODSEQ?
|
||||
flags,
|
||||
body,
|
||||
references: None, // TODO
|
||||
envelope: None, // TODO
|
||||
modseq: None, // TODO: HIGHESTMODSEQ?
|
||||
flags: None,
|
||||
body: None,
|
||||
references: None,
|
||||
envelope: None,
|
||||
raw_fetch_value: &[], // TODO
|
||||
};
|
||||
|
||||
for attribute in attributes.into_iter() {
|
||||
// TODO: What should be present and what not?
|
||||
match attribute {
|
||||
FetchAttributeValue::Uid(uid) => ret.uid = Some(uid.get() as usize),
|
||||
FetchAttributeValue::Flags(flags) => {
|
||||
ret.flags = Some((
|
||||
// TODO
|
||||
flags
|
||||
.into_iter()
|
||||
.map(|flag| crate::Flag::from(flag))
|
||||
.collect(),
|
||||
// TODO
|
||||
vec![],
|
||||
))
|
||||
}
|
||||
FetchAttributeValue::BodyExt {
|
||||
section: None,
|
||||
origin: None,
|
||||
data,
|
||||
} => {
|
||||
ret.body = data.into_option();
|
||||
}
|
||||
//TODO: Make query of REFERENCES more ergonomic.
|
||||
FetchAttributeValue::BodyExt {
|
||||
section: Some(Section::HeaderFields(None, fields)),
|
||||
origin: None,
|
||||
data,
|
||||
} if fields
|
||||
.into_iter()
|
||||
.map(|i| i.as_ref())
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
.collect::<Vec<_>>()
|
||||
.contains(b"REFERENCES") =>
|
||||
{
|
||||
// TODO
|
||||
println!("YAY!")
|
||||
}
|
||||
FetchAttributeValue::Envelope(envelope) => {
|
||||
// TODO
|
||||
}
|
||||
FetchAttributeValue::BodyStructure(body_structure) => {
|
||||
// TODO
|
||||
}
|
||||
unexpected => {
|
||||
// Ignore unexpected attributes.
|
||||
panic!("Unexpected attribute `{:?}`", unexpected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok((remainder, ret, None))
|
||||
}
|
||||
_ => todo!(),
|
||||
|
@ -900,7 +929,7 @@ fn test_imap_fetch_response() {
|
|||
flags: Some((Flag::SEEN, vec![])),
|
||||
modseq: None,
|
||||
body: None,
|
||||
references: None,
|
||||
references: None, // TODO: Some?
|
||||
envelope: Some(env),
|
||||
raw_fetch_value: input,
|
||||
},
|
||||
|
|
|
@ -232,16 +232,20 @@ crate::declare_u64_hash!(EnvelopeHash);
|
|||
/// bytes into an `Attachment` object.
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct Envelope {
|
||||
pub hash: EnvelopeHash,
|
||||
// ----- IMAP4rev1 -----
|
||||
pub date: String,
|
||||
pub timestamp: UnixTimestamp,
|
||||
pub subject: Option<String>,
|
||||
pub from: SmallVec<[Address; 1]>,
|
||||
// TODO: sender
|
||||
// TODO: reply_to
|
||||
pub to: SmallVec<[Address; 1]>,
|
||||
pub cc: SmallVec<[Address; 1]>,
|
||||
pub bcc: Vec<Address>,
|
||||
pub subject: Option<String>,
|
||||
pub message_id: MessageID,
|
||||
pub in_reply_to: Option<MessageID>,
|
||||
pub message_id: MessageID,
|
||||
// ----- Other -----
|
||||
pub hash: EnvelopeHash,
|
||||
pub timestamp: UnixTimestamp,
|
||||
pub references: Option<References>,
|
||||
pub other_headers: HeaderMap,
|
||||
pub thread: ThreadNodeHash,
|
||||
|
|
Loading…
Reference in New Issue