@Override
protected void doProcess(RenameRequest request, ImapSession session, String tag, ImapCommand command, Responder responder) {
PathConverter pathConverter = PathConverter.forSession(session);
MailboxPath existingPath = pathConverter.buildFullPath(request.getExistingName());
MailboxPath newPath = pathConverter.buildFullPath(request.getNewName());
try {
final MailboxManager mailboxManager = getMailboxManager();
MailboxSession mailboxsession = ImapSessionUtils.getMailboxSession(session);
mailboxManager.renameMailbox(existingPath, newPath, mailboxsession);
if (existingPath.getName().equalsIgnoreCase(ImapConstants.INBOX_NAME) && !mailboxManager.mailboxExists(existingPath, mailboxsession)) {
mailboxManager.createMailbox(existingPath, mailboxsession);
}
okComplete(command, tag, responder);
unsolicitedResponses(session, responder, false);
} catch (MailboxExistsException e) {
LOGGER.debug("Rename from {} to {} failed because the target mailbox exists", existingPath, newPath, e);
no(command, tag, responder, HumanReadableText.FAILURE_MAILBOX_EXISTS);
} catch (MailboxNotFoundException e) {
LOGGER.debug("Rename from {} to {} failed because the source mailbox doesn't exist", existingPath, newPath, e);
no(command, tag, responder, HumanReadableText.MAILBOX_NOT_FOUND);
} catch (TooLongMailboxNameException e) {
LOGGER.debug("The mailbox name length is over limit: {}", newPath.getName(), e);
taggedBad(command, tag, responder, HumanReadableText.FAILURE_MAILBOX_NAME);
} catch (MailboxException e) {
LOGGER.error("Rename from {} to {} failed", existingPath, newPath, e);
no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
}
}