@Override public List<MailboxPath> retrieveAssociatedMailboxes(QuotaRoot quotaRoot, MailboxSession mailboxSession) throws MailboxException { List<String> parts = toParts(quotaRoot.getValue()); String namespace = parts.get(0); String user = parts.get(1); return Lists.transform(factory.getMailboxMapper(mailboxSession) .findMailboxWithPathLike(new MailboxPath(namespace, user, "%")), Mailbox::generateAssociatedPath); }
private List<MailboxMetaData> searchMailboxes(MailboxQuery mailboxExpression, MailboxSession session, Right right) throws MailboxException { MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(session); Stream<Mailbox> baseMailboxes = mailboxMapper .findMailboxWithPathLike(getPathLike(mailboxExpression, session)) .stream(); Stream<Mailbox> delegatedMailboxes = getDelegatedMailboxes(mailboxMapper, mailboxExpression, right, session); List<Mailbox> mailboxes = Stream.concat(baseMailboxes, delegatedMailboxes) .distinct() .filter(Throwing.predicate(mailbox -> storeRightManager.hasRight(mailbox, right, session))) .collect(Guavate.toImmutableList()); return mailboxes .stream() .filter(mailbox -> mailboxExpression.isPathMatch(mailbox.generateAssociatedPath())) .map(mailbox -> toMailboxMetadata(session, mailboxes, mailbox)) .sorted(new StandardMailboxMetaDataComparator()) .collect(Guavate.toImmutableList()); }
private void doRenameMailbox(MailboxPath from, MailboxPath to, MailboxSession session, MailboxMapper mapper) throws MailboxException { // TODO put this into a serilizable transaction Mailbox mailbox = Optional.ofNullable(mapper.findMailboxByPath(from)) .orElseThrow(() -> new MailboxNotFoundException(from)); mailbox.setNamespace(to.getNamespace()); mailbox.setUser(to.getUser()); mailbox.setName(to.getName()); mapper.save(mailbox); dispatcher.mailboxRenamed(session, from, mailbox); // rename submailboxes MailboxPath children = new MailboxPath(from.getNamespace(), from.getUser(), from.getName() + getDelimiter() + "%"); locker.executeWithLock(session, children, (LockAwareExecution<Void>) () -> { List<Mailbox> subMailboxes = mapper.findMailboxWithPathLike(children); for (Mailbox sub : subMailboxes) { String subOriginalName = sub.getName(); String subNewName = to.getName() + subOriginalName.substring(from.getName().length()); MailboxPath fromPath = new MailboxPath(children, subOriginalName); sub.setName(subNewName); mapper.save(sub); dispatcher.mailboxRenamed(session, fromPath, sub); LOGGER.debug("Rename mailbox sub-mailbox {} to {}", subOriginalName, subNewName); } return null; }, true); }