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 7340c854147270e0a33d1db8b90d469f2c038304
Author: Benoit TELLIER <[email protected]>
AuthorDate: Tue Jun 16 16:17:05 2026 +0200

    [FIX] User rename: Simplify rename dance when destination exist
---
 .../mailbox/MailboxUsernameChangeTaskStep.java     | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git 
a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxUsernameChangeTaskStep.java
 
b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxUsernameChangeTaskStep.java
index 45523ec599..74441266f7 100644
--- 
a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxUsernameChangeTaskStep.java
+++ 
b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxUsernameChangeTaskStep.java
@@ -84,8 +84,7 @@ public class MailboxUsernameChangeTaskStep implements 
UsernameChangeTaskStep {
                 if (!exist) {
                     return 
renameMailboxAndRenameSubscriptionForDelegatee(fromSession, toSession, mailbox, 
renamedPath);
                 } else {
-                    return renameWhenMailboxExist(toSession, renamedPath,
-                        
renameMailboxAndRenameSubscriptionForDelegatee(fromSession, toSession, mailbox, 
renamedPath));
+                    return moveWhenMailboxExist(fromSession, toSession, 
mailbox, renamedPath);
                 }
             });
     }
@@ -98,18 +97,15 @@ public class MailboxUsernameChangeTaskStep implements 
UsernameChangeTaskStep {
             .then();
     }
 
-    // rename: renamedPath -> temporaryPath
-    // rename: mailbox.getPath -> renamedPath
-    // copy messages: temporaryPath -> renamedPath
-    // delete: temporaryPath
-    private Mono<Void> renameWhenMailboxExist(MailboxSession toSession, 
MailboxPath renamedPath, Mono<Void> renamePublisher) {
+    // The destination mailbox already exists: bring the source mailbox into 
the destination
+    // account under a temporary name, MOVE its messages into the destination, 
then drop the
+    // emptied temporary mailbox.
+    private Mono<Void> moveWhenMailboxExist(MailboxSession fromSession, 
MailboxSession toSession, MailboxMetaData mailbox, MailboxPath renamedPath) {
         MailboxPath temporaryPath = new 
MailboxPath(renamedPath.getNamespace(), renamedPath.getUser(), 
renamedPath.getName() + "tmp");
-        return mailboxManager.renameMailboxReactive(renamedPath, temporaryPath,
-                MailboxManager.RenameOption.NONE, toSession)
-            .then(renamePublisher)
-            .then(mailboxManager.copyMessagesReactive(MessageRange.all(),
-                    temporaryPath, renamedPath, toSession)
-                .then())
+        return mailboxManager.renameMailboxReactive(mailbox.getPath(), 
temporaryPath,
+                MailboxManager.RenameOption.NONE, fromSession, toSession)
+            .thenMany(mailboxManager.moveMessagesReactive(MessageRange.all(), 
temporaryPath, renamedPath, toSession))
+            .then(renameSubscriptionsForDelegatee(mailbox, renamedPath))
             .then(mailboxManager.deleteMailboxReactive(temporaryPath, 
toSession));
     }
 


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

Reply via email to