This is an automated email from the ASF dual-hosted git repository. chibenwa pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit c014c50dd6a84d386ff6c49dd1d99fa5e021ef70 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]
