@Override public void renameMailbox(MailboxPath from, MailboxPath to, MailboxSession session) throws MailboxException { LOGGER.debug("renameMailbox {} to {}", from, to); if (mailboxExists(to, session)) { throw new MailboxExistsException(to.toString()); } if (isMailboxNameTooLong(to)) { throw new TooLongMailboxNameException("Mailbox name exceed maximum size of " + MAX_MAILBOX_NAME_LENGTH + " characters"); } assertIsOwner(session, from); MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); mapper.execute(Mapper.toTransaction(() -> doRenameMailbox(from, to, session, mapper))); }
MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession); try { mapper.execute(Mapper.toTransaction(() -> mailboxIds.add(mapper.save(m))));
@Override public void deleteMailbox(final MailboxPath mailboxPath, final MailboxSession session) throws MailboxException { LOGGER.info("deleteMailbox {}", mailboxPath); assertIsOwner(session, mailboxPath); MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(session); MessageMapper messageMapper = mailboxSessionMapperFactory.getMessageMapper(session); mailboxMapper.execute((Mapper.Transaction<Mailbox>) () -> { Mailbox mailbox = mailboxMapper.findMailboxByPath(mailboxPath); if (mailbox == null) { throw new MailboxNotFoundException(mailboxPath); } QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(mailboxPath); long messageCount = messageMapper.countMessagesInMailbox(mailbox); long totalSize = Iterators.toStream(messageMapper.findInMailbox(mailbox, MessageRange.all(), MessageMapper.FetchType.Metadata, -1)) .mapToLong(Message::getFullContentOctets) .sum(); // We need to create a copy of the mailbox as maybe we can not refer to the real // mailbox once we remove it SimpleMailbox m = new SimpleMailbox(mailbox); mailboxMapper.delete(mailbox); dispatcher.mailboxDeleted(session, mailbox, quotaRoot, QuotaCount.count(messageCount), QuotaSize.size(totalSize)); return m; }); }