Fetch and store modifiers are parsed

This commit is contained in:
Quentin 2024-01-11 16:55:37 +01:00
parent a9d33c6708
commit 60a166185a
Signed by: quentin
GPG key ID: E9602264D639FF68
5 changed files with 25 additions and 24 deletions

4
Cargo.lock generated
View file

@ -1807,7 +1807,7 @@ dependencies = [
[[package]] [[package]]
name = "imap-codec" name = "imap-codec"
version = "2.0.0" version = "2.0.0"
source = "git+https://github.com/superboum/imap-codec?branch=custom/aerogramme#3fdc1f3184ec121823d44b3f39e56b448ac80751" source = "git+https://github.com/superboum/imap-codec?branch=custom/aerogramme#b0a80c4826f3d8bf2d2e69f68443c261e62bb40f"
dependencies = [ dependencies = [
"abnf-core", "abnf-core",
"base64 0.21.5", "base64 0.21.5",
@ -1834,7 +1834,7 @@ dependencies = [
[[package]] [[package]]
name = "imap-types" name = "imap-types"
version = "2.0.0" version = "2.0.0"
source = "git+https://github.com/superboum/imap-codec?branch=custom/aerogramme#3fdc1f3184ec121823d44b3f39e56b448ac80751" source = "git+https://github.com/superboum/imap-codec?branch=custom/aerogramme#b0a80c4826f3d8bf2d2e69f68443c261e62bb40f"
dependencies = [ dependencies = [
"base64 0.21.5", "base64 0.21.5",
"bounded-static", "bounded-static",

View file

@ -1,4 +1,5 @@
use imap_codec::imap_types::core::{Atom, NonEmptyVec}; use imap_codec::imap_types::command::SelectExamineModifier;
use imap_codec::imap_types::core::NonEmptyVec;
use imap_codec::imap_types::extensions::enable::{CapabilityEnable, Utf8Kind}; use imap_codec::imap_types::extensions::enable::{CapabilityEnable, Utf8Kind};
use imap_codec::imap_types::response::Capability; use imap_codec::imap_types::response::Capability;
use std::collections::HashSet; use std::collections::HashSet;
@ -90,10 +91,10 @@ impl ClientCapability {
self.condstore = self.condstore.enable(); self.condstore = self.condstore.enable();
} }
pub fn select_enable(&mut self, atoms: &[Atom]) { pub fn select_enable(&mut self, mods: &[SelectExamineModifier]) {
for at in atoms.iter() { for m in mods.iter() {
if at.as_ref().to_uppercase() == "CONDSTORE" { match m {
self.enable_condstore(); SelectExamineModifier::Condstore => self.enable_condstore(),
} }
} }
} }

View file

@ -2,7 +2,7 @@ use std::collections::BTreeMap;
use std::sync::Arc; use std::sync::Arc;
use anyhow::{anyhow, bail, Result}; use anyhow::{anyhow, bail, Result};
use imap_codec::imap_types::command::{Command, CommandBody}; use imap_codec::imap_types::command::{Command, CommandBody, SelectExamineModifier};
use imap_codec::imap_types::core::{Atom, Literal, NonEmptyVec, QuotedChar}; use imap_codec::imap_types::core::{Atom, Literal, NonEmptyVec, QuotedChar};
use imap_codec::imap_types::datetime::DateTime; use imap_codec::imap_types::datetime::DateTime;
use imap_codec::imap_types::extensions::enable::CapabilityEnable; use imap_codec::imap_types::extensions::enable::CapabilityEnable;
@ -58,8 +58,8 @@ pub async fn dispatch<'a>(
} => ctx.status(mailbox, item_names).await, } => ctx.status(mailbox, item_names).await,
CommandBody::Subscribe { mailbox } => ctx.subscribe(mailbox).await, CommandBody::Subscribe { mailbox } => ctx.subscribe(mailbox).await,
CommandBody::Unsubscribe { mailbox } => ctx.unsubscribe(mailbox).await, CommandBody::Unsubscribe { mailbox } => ctx.unsubscribe(mailbox).await,
CommandBody::Select { mailbox, parameters } => ctx.select(mailbox, parameters).await, CommandBody::Select { mailbox, modifiers } => ctx.select(mailbox, modifiers).await,
CommandBody::Examine { mailbox, parameters } => ctx.examine(mailbox, parameters).await, CommandBody::Examine { mailbox, modifiers } => ctx.examine(mailbox, modifiers).await,
CommandBody::Append { CommandBody::Append {
mailbox, mailbox,
flags, flags,
@ -422,11 +422,9 @@ impl<'a> AuthenticatedContext<'a> {
async fn select( async fn select(
self, self,
mailbox: &MailboxCodec<'a>, mailbox: &MailboxCodec<'a>,
parameters: &Option<NonEmptyVec<Atom<'a>>>, modifiers: &[SelectExamineModifier],
) -> Result<(Response<'static>, flow::Transition)> { ) -> Result<(Response<'static>, flow::Transition)> {
parameters.as_ref().map(|plist| self.client_capabilities.select_enable(modifiers);
self.client_capabilities.select_enable(plist.as_ref())
);
let name: &str = MailboxName(mailbox).try_into()?; let name: &str = MailboxName(mailbox).try_into()?;
@ -462,11 +460,9 @@ impl<'a> AuthenticatedContext<'a> {
async fn examine( async fn examine(
self, self,
mailbox: &MailboxCodec<'a>, mailbox: &MailboxCodec<'a>,
parameters: &Option<NonEmptyVec<Atom<'a>>>, modifiers: &[SelectExamineModifier],
) -> Result<(Response<'static>, flow::Transition)> { ) -> Result<(Response<'static>, flow::Transition)> {
parameters.as_ref().map(|plist| self.client_capabilities.select_enable(modifiers);
self.client_capabilities.select_enable(plist.as_ref())
);
let name: &str = MailboxName(mailbox).try_into()?; let name: &str = MailboxName(mailbox).try_into()?;

View file

@ -1,7 +1,7 @@
use std::sync::Arc; use std::sync::Arc;
use anyhow::Result; use anyhow::Result;
use imap_codec::imap_types::command::{Command, CommandBody}; use imap_codec::imap_types::command::{Command, CommandBody, FetchModifier};
use imap_codec::imap_types::core::Charset; use imap_codec::imap_types::core::Charset;
use imap_codec::imap_types::fetch::MacroOrMessageDataItemNames; use imap_codec::imap_types::fetch::MacroOrMessageDataItemNames;
use imap_codec::imap_types::search::SearchKey; use imap_codec::imap_types::search::SearchKey;
@ -37,8 +37,9 @@ pub async fn dispatch(ctx: ExaminedContext<'_>) -> Result<(Response<'static>, fl
CommandBody::Fetch { CommandBody::Fetch {
sequence_set, sequence_set,
macro_or_item_names, macro_or_item_names,
modifiers,
uid, uid,
} => ctx.fetch(sequence_set, macro_or_item_names, uid).await, } => ctx.fetch(sequence_set, macro_or_item_names, modifiers, uid).await,
CommandBody::Search { CommandBody::Search {
charset, charset,
criteria, criteria,
@ -88,6 +89,7 @@ impl<'a> ExaminedContext<'a> {
self, self,
sequence_set: &SequenceSet, sequence_set: &SequenceSet,
attributes: &'a MacroOrMessageDataItemNames<'static>, attributes: &'a MacroOrMessageDataItemNames<'static>,
modifiers: &[FetchModifier],
uid: &bool, uid: &bool,
) -> Result<(Response<'static>, flow::Transition)> { ) -> Result<(Response<'static>, flow::Transition)> {
match self.mailbox.fetch(sequence_set, attributes, uid).await { match self.mailbox.fetch(sequence_set, attributes, uid).await {

View file

@ -1,8 +1,8 @@
use std::sync::Arc; use std::sync::Arc;
use anyhow::Result; use anyhow::Result;
use imap_codec::imap_types::command::{Command, CommandBody, StoreModifier}; use imap_codec::imap_types::command::{Command, CommandBody, FetchModifier, StoreModifier};
use imap_codec::imap_types::core::{Charset, Atom}; use imap_codec::imap_types::core::Charset;
use imap_codec::imap_types::fetch::MacroOrMessageDataItemNames; use imap_codec::imap_types::fetch::MacroOrMessageDataItemNames;
use imap_codec::imap_types::flag::{Flag, StoreResponse, StoreType}; use imap_codec::imap_types::flag::{Flag, StoreResponse, StoreType};
use imap_codec::imap_types::mailbox::Mailbox as MailboxCodec; use imap_codec::imap_types::mailbox::Mailbox as MailboxCodec;
@ -43,8 +43,9 @@ pub async fn dispatch<'a>(
CommandBody::Fetch { CommandBody::Fetch {
sequence_set, sequence_set,
macro_or_item_names, macro_or_item_names,
modifiers,
uid, uid,
} => ctx.fetch(sequence_set, macro_or_item_names, uid).await, } => ctx.fetch(sequence_set, macro_or_item_names, modifiers, uid).await,
CommandBody::Search { CommandBody::Search {
charset, charset,
criteria, criteria,
@ -114,6 +115,7 @@ impl<'a> SelectedContext<'a> {
self, self,
sequence_set: &SequenceSet, sequence_set: &SequenceSet,
attributes: &'a MacroOrMessageDataItemNames<'static>, attributes: &'a MacroOrMessageDataItemNames<'static>,
modifiers: &[FetchModifier],
uid: &bool, uid: &bool,
) -> Result<(Response<'static>, flow::Transition)> { ) -> Result<(Response<'static>, flow::Transition)> {
match self.mailbox.fetch(sequence_set, attributes, uid).await { match self.mailbox.fetch(sequence_set, attributes, uid).await {
@ -194,7 +196,7 @@ impl<'a> SelectedContext<'a> {
kind: &StoreType, kind: &StoreType,
response: &StoreResponse, response: &StoreResponse,
flags: &[Flag<'a>], flags: &[Flag<'a>],
modifiers: &[(Atom<'a>, StoreModifier<'a>)], modifiers: &[StoreModifier],
uid: &bool, uid: &bool,
) -> Result<(Response<'static>, flow::Transition)> { ) -> Result<(Response<'static>, flow::Transition)> {
tracing::info!(modifiers=?modifiers); tracing::info!(modifiers=?modifiers);