This is an automated email from the ASF dual-hosted git repository.

Arsnael pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new 98adde33d4 [FIX] StoreMailboxManager:renameSubMailboxes should change 
namespace
98adde33d4 is described below

commit 98adde33d4d3c461b468c48875a5c9d039d54909
Author: Quan Tran <[email protected]>
AuthorDate: Mon Jun 22 10:41:22 2026 +0700

    [FIX] StoreMailboxManager:renameSubMailboxes should change namespace
    
    When renaming a mailbox across namespaces, StoreMailboxManager preloads the
    mailbox and its children then renames them through renameSubMailboxes.
    
    That helper updated the mailbox name and user but not the namespace, causing
    id-based renames across namespaces to keep the old namespace in storage.
    
    Update the namespace during rename and add a regression test covering both 
the
    renamed mailbox and one child mailbox.
---
 .../apache/james/mailbox/MailboxManagerTest.java    | 21 +++++++++++++++++++++
 .../james/mailbox/store/StoreMailboxManager.java    |  1 +
 2 files changed, 22 insertions(+)

diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java 
b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
index ad44a3b4ae..c3253f44ef 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
@@ -2121,6 +2121,27 @@ public abstract class MailboxManagerTest<T extends 
MailboxManager> {
                 .isEqualTo(mailboxPath2);
         }
 
+        @Test
+        protected void renameMailboxByIdShouldChangeTheMailboxNamespace() 
throws Exception {
+            MailboxSession session = 
mailboxManager.createSystemSession(USER_1);
+
+            MailboxPath oldMailboxPath = new MailboxPath("#source", USER_1, 
"mbx1");
+            MailboxPath oldMailboxPathChild = new MailboxPath("#source", 
USER_1, "mbx1.child");
+            MailboxPath newMailboxPath = new MailboxPath("#destination", 
USER_1, "mbx2");
+            Optional<MailboxId> mailboxId = 
mailboxManager.createMailbox(oldMailboxPath, session);
+            Optional<MailboxId> childMailboxId = 
mailboxManager.createMailbox(oldMailboxPathChild, session);
+
+            mailboxManager.renameMailbox(mailboxId.get(), newMailboxPath, 
session);
+
+            MailboxPath renamedMailboxPath = 
mailboxManager.getMailbox(mailboxId.get(), session).getMailboxPath();
+            MailboxPath renamedChildMailboxPath = 
mailboxManager.getMailbox(childMailboxId.get(), session).getMailboxPath();
+
+            SoftAssertions.assertSoftly(softly -> {
+                
softly.assertThat(renamedMailboxPath).isEqualTo(newMailboxPath);
+                softly.assertThat(renamedChildMailboxPath).isEqualTo(new 
MailboxPath("#destination", USER_1, "mbx2.child"));
+            });
+        }
+
         @Test
         void renameMailboxShouldThrowWhenMailboxPathsDoNotBelongToUser() 
throws Exception {
             MailboxSession sessionUser1 = 
mailboxManager.createSystemSession(USER_1);
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index 64a66db2de..0f32e3be59 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -754,6 +754,7 @@ public class StoreMailboxManager implements MailboxManager {
                 String subOriginalName = sub.getName();
                 String subNewName = newMailboxPath.getName() + 
subOriginalName.substring(from.getName().length());
                 MailboxPath fromPath = new MailboxPath(from, subOriginalName);
+                sub.setNamespace(newMailboxPath.getNamespace());
                 sub.setName(subNewName);
                 sub.setUser(newMailboxPath.getUser());
                 return mapper.rename(sub, fromPath)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to