From 7ebc708acab9c91db41652cfbfe2814a3a27569d Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 3 Jan 2024 09:21:46 +0100 Subject: unselect implemented rfc3691 --- src/imap/command/anystate.rs | 7 +++++-- src/imap/command/examined.rs | 11 +++++++---- src/imap/command/selected.rs | 13 +++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) (limited to 'src/imap/command') diff --git a/src/imap/command/anystate.rs b/src/imap/command/anystate.rs index 42fe645..f326852 100644 --- a/src/imap/command/anystate.rs +++ b/src/imap/command/anystate.rs @@ -6,8 +6,11 @@ use crate::imap::flow; use crate::imap::response::Response; pub(crate) fn capability(tag: Tag<'static>) -> Result<(Response<'static>, flow::Transition)> { - let capabilities: NonEmptyVec = - (vec![Capability::Imap4Rev1, Capability::Idle]).try_into()?; + let capabilities: NonEmptyVec = (vec![ + Capability::Imap4Rev1, + Capability::try_from("UNSELECT").unwrap(), + ]) + .try_into()?; let res = Response::build() .tag(tag) .message("Server capabilities") diff --git a/src/imap/command/examined.rs b/src/imap/command/examined.rs index 7de94f4..8876297 100644 --- a/src/imap/command/examined.rs +++ b/src/imap/command/examined.rs @@ -28,7 +28,7 @@ pub async fn dispatch(ctx: ExaminedContext<'_>) -> Result<(Response<'static>, fl // Specific to the EXAMINE state (specialization of the SELECTED state) // ~3 commands -> close, fetch, search + NOOP - CommandBody::Close => ctx.close().await, + CommandBody::Close => ctx.close("CLOSE").await, CommandBody::Fetch { sequence_set, macro_or_item_names, @@ -44,10 +44,13 @@ pub async fn dispatch(ctx: ExaminedContext<'_>) -> Result<(Response<'static>, fl Response::build() .to_req(ctx.req) .message("Forbidden command: can't write in read-only mode (EXAMINE)") - .bad()?, + .no()?, flow::Transition::None, )), + // UNSELECT extension (rfc3691) + CommandBody::Unselect => ctx.close("UNSELECT").await, + // In examined mode, we fallback to authenticated when needed _ => { authenticated::dispatch(authenticated::AuthenticatedContext { @@ -64,11 +67,11 @@ pub async fn dispatch(ctx: ExaminedContext<'_>) -> Result<(Response<'static>, fl impl<'a> ExaminedContext<'a> { /// CLOSE in examined state is not the same as in selected state /// (in selected state it also does an EXPUNGE, here it doesn't) - async fn close(self) -> Result<(Response<'static>, flow::Transition)> { + async fn close(self, kind: &str) -> Result<(Response<'static>, flow::Transition)> { Ok(( Response::build() .to_req(self.req) - .message("CLOSE completed") + .message(format!("{} completed", kind)) .ok()?, flow::Transition::Unselect, )) diff --git a/src/imap/command/selected.rs b/src/imap/command/selected.rs index 220a952..0653226 100644 --- a/src/imap/command/selected.rs +++ b/src/imap/command/selected.rs @@ -59,6 +59,9 @@ pub async fn dispatch<'a>( uid, } => ctx.copy(sequence_set, mailbox, uid).await, + // UNSELECT extension (rfc3691) + CommandBody::Unselect => ctx.unselect().await, + // In selected mode, we fallback to authenticated when needed _ => { authenticated::dispatch(authenticated::AuthenticatedContext { @@ -84,6 +87,16 @@ impl<'a> SelectedContext<'a> { )) } + async fn unselect(self) -> Result<(Response<'static>, flow::Transition)> { + Ok(( + Response::build() + .to_req(self.req) + .message("UNSELECT completed") + .ok()?, + flow::Transition::Unselect, + )) + } + pub async fn fetch( self, sequence_set: &SequenceSet, -- cgit v1.2.3 From 6d37924399dd5d04f5be2506e3e044dd165f6399 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 3 Jan 2024 12:29:19 +0100 Subject: rework capability --- src/imap/command/anonymous.rs | 8 +++++++- src/imap/command/anystate.rs | 14 +++++--------- src/imap/command/authenticated.rs | 6 +++++- src/imap/command/examined.rs | 8 +++++++- src/imap/command/selected.rs | 8 +++++++- 5 files changed, 31 insertions(+), 13 deletions(-) (limited to 'src/imap/command') diff --git a/src/imap/command/anonymous.rs b/src/imap/command/anonymous.rs index fbd10e9..fda78c2 100644 --- a/src/imap/command/anonymous.rs +++ b/src/imap/command/anonymous.rs @@ -1,10 +1,12 @@ use anyhow::Result; use imap_codec::imap_types::command::{Command, CommandBody}; use imap_codec::imap_types::core::AString; +use imap_codec::imap_types::response::Code; use imap_codec::imap_types::secret::Secret; use crate::imap::command::anystate; use crate::imap::flow; +use crate::imap::capability::ServerCapability; use crate::imap::response::Response; use crate::login::ArcLoginProvider; use crate::mail::user::User; @@ -13,6 +15,7 @@ use crate::mail::user::User; pub struct AnonymousContext<'a> { pub req: &'a Command<'static>, + pub server_capabilities: &'a ServerCapability, pub login_provider: &'a ArcLoginProvider, } @@ -20,7 +23,9 @@ pub async fn dispatch(ctx: AnonymousContext<'_>) -> Result<(Response<'static>, f match &ctx.req.body { // Any State CommandBody::Noop => anystate::noop_nothing(ctx.req.tag.clone()), - CommandBody::Capability => anystate::capability(ctx.req.tag.clone()), + CommandBody::Capability => anystate::capability( + ctx.req.tag.clone(), + ctx.server_capabilities), CommandBody::Logout => anystate::logout(), // Specific to anonymous context (3 commands) @@ -69,6 +74,7 @@ impl<'a> AnonymousContext<'a> { Ok(( Response::build() .to_req(self.req) + .code(Code::Capability(self.server_capabilities.to_vec())) .message("Completed") .ok()?, flow::Transition::Authenticate(user), diff --git a/src/imap/command/anystate.rs b/src/imap/command/anystate.rs index f326852..7d7c0b2 100644 --- a/src/imap/command/anystate.rs +++ b/src/imap/command/anystate.rs @@ -1,20 +1,16 @@ use anyhow::Result; -use imap_codec::imap_types::core::{NonEmptyVec, Tag}; -use imap_codec::imap_types::response::{Capability, Data}; +use imap_codec::imap_types::core::Tag; +use imap_codec::imap_types::response::Data; use crate::imap::flow; +use crate::imap::capability::ServerCapability; use crate::imap::response::Response; -pub(crate) fn capability(tag: Tag<'static>) -> Result<(Response<'static>, flow::Transition)> { - let capabilities: NonEmptyVec = (vec![ - Capability::Imap4Rev1, - Capability::try_from("UNSELECT").unwrap(), - ]) - .try_into()?; +pub(crate) fn capability(tag: Tag<'static>, cap: &ServerCapability) -> Result<(Response<'static>, flow::Transition)> { let res = Response::build() .tag(tag) .message("Server capabilities") - .data(Data::Capability(capabilities)) + .data(Data::Capability(cap.to_vec())) .ok()?; Ok((res, flow::Transition::None)) diff --git a/src/imap/command/authenticated.rs b/src/imap/command/authenticated.rs index 1bb4c6d..a6a5203 100644 --- a/src/imap/command/authenticated.rs +++ b/src/imap/command/authenticated.rs @@ -14,6 +14,7 @@ use crate::imap::command::{anystate, MailboxName}; use crate::imap::flow; use crate::imap::mailbox_view::MailboxView; use crate::imap::response::Response; +use crate::imap::capability::ServerCapability; use crate::mail::mailbox::Mailbox; use crate::mail::uidindex::*; @@ -22,6 +23,7 @@ use crate::mail::IMF; pub struct AuthenticatedContext<'a> { pub req: &'a Command<'static>, + pub server_capabilities: &'a ServerCapability, pub user: &'a Arc, } @@ -31,7 +33,9 @@ pub async fn dispatch<'a>( match &ctx.req.body { // Any state CommandBody::Noop => anystate::noop_nothing(ctx.req.tag.clone()), - CommandBody::Capability => anystate::capability(ctx.req.tag.clone()), + CommandBody::Capability => anystate::capability( + ctx.req.tag.clone(), + ctx.server_capabilities), CommandBody::Logout => anystate::logout(), // Specific to this state (11 commands) diff --git a/src/imap/command/examined.rs b/src/imap/command/examined.rs index 8876297..7cccf7b 100644 --- a/src/imap/command/examined.rs +++ b/src/imap/command/examined.rs @@ -11,19 +11,24 @@ use crate::imap::command::{anystate, authenticated}; use crate::imap::flow; use crate::imap::mailbox_view::MailboxView; use crate::imap::response::Response; +use crate::imap::capability::ServerCapability; use crate::mail::user::User; pub struct ExaminedContext<'a> { pub req: &'a Command<'static>, pub user: &'a Arc, pub mailbox: &'a mut MailboxView, + pub server_capabilities: &'a ServerCapability, } pub async fn dispatch(ctx: ExaminedContext<'_>) -> Result<(Response<'static>, flow::Transition)> { match &ctx.req.body { // Any State // noop is specific to this state - CommandBody::Capability => anystate::capability(ctx.req.tag.clone()), + CommandBody::Capability => anystate::capability( + ctx.req.tag.clone(), + ctx.server_capabilities, + ), CommandBody::Logout => anystate::logout(), // Specific to the EXAMINE state (specialization of the SELECTED state) @@ -55,6 +60,7 @@ pub async fn dispatch(ctx: ExaminedContext<'_>) -> Result<(Response<'static>, fl _ => { authenticated::dispatch(authenticated::AuthenticatedContext { req: ctx.req, + server_capabilities: ctx.server_capabilities, user: ctx.user, }) .await diff --git a/src/imap/command/selected.rs b/src/imap/command/selected.rs index 0653226..681b509 100644 --- a/src/imap/command/selected.rs +++ b/src/imap/command/selected.rs @@ -14,6 +14,7 @@ use crate::imap::command::{anystate, authenticated, MailboxName}; use crate::imap::flow; use crate::imap::mailbox_view::MailboxView; use crate::imap::response::Response; +use crate::imap::capability::ServerCapability; use crate::mail::user::User; @@ -21,6 +22,7 @@ pub struct SelectedContext<'a> { pub req: &'a Command<'static>, pub user: &'a Arc, pub mailbox: &'a mut MailboxView, + pub server_capabilities: &'a ServerCapability, } pub async fn dispatch<'a>( @@ -29,7 +31,10 @@ pub async fn dispatch<'a>( match &ctx.req.body { // Any State // noop is specific to this state - CommandBody::Capability => anystate::capability(ctx.req.tag.clone()), + CommandBody::Capability => anystate::capability( + ctx.req.tag.clone(), + ctx.server_capabilities, + ), CommandBody::Logout => anystate::logout(), // Specific to this state (7 commands + NOOP) @@ -66,6 +71,7 @@ pub async fn dispatch<'a>( _ => { authenticated::dispatch(authenticated::AuthenticatedContext { req: ctx.req, + server_capabilities: ctx.server_capabilities, user: ctx.user, }) .await -- cgit v1.2.3 From ef257e286a5377031bfde9645629825d3223b3d4 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 3 Jan 2024 15:00:05 +0100 Subject: implement move --- src/imap/command/anonymous.rs | 8 ++--- src/imap/command/anystate.rs | 7 ++-- src/imap/command/authenticated.rs | 8 ++--- src/imap/command/examined.rs | 9 +++--- src/imap/command/selected.rs | 68 ++++++++++++++++++++++++++++++++++++--- 5 files changed, 80 insertions(+), 20 deletions(-) (limited to 'src/imap/command') diff --git a/src/imap/command/anonymous.rs b/src/imap/command/anonymous.rs index fda78c2..0582b06 100644 --- a/src/imap/command/anonymous.rs +++ b/src/imap/command/anonymous.rs @@ -4,9 +4,9 @@ use imap_codec::imap_types::core::AString; use imap_codec::imap_types::response::Code; use imap_codec::imap_types::secret::Secret; +use crate::imap::capability::ServerCapability; use crate::imap::command::anystate; use crate::imap::flow; -use crate::imap::capability::ServerCapability; use crate::imap::response::Response; use crate::login::ArcLoginProvider; use crate::mail::user::User; @@ -23,9 +23,9 @@ pub async fn dispatch(ctx: AnonymousContext<'_>) -> Result<(Response<'static>, f match &ctx.req.body { // Any State CommandBody::Noop => anystate::noop_nothing(ctx.req.tag.clone()), - CommandBody::Capability => anystate::capability( - ctx.req.tag.clone(), - ctx.server_capabilities), + CommandBody::Capability => { + anystate::capability(ctx.req.tag.clone(), ctx.server_capabilities) + } CommandBody::Logout => anystate::logout(), // Specific to anonymous context (3 commands) diff --git a/src/imap/command/anystate.rs b/src/imap/command/anystate.rs index 7d7c0b2..718ba3f 100644 --- a/src/imap/command/anystate.rs +++ b/src/imap/command/anystate.rs @@ -2,11 +2,14 @@ use anyhow::Result; use imap_codec::imap_types::core::Tag; use imap_codec::imap_types::response::Data; -use crate::imap::flow; use crate::imap::capability::ServerCapability; +use crate::imap::flow; use crate::imap::response::Response; -pub(crate) fn capability(tag: Tag<'static>, cap: &ServerCapability) -> Result<(Response<'static>, flow::Transition)> { +pub(crate) fn capability( + tag: Tag<'static>, + cap: &ServerCapability, +) -> Result<(Response<'static>, flow::Transition)> { let res = Response::build() .tag(tag) .message("Server capabilities") diff --git a/src/imap/command/authenticated.rs b/src/imap/command/authenticated.rs index a6a5203..2970b63 100644 --- a/src/imap/command/authenticated.rs +++ b/src/imap/command/authenticated.rs @@ -10,11 +10,11 @@ use imap_codec::imap_types::mailbox::{ListMailbox, Mailbox as MailboxCodec}; use imap_codec::imap_types::response::{Code, CodeOther, Data}; use imap_codec::imap_types::status::{StatusDataItem, StatusDataItemName}; +use crate::imap::capability::ServerCapability; use crate::imap::command::{anystate, MailboxName}; use crate::imap::flow; use crate::imap::mailbox_view::MailboxView; use crate::imap::response::Response; -use crate::imap::capability::ServerCapability; use crate::mail::mailbox::Mailbox; use crate::mail::uidindex::*; @@ -33,9 +33,9 @@ pub async fn dispatch<'a>( match &ctx.req.body { // Any state CommandBody::Noop => anystate::noop_nothing(ctx.req.tag.clone()), - CommandBody::Capability => anystate::capability( - ctx.req.tag.clone(), - ctx.server_capabilities), + CommandBody::Capability => { + anystate::capability(ctx.req.tag.clone(), ctx.server_capabilities) + } CommandBody::Logout => anystate::logout(), // Specific to this state (11 commands) diff --git a/src/imap/command/examined.rs b/src/imap/command/examined.rs index 7cccf7b..bddd0f9 100644 --- a/src/imap/command/examined.rs +++ b/src/imap/command/examined.rs @@ -7,11 +7,11 @@ use imap_codec::imap_types::fetch::MacroOrMessageDataItemNames; use imap_codec::imap_types::search::SearchKey; use imap_codec::imap_types::sequence::SequenceSet; +use crate::imap::capability::ServerCapability; use crate::imap::command::{anystate, authenticated}; use crate::imap::flow; use crate::imap::mailbox_view::MailboxView; use crate::imap::response::Response; -use crate::imap::capability::ServerCapability; use crate::mail::user::User; pub struct ExaminedContext<'a> { @@ -25,10 +25,9 @@ pub async fn dispatch(ctx: ExaminedContext<'_>) -> Result<(Response<'static>, fl match &ctx.req.body { // Any State // noop is specific to this state - CommandBody::Capability => anystate::capability( - ctx.req.tag.clone(), - ctx.server_capabilities, - ), + CommandBody::Capability => { + anystate::capability(ctx.req.tag.clone(), ctx.server_capabilities) + } CommandBody::Logout => anystate::logout(), // Specific to the EXAMINE state (specialization of the SELECTED state) diff --git a/src/imap/command/selected.rs b/src/imap/command/selected.rs index 681b509..28ebbe8 100644 --- a/src/imap/command/selected.rs +++ b/src/imap/command/selected.rs @@ -10,11 +10,11 @@ use imap_codec::imap_types::response::{Code, CodeOther}; use imap_codec::imap_types::search::SearchKey; use imap_codec::imap_types::sequence::SequenceSet; +use crate::imap::capability::ServerCapability; use crate::imap::command::{anystate, authenticated, MailboxName}; use crate::imap::flow; use crate::imap::mailbox_view::MailboxView; use crate::imap::response::Response; -use crate::imap::capability::ServerCapability; use crate::mail::user::User; @@ -31,10 +31,9 @@ pub async fn dispatch<'a>( match &ctx.req.body { // Any State // noop is specific to this state - CommandBody::Capability => anystate::capability( - ctx.req.tag.clone(), - ctx.server_capabilities, - ), + CommandBody::Capability => { + anystate::capability(ctx.req.tag.clone(), ctx.server_capabilities) + } CommandBody::Logout => anystate::logout(), // Specific to this state (7 commands + NOOP) @@ -63,6 +62,11 @@ pub async fn dispatch<'a>( mailbox, uid, } => ctx.copy(sequence_set, mailbox, uid).await, + CommandBody::Move { + sequence_set, + mailbox, + uid, + } => ctx.r#move(sequence_set, mailbox, uid).await, // UNSELECT extension (rfc3691) CommandBody::Unselect => ctx.unselect().await, @@ -245,4 +249,58 @@ impl<'a> SelectedContext<'a> { flow::Transition::None, )) } + + async fn r#move( + self, + sequence_set: &SequenceSet, + mailbox: &MailboxCodec<'a>, + uid: &bool, + ) -> Result<(Response<'static>, flow::Transition)> { + let name: &str = MailboxName(mailbox).try_into()?; + + let mb_opt = self.user.open_mailbox(&name).await?; + let mb = match mb_opt { + Some(mb) => mb, + None => { + return Ok(( + Response::build() + .to_req(self.req) + .message("Destination mailbox does not exist") + .code(Code::TryCreate) + .no()?, + flow::Transition::None, + )) + } + }; + + let (uidval, uid_map, data) = self.mailbox.r#move(sequence_set, mb, uid).await?; + + // compute code + let copyuid_str = format!( + "{} {} {}", + uidval, + uid_map + .iter() + .map(|(sid, _)| format!("{}", sid)) + .collect::>() + .join(","), + uid_map + .iter() + .map(|(_, tuid)| format!("{}", tuid)) + .collect::>() + .join(",") + ); + + Ok(( + Response::build() + .to_req(self.req) + .message("COPY completed") + .code(Code::Other(CodeOther::unvalidated( + format!("COPYUID {}", copyuid_str).into_bytes(), + ))) + .set_body(data) + .ok()?, + flow::Transition::None, + )) + } } -- cgit v1.2.3 From 74686ebb778b740ccfccfbf61ccd24628f60e9d0 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 3 Jan 2024 16:52:31 +0100 Subject: append ignore dates instead of failing --- src/imap/command/authenticated.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/imap/command') diff --git a/src/imap/command/authenticated.rs b/src/imap/command/authenticated.rs index 2970b63..fbf29f9 100644 --- a/src/imap/command/authenticated.rs +++ b/src/imap/command/authenticated.rs @@ -305,6 +305,9 @@ impl<'a> AuthenticatedContext<'a> { StatusDataItemName::DeletedStorage => { bail!("quota not implemented, can't return freed storage after EXPUNGE will be run"); }, + StatusDataItemName::HighestModSeq => { + bail!("highestmodseq not yet implemented"); + } }); } @@ -524,7 +527,7 @@ impl<'a> AuthenticatedContext<'a> { }; if date.is_some() { - bail!("Cannot set date when appending message"); + tracing::warn!("Cannot set date when appending message"); } let msg = -- cgit v1.2.3 From a6a0e1994db2b43f559e5c2e8ae5c58342e5136f Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 3 Jan 2024 20:53:07 +0100 Subject: ENABLE is now supported --- src/imap/command/authenticated.rs | 25 +++++++++++++++++++++++-- src/imap/command/examined.rs | 4 +++- src/imap/command/selected.rs | 4 +++- 3 files changed, 29 insertions(+), 4 deletions(-) (limited to 'src/imap/command') diff --git a/src/imap/command/authenticated.rs b/src/imap/command/authenticated.rs index fbf29f9..ee7c8f3 100644 --- a/src/imap/command/authenticated.rs +++ b/src/imap/command/authenticated.rs @@ -3,14 +3,15 @@ use std::sync::Arc; use anyhow::{anyhow, bail, Result}; use imap_codec::imap_types::command::{Command, CommandBody}; -use imap_codec::imap_types::core::{Atom, Literal, QuotedChar}; +use imap_codec::imap_types::core::{Atom, Literal, QuotedChar, NonEmptyVec}; use imap_codec::imap_types::datetime::DateTime; use imap_codec::imap_types::flag::{Flag, FlagNameAttribute}; use imap_codec::imap_types::mailbox::{ListMailbox, Mailbox as MailboxCodec}; use imap_codec::imap_types::response::{Code, CodeOther, Data}; use imap_codec::imap_types::status::{StatusDataItem, StatusDataItemName}; +use imap_codec::imap_types::extensions::enable::CapabilityEnable; -use crate::imap::capability::ServerCapability; +use crate::imap::capability::{ClientCapability, ServerCapability}; use crate::imap::command::{anystate, MailboxName}; use crate::imap::flow; use crate::imap::mailbox_view::MailboxView; @@ -24,6 +25,7 @@ use crate::mail::IMF; pub struct AuthenticatedContext<'a> { pub req: &'a Command<'static>, pub server_capabilities: &'a ServerCapability, + pub client_capabilities: &'a mut ClientCapability, pub user: &'a Arc, } @@ -65,6 +67,11 @@ pub async fn dispatch<'a>( message, } => ctx.append(mailbox, flags, date, message).await, + // rfc5161 ENABLE + CommandBody::Enable { capabilities } => { + ctx.enable(capabilities) + }, + // Collect other commands _ => anystate::wrong_state(ctx.req.tag.clone()), } @@ -511,6 +518,20 @@ impl<'a> AuthenticatedContext<'a> { } } + fn enable(self, cap_enable: &NonEmptyVec>) -> Result<(Response<'static>, flow::Transition)> { + let mut response_builder = Response::build().to_req(self.req); + let capabilities = self.client_capabilities.try_enable(cap_enable.as_ref()); + if capabilities.len() > 0 { + response_builder = response_builder.data(Data::Enabled { capabilities }); + } + Ok(( + response_builder + .message("ENABLE completed") + .ok()?, + flow::Transition::None, + )) + } + pub(crate) async fn append_internal( self, mailbox: &MailboxCodec<'a>, diff --git a/src/imap/command/examined.rs b/src/imap/command/examined.rs index bddd0f9..0d688c0 100644 --- a/src/imap/command/examined.rs +++ b/src/imap/command/examined.rs @@ -7,7 +7,7 @@ use imap_codec::imap_types::fetch::MacroOrMessageDataItemNames; use imap_codec::imap_types::search::SearchKey; use imap_codec::imap_types::sequence::SequenceSet; -use crate::imap::capability::ServerCapability; +use crate::imap::capability::{ClientCapability, ServerCapability}; use crate::imap::command::{anystate, authenticated}; use crate::imap::flow; use crate::imap::mailbox_view::MailboxView; @@ -19,6 +19,7 @@ pub struct ExaminedContext<'a> { pub user: &'a Arc, pub mailbox: &'a mut MailboxView, pub server_capabilities: &'a ServerCapability, + pub client_capabilities: &'a mut ClientCapability, } pub async fn dispatch(ctx: ExaminedContext<'_>) -> Result<(Response<'static>, flow::Transition)> { @@ -60,6 +61,7 @@ pub async fn dispatch(ctx: ExaminedContext<'_>) -> Result<(Response<'static>, fl authenticated::dispatch(authenticated::AuthenticatedContext { req: ctx.req, server_capabilities: ctx.server_capabilities, + client_capabilities: ctx.client_capabilities, user: ctx.user, }) .await diff --git a/src/imap/command/selected.rs b/src/imap/command/selected.rs index 28ebbe8..c8cc680 100644 --- a/src/imap/command/selected.rs +++ b/src/imap/command/selected.rs @@ -10,7 +10,7 @@ use imap_codec::imap_types::response::{Code, CodeOther}; use imap_codec::imap_types::search::SearchKey; use imap_codec::imap_types::sequence::SequenceSet; -use crate::imap::capability::ServerCapability; +use crate::imap::capability::{ClientCapability, ServerCapability}; use crate::imap::command::{anystate, authenticated, MailboxName}; use crate::imap::flow; use crate::imap::mailbox_view::MailboxView; @@ -23,6 +23,7 @@ pub struct SelectedContext<'a> { pub user: &'a Arc, pub mailbox: &'a mut MailboxView, pub server_capabilities: &'a ServerCapability, + pub client_capabilities: &'a mut ClientCapability, } pub async fn dispatch<'a>( @@ -76,6 +77,7 @@ pub async fn dispatch<'a>( authenticated::dispatch(authenticated::AuthenticatedContext { req: ctx.req, server_capabilities: ctx.server_capabilities, + client_capabilities: ctx.client_capabilities, user: ctx.user, }) .await -- cgit v1.2.3 From 8180baae0084faf76d49e6e03f8405487723c46f Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 3 Jan 2024 20:53:25 +0100 Subject: format code --- src/imap/command/authenticated.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/imap/command') diff --git a/src/imap/command/authenticated.rs b/src/imap/command/authenticated.rs index ee7c8f3..1481a80 100644 --- a/src/imap/command/authenticated.rs +++ b/src/imap/command/authenticated.rs @@ -3,13 +3,13 @@ use std::sync::Arc; use anyhow::{anyhow, bail, Result}; use imap_codec::imap_types::command::{Command, CommandBody}; -use imap_codec::imap_types::core::{Atom, Literal, QuotedChar, NonEmptyVec}; +use imap_codec::imap_types::core::{Atom, Literal, NonEmptyVec, QuotedChar}; use imap_codec::imap_types::datetime::DateTime; +use imap_codec::imap_types::extensions::enable::CapabilityEnable; use imap_codec::imap_types::flag::{Flag, FlagNameAttribute}; use imap_codec::imap_types::mailbox::{ListMailbox, Mailbox as MailboxCodec}; use imap_codec::imap_types::response::{Code, CodeOther, Data}; use imap_codec::imap_types::status::{StatusDataItem, StatusDataItemName}; -use imap_codec::imap_types::extensions::enable::CapabilityEnable; use crate::imap::capability::{ClientCapability, ServerCapability}; use crate::imap::command::{anystate, MailboxName}; @@ -68,9 +68,7 @@ pub async fn dispatch<'a>( } => ctx.append(mailbox, flags, date, message).await, // rfc5161 ENABLE - CommandBody::Enable { capabilities } => { - ctx.enable(capabilities) - }, + CommandBody::Enable { capabilities } => ctx.enable(capabilities), // Collect other commands _ => anystate::wrong_state(ctx.req.tag.clone()), @@ -518,16 +516,17 @@ impl<'a> AuthenticatedContext<'a> { } } - fn enable(self, cap_enable: &NonEmptyVec>) -> Result<(Response<'static>, flow::Transition)> { + fn enable( + self, + cap_enable: &NonEmptyVec>, + ) -> Result<(Response<'static>, flow::Transition)> { let mut response_builder = Response::build().to_req(self.req); let capabilities = self.client_capabilities.try_enable(cap_enable.as_ref()); if capabilities.len() > 0 { response_builder = response_builder.data(Data::Enabled { capabilities }); } Ok(( - response_builder - .message("ENABLE completed") - .ok()?, + response_builder.message("ENABLE completed").ok()?, flow::Transition::None, )) } -- cgit v1.2.3