2024-01-11 22:02:03 +00:00
|
|
|
use imap_codec::imap_types::command::FetchModifier;
|
2024-01-18 17:03:21 +00:00
|
|
|
use imap_codec::imap_types::fetch::{MacroOrMessageDataItemNames, MessageDataItemName, Section};
|
2024-01-04 19:54:21 +00:00
|
|
|
|
|
|
|
/// Internal decisions based on fetched attributes
|
|
|
|
/// passed by the client
|
|
|
|
|
|
|
|
pub struct AttributesProxy {
|
|
|
|
pub attrs: Vec<MessageDataItemName<'static>>,
|
|
|
|
}
|
|
|
|
impl AttributesProxy {
|
2024-01-18 17:03:21 +00:00
|
|
|
pub fn new(
|
|
|
|
attrs: &MacroOrMessageDataItemNames<'static>,
|
|
|
|
modifiers: &[FetchModifier],
|
|
|
|
is_uid_fetch: bool,
|
|
|
|
) -> Self {
|
2024-01-04 19:54:21 +00:00
|
|
|
// Expand macros
|
|
|
|
let mut fetch_attrs = match attrs {
|
|
|
|
MacroOrMessageDataItemNames::Macro(m) => {
|
|
|
|
use imap_codec::imap_types::fetch::Macro;
|
|
|
|
use MessageDataItemName::*;
|
|
|
|
match m {
|
|
|
|
Macro::All => vec![Flags, InternalDate, Rfc822Size, Envelope],
|
|
|
|
Macro::Fast => vec![Flags, InternalDate, Rfc822Size],
|
|
|
|
Macro::Full => vec![Flags, InternalDate, Rfc822Size, Envelope, Body],
|
|
|
|
_ => {
|
|
|
|
tracing::error!("unimplemented macro");
|
|
|
|
vec![]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MacroOrMessageDataItemNames::MessageDataItemNames(a) => a.clone(),
|
|
|
|
};
|
|
|
|
|
|
|
|
// Handle uids
|
|
|
|
if is_uid_fetch && !fetch_attrs.contains(&MessageDataItemName::Uid) {
|
|
|
|
fetch_attrs.push(MessageDataItemName::Uid);
|
|
|
|
}
|
2024-01-11 22:02:03 +00:00
|
|
|
|
|
|
|
// Handle inferred MODSEQ tag
|
|
|
|
let is_changed_since = modifiers
|
|
|
|
.iter()
|
|
|
|
.any(|m| matches!(m, FetchModifier::ChangedSince(..)));
|
|
|
|
if is_changed_since && !fetch_attrs.contains(&MessageDataItemName::ModSeq) {
|
|
|
|
fetch_attrs.push(MessageDataItemName::ModSeq);
|
|
|
|
}
|
2024-01-04 19:54:21 +00:00
|
|
|
|
|
|
|
Self { attrs: fetch_attrs }
|
|
|
|
}
|
|
|
|
|
2024-01-10 17:38:21 +00:00
|
|
|
pub fn is_enabling_condstore(&self) -> bool {
|
2024-01-18 17:03:21 +00:00
|
|
|
self.attrs
|
|
|
|
.iter()
|
|
|
|
.any(|x| matches!(x, MessageDataItemName::ModSeq))
|
2024-01-10 17:38:21 +00:00
|
|
|
}
|
|
|
|
|
2024-01-04 19:54:21 +00:00
|
|
|
pub fn need_body(&self) -> bool {
|
2024-01-18 17:03:21 +00:00
|
|
|
self.attrs.iter().any(|x| match x {
|
|
|
|
MessageDataItemName::Body
|
|
|
|
| MessageDataItemName::Rfc822
|
|
|
|
| MessageDataItemName::Rfc822Text
|
|
|
|
| MessageDataItemName::BodyStructure => true,
|
2024-01-08 20:32:55 +00:00
|
|
|
|
2024-01-18 17:03:21 +00:00
|
|
|
MessageDataItemName::BodyExt {
|
|
|
|
section: Some(section),
|
|
|
|
partial: _,
|
|
|
|
peek: _,
|
|
|
|
} => match section {
|
|
|
|
Section::Header(None)
|
|
|
|
| Section::HeaderFields(None, _)
|
|
|
|
| Section::HeaderFieldsNot(None, _) => false,
|
|
|
|
_ => true,
|
|
|
|
},
|
|
|
|
MessageDataItemName::BodyExt { .. } => true,
|
|
|
|
_ => false,
|
2024-01-04 19:54:21 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|