aboutsummaryrefslogtreecommitdiff
path: root/src/imap/attributes.rs
diff options
context:
space:
mode:
authorQuentin <quentin@dufour.io>2024-01-06 10:38:37 +0000
committerQuentin <quentin@dufour.io>2024-01-06 10:38:37 +0000
commit44ca458c5cf666246e472dea9be70b745a130e8c (patch)
treeb78cca747e5c2bc004cb93b93536623f7abb6ef5 /src/imap/attributes.rs
parentbcf6de83419b405fea95b740869f98d43586ea7c (diff)
parent53dbf82cbce3cb17cbcffd09558677faf8702f54 (diff)
downloadaerogramme-44ca458c5cf666246e472dea9be70b745a130e8c.tar.gz
aerogramme-44ca458c5cf666246e472dea9be70b745a130e8c.zip
Merge pull request 'Aerogramme refactoring' (#57) from feat/more-imap-qol into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/aerogramme/pulls/57
Diffstat (limited to 'src/imap/attributes.rs')
-rw-r--r--src/imap/attributes.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/imap/attributes.rs b/src/imap/attributes.rs
new file mode 100644
index 0000000..7a55632
--- /dev/null
+++ b/src/imap/attributes.rs
@@ -0,0 +1,49 @@
+use imap_codec::imap_types::fetch::{MacroOrMessageDataItemNames, MessageDataItemName};
+
+/// Internal decisions based on fetched attributes
+/// passed by the client
+
+pub struct AttributesProxy {
+ pub attrs: Vec<MessageDataItemName<'static>>,
+}
+impl AttributesProxy {
+ pub fn new(attrs: &MacroOrMessageDataItemNames<'static>, is_uid_fetch: bool) -> Self {
+ // 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);
+ }
+
+ Self { attrs: fetch_attrs }
+ }
+
+ pub fn need_body(&self) -> bool {
+ self.attrs.iter().any(|x| {
+ matches!(
+ x,
+ MessageDataItemName::Body
+ | MessageDataItemName::BodyExt { .. }
+ | MessageDataItemName::Rfc822
+ | MessageDataItemName::Rfc822Text
+ | MessageDataItemName::BodyStructure
+ )
+ })
+ }
+}