aboutsummaryrefslogtreecommitdiff
path: root/src/imap/capability.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/imap/capability.rs')
-rw-r--r--src/imap/capability.rs57
1 files changed, 53 insertions, 4 deletions
diff --git a/src/imap/capability.rs b/src/imap/capability.rs
index feadb6b..6533ccb 100644
--- a/src/imap/capability.rs
+++ b/src/imap/capability.rs
@@ -1,8 +1,11 @@
+use imap_codec::imap_types::command::{FetchModifier, StoreModifier, SelectExamineModifier};
use imap_codec::imap_types::core::NonEmptyVec;
use imap_codec::imap_types::extensions::enable::{CapabilityEnable, Utf8Kind};
use imap_codec::imap_types::response::Capability;
use std::collections::HashSet;
+use crate::imap::attributes::AttributesProxy;
+
fn capability_unselect() -> Capability<'static> {
Capability::try_from("UNSELECT").unwrap()
}
@@ -11,9 +14,11 @@ fn capability_condstore() -> Capability<'static> {
Capability::try_from("CONDSTORE").unwrap()
}
+/*
fn capability_qresync() -> Capability<'static> {
Capability::try_from("QRESYNC").unwrap()
}
+*/
#[derive(Debug, Clone)]
pub struct ServerCapability(HashSet<Capability<'static>>);
@@ -26,7 +31,7 @@ impl Default for ServerCapability {
Capability::Move,
Capability::LiteralPlus,
capability_unselect(),
- //capability_condstore(),
+ capability_condstore(),
//capability_qresync(),
]))
}
@@ -48,15 +53,29 @@ impl ServerCapability {
}
}
-enum ClientStatus {
+#[derive(Clone)]
+pub enum ClientStatus {
NotSupportedByServer,
Disabled,
Enabled,
}
+impl ClientStatus {
+ pub fn is_enabled(&self) -> bool {
+ matches!(self, Self::Enabled)
+ }
+
+ pub fn enable(&self) -> Self {
+ match self {
+ Self::Disabled => Self::Enabled,
+ other => other.clone(),
+ }
+ }
+}
+
pub struct ClientCapability {
- condstore: ClientStatus,
- utf8kind: Option<Utf8Kind>,
+ pub condstore: ClientStatus,
+ pub utf8kind: Option<Utf8Kind>,
}
impl ClientCapability {
@@ -70,6 +89,36 @@ impl ClientCapability {
}
}
+ pub fn enable_condstore(&mut self) {
+ self.condstore = self.condstore.enable();
+ }
+
+ pub fn attributes_enable(&mut self, ap: &AttributesProxy) {
+ if ap.is_enabling_condstore() {
+ self.enable_condstore()
+ }
+ }
+
+ pub fn fetch_modifiers_enable(&mut self, mods: &[FetchModifier]) {
+ if mods.iter().any(|x| matches!(x, FetchModifier::ChangedSince(..))) {
+ self.enable_condstore()
+ }
+ }
+
+ pub fn store_modifiers_enable(&mut self, mods: &[StoreModifier]) {
+ if mods.iter().any(|x| matches!(x, StoreModifier::UnchangedSince(..))) {
+ self.enable_condstore()
+ }
+ }
+
+ pub fn select_enable(&mut self, mods: &[SelectExamineModifier]) {
+ for m in mods.iter() {
+ match m {
+ SelectExamineModifier::Condstore => self.enable_condstore(),
+ }
+ }
+ }
+
pub fn try_enable(
&mut self,
caps: &[CapabilityEnable<'static>],