// renaming the INBOX means to move its contents to the new folder
if (originalMailbox.getName().equals(MailboxConstants.INBOX)) {
File inboxFolder = originalFolder.getRootFile();
File newFolder = folder.getRootFile();
if (!newFolder.mkdirs())
throw new MailboxException("Failed to saveMailbox " + mailbox);
originalFolder.getCurFolder().renameTo(folder.getCurFolder());
originalFolder.getNewFolder().renameTo(folder.getNewFolder());
originalFolder.getTmpFolder().renameTo(folder.getTmpFolder());
(new File(inboxFolder, MaildirFolder.UIDLIST_FILE)).renameTo(
(new File(newFolder, MaildirFolder.UIDLIST_FILE)));
(new File(inboxFolder, MaildirFolder.VALIDITY_FILE)).renameTo(
(new File(newFolder, MaildirFolder.VALIDITY_FILE)));
// recreate the INBOX folders, uidvalidity and uidlist will
// automatically be recreated later
originalFolder.getCurFolder().mkdir();
originalFolder.getNewFolder().mkdir();
originalFolder.getTmpFolder().mkdir();
}
else {
if (!originalFolder.getRootFile().renameTo(folder.getRootFile()))
throw new MailboxException("Failed to save Mailbox " + mailbox,
new IOException("Could not rename folder " + originalFolder));
}
}
} catch (MailboxNotFoundException e) {
// it cannot be found and is thus new
MaildirFolder folder = maildirStore.createMaildirFolder(mailbox);
if (!folder.exists()) {
boolean success = folder.getRootFile().exists();
if (!success) success = folder.getRootFile().mkdirs();
if (!success)
throw new MailboxException("Failed to save Mailbox " + mailbox);
success = folder.getCurFolder().mkdir();
success = success && folder.getNewFolder().mkdir();
success = success && folder.getTmpFolder().mkdir();
if (!success)
throw new MailboxException("Failed to save Mailbox " + mailbox, new IOException("Needed folder structure can not be created"));
}
try {
folder.setUidValidity(mailbox.getUidValidity());
} catch (IOException ioe) {
throw new MailboxException("Failed to save Mailbox " + mailbox, ioe);
}
}
}