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

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

commit 144bf6411a54e5e1633ee789dd4f200cd54bf6cf
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 76e747aba0..e9cb4a9635 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
@@ -2067,6 +2067,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 7404512cf2..e8c64e4c24 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
@@ -727,6 +727,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