private MessageManager.MetaData selectMailbox(MailboxPath mailboxPath, ImapSession session) throws MailboxException {
final MailboxManager mailboxManager = getMailboxManager();
final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
final MessageManager mailbox = mailboxManager.getMailbox(mailboxPath, mailboxSession);
final SelectedMailbox sessionMailbox;
final SelectedMailbox currentMailbox = session.getSelected();
if (currentMailbox == null || !currentMailbox.getPath().equals(mailboxPath)) {
sessionMailbox = createNewSelectedMailbox(mailbox, mailboxSession, session, mailboxPath);
} else {
sessionMailbox = currentMailbox;
}
final MessageManager.MetaData metaData = mailbox.getMetaData(!openReadOnly, mailboxSession, MessageManager.MetaData.FetchGroup.FIRST_UNSEEN);