* imap.store.mail.model.Mailbox)
*/
public void save(Mailbox<String> mailbox) throws MailboxException {
try {
final JCRMailbox jcrMailbox = (JCRMailbox)mailbox;
Node node = null;
if (jcrMailbox.isPersistent()) {
node = getSession().getNodeByIdentifier(jcrMailbox.getMailboxId());
}
if (node == null) {
Node rootNode = getSession().getRootNode();
Node mailboxNode;
if (rootNode.hasNode(MAILBOXES_PATH) == false) {
mailboxNode = rootNode.addNode(MAILBOXES_PATH);
mailboxNode.addMixin(JcrConstants.MIX_LOCKABLE);
getSession().save();
} else {
mailboxNode = rootNode.getNode(MAILBOXES_PATH);
}
node = JcrUtils.getOrAddNode(mailboxNode, Text.escapeIllegalJcrChars(jcrMailbox.getNamespace()), "nt:unstructured");
if (jcrMailbox.getUser() != null) {
node = createUserPathStructure(node, Text.escapeIllegalJcrChars(jcrMailbox.getUser()));
}
node = JcrUtils.getOrAddNode(node, Text.escapeIllegalJcrChars(jcrMailbox.getName()), "nt:unstructured");
node.addMixin("jamesMailbox:mailbox");
jcrMailbox.merge(node);
} else {
jcrMailbox.merge(node);
}
} catch (RepositoryException e) {
throw new MailboxException("Unable to save mailbox " + mailbox, e);
}