aboutsummaryrefslogtreecommitdiff
path: root/src/imap/capability.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-01-03 16:52:31 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-01-03 16:52:31 +0100
commit74686ebb778b740ccfccfbf61ccd24628f60e9d0 (patch)
tree0eefb4982d14499b47c7d57c7256004500f7edb3 /src/imap/capability.rs
parentb91c64920d7454d50b60ad3abb58fad9d09f0511 (diff)
downloadaerogramme-74686ebb778b740ccfccfbf61ccd24628f60e9d0.tar.gz
aerogramme-74686ebb778b740ccfccfbf61ccd24628f60e9d0.zip
append ignore dates instead of failing
Diffstat (limited to 'src/imap/capability.rs')
-rw-r--r--src/imap/capability.rs74
1 files changed, 73 insertions, 1 deletions
diff --git a/src/imap/capability.rs b/src/imap/capability.rs
index b98e8f8..f6b5a51 100644
--- a/src/imap/capability.rs
+++ b/src/imap/capability.rs
@@ -1,10 +1,24 @@
use imap_codec::imap_types::core::NonEmptyVec;
use imap_codec::imap_types::response::Capability;
+fn capability_unselect() -> Capability<'static> {
+ Capability::try_from("UNSELECT").unwrap()
+}
+
+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 {
r#move: bool,
unselect: bool,
+ condstore: bool,
+ qresync: bool,
}
impl Default for ServerCapability {
@@ -12,6 +26,8 @@ impl Default for ServerCapability {
Self {
r#move: true,
unselect: true,
+ condstore: false,
+ qresync: false,
}
}
}
@@ -23,8 +39,64 @@ impl ServerCapability {
acc.push(Capability::Move);
}
if self.unselect {
- acc.push(Capability::try_from("UNSELECT").unwrap());
+ acc.push(capability_unselect());
+ }
+ if self.condstore {
+ acc.push(capability_condstore());
+ }
+ if self.qresync {
+ acc.push(capability_qresync());
}
acc.try_into().unwrap()
}
+
+ pub fn support(&self, cap: &Capability<'static>) -> bool {
+ match cap {
+ Capability::Imap4Rev1 => true,
+ Capability::Move => self.r#move,
+ x if *x == capability_condstore() => self.condstore,
+ x if *x == capability_qresync() => self.qresync,
+ x if *x == capability_unselect() => self.unselect,
+ _ => false,
+ }
+ }
+}
+
+pub struct ClientCapability {
+ condstore: bool,
+ qresync: bool,
+}
+
+impl Default for ClientCapability {
+ fn default() -> Self {
+ Self {
+ condstore: false,
+ qresync: false,
+ }
+ }
+}
+
+impl ClientCapability {
+ pub fn try_enable(
+ &mut self,
+ srv: &ServerCapability,
+ caps: &[Capability<'static>],
+ ) -> Vec<Capability<'static>> {
+ let mut enabled = vec![];
+ for cap in caps {
+ match cap {
+ x if *x == capability_condstore() && srv.condstore && !self.condstore => {
+ self.condstore = true;
+ enabled.push(x.clone());
+ }
+ x if *x == capability_qresync() && srv.qresync && !self.qresync => {
+ self.qresync = true;
+ enabled.push(x.clone());
+ }
+ _ => (),
+ }
+ }
+
+ enabled
+ }
}