diff --git a/crates/imap/src/core/mailbox.rs b/crates/imap/src/core/mailbox.rs index 0b18166e..25f41839 100644 --- a/crates/imap/src/core/mailbox.rs +++ b/crates/imap/src/core/mailbox.rs @@ -226,9 +226,13 @@ impl SessionData { ..Default::default() }, ); - account - .mailbox_names - .insert(mailbox_path.join("/"), *mailbox_id); + + let mut mailbox_name = mailbox_path.join("/"); + if mailbox_name.eq_ignore_ascii_case("inbox") && *mailbox_id != INBOX_ID { + // If there is another mailbox called Inbox, renamed it to avoid conflicts + mailbox_name = format!("{mailbox_name} 2"); + } + account.mailbox_names.insert(mailbox_name, *mailbox_id); if has_children && iter_stack.len() < 100 { iter_stack.push((iter, parent_id, path)); @@ -508,7 +512,9 @@ impl SessionData { .map_or(true, |p| mailbox_name.starts_with(p)) { for (mailbox_name_, mailbox_id_) in account.mailbox_names.iter() { - if mailbox_name_ == mailbox_name || (is_inbox && *mailbox_id_ == INBOX_ID) { + if (!is_inbox && mailbox_name_ == mailbox_name) + || (is_inbox && *mailbox_id_ == INBOX_ID) + { return MailboxId { account_id: account.account_id, mailbox_id: *mailbox_id_, diff --git a/crates/imap/src/op/fetch.rs b/crates/imap/src/op/fetch.rs index c0fac6a6..39f51489 100644 --- a/crates/imap/src/op/fetch.rs +++ b/crates/imap/src/op/fetch.rs @@ -37,7 +37,7 @@ use imap_proto::{ receiver::Request, Command, ResponseCode, StatusResponse, }; -use jmap::{email::metadata::MessageMetadata, Bincode}; +use jmap::email::metadata::MessageMetadata; use jmap_proto::{ error::method::MethodError, types::{ @@ -48,7 +48,7 @@ use jmap_proto::{ use mail_parser::{Address, GetHeader, HeaderName, Message, PartType}; use store::{ query::log::{Change, Query}, - write::{assert::HashedValue, BatchBuilder, F_BITMAP, F_VALUE}, + write::{assert::HashedValue, BatchBuilder, Bincode, F_BITMAP, F_VALUE}, }; use utils::listener::SessionStream; diff --git a/crates/imap/src/op/noop.rs b/crates/imap/src/op/noop.rs index 0a6386dd..3a989201 100644 --- a/crates/imap/src/op/noop.rs +++ b/crates/imap/src/op/noop.rs @@ -29,22 +29,15 @@ use crate::core::{Session, State}; impl Session { pub async fn handle_noop(&mut self, request: Request) -> crate::OpResult { - match &self.state { - State::Authenticated { data, .. } => { - data.write_changes(&None, true, false, self.is_qresync, self.version.is_rev2()) - .await; - } - State::Selected { data, mailbox, .. } => { - data.write_changes( - &Some(mailbox.clone()), - true, - true, - self.is_qresync, - self.version.is_rev2(), - ) - .await; - } - _ => (), + if let State::Selected { data, mailbox, .. } = &self.state { + data.write_changes( + &Some(mailbox.clone()), + false, + true, + self.is_qresync, + self.version.is_rev2(), + ) + .await; } self.write_bytes(