@Override public boolean mailboxExists(MailboxPath mailboxPath, MailboxSession session) throws MailboxException { try { final MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); mapper.findMailboxByPath(mailboxPath); return true; } catch (MailboxNotFoundException e) { return false; } }
private List<Mailbox> retrieveMailboxes(QuotaRoot quotaRoot, MailboxSession session) throws MailboxException { List<MailboxPath> paths = quotaRootResolver.retrieveAssociatedMailboxes(quotaRoot, session); final MailboxMapper mapper = factory.getMailboxMapper(session); return Lists.transform(paths, mailboxPath -> { try { return mapper.findMailboxByPath(mailboxPath); } catch (MailboxException e) { throw new RuntimeException(e); } }); }
@Override public Rfc4314Rights myRights(MailboxId mailboxId, MailboxSession session) throws MailboxException { MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); Mailbox mailbox = mapper.findMailboxById(mailboxId); return myRights(mailbox, session); }
@Override public MailboxACL listRights(MailboxPath mailboxPath, MailboxSession session) throws MailboxException { MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); Mailbox mailbox = mapper.findMailboxByPath(mailboxPath); return mailbox.getACL(); }
@Override public Rfc4314Rights myRights(MailboxPath mailboxPath, MailboxSession session) throws MailboxException { MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); Mailbox mailbox = mapper.findMailboxByPath(mailboxPath); return myRights(mailbox, session); }
@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 void validateQuota(MessageMoves messageMoves, MailboxSession mailboxSession, MailboxMessage mailboxMessage) throws MailboxException { MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession); Map<QuotaRoot, Integer> messageCountByQuotaRoot = buildMapQuotaRoot(messageMoves, mailboxMapper); for (Map.Entry<QuotaRoot, Integer> entry : messageCountByQuotaRoot.entrySet()) { Integer additionalCopyCount = entry.getValue(); if (additionalCopyCount > 0) { long additionalOccupiedSpace = additionalCopyCount * mailboxMessage.getFullContentOctets(); new QuotaChecker(quotaManager.getMessageQuota(entry.getKey()), quotaManager.getStorageQuota(entry.getKey()), entry.getKey()) .tryAddition(additionalCopyCount, additionalOccupiedSpace); } } }
@Override public Rfc4314Rights[] listRights(MailboxPath mailboxPath, EntryKey key, MailboxSession session) throws MailboxException { MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); Mailbox mailbox = mapper.findMailboxByPath(mailboxPath); return aclResolver.listRights(key, groupMembershipResolver, mailbox.getUser(), !GROUP_FOLDER); }
public Result reIndex(MailboxMessage mailboxMessage, MailboxSession session) { try { MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(session); Mailbox mailbox = mailboxMapper.findMailboxById(mailboxMessage.getMailboxId()); index.add(session, mailbox, mailboxMessage); return Result.COMPLETED; } catch (Exception e) { LOGGER.warn("Failed to re-index {} in {}", messageId, mailboxMessage.getMailboxId(), e); return Result.PARTIAL; } }
@Override public void setRights(MailboxId mailboxId, MailboxACL mailboxACL, MailboxSession session) throws MailboxException { MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); Mailbox mailbox = mapper.findMailboxById(mailboxId); setRights(mailbox.generateAssociatedPath(), mailboxACL, session); }
@Override public boolean hasChildren(MailboxPath mailboxPath, MailboxSession session) throws MailboxException { MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); Mailbox mailbox = mapper.findMailboxByPath(mailboxPath); return mapper.hasChildren(mailbox, session.getPathDelimiter()); } }
public MailboxId checkThenGetMailboxId(MailboxPath path, MailboxSession session) throws MailboxException { MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(session); Mailbox mailbox = mailboxMapper.findMailboxByPath(path); if (!rightManager.hasRight(mailbox, Right.Read, session)) { throw new InsufficientRightsException("Not enough rights on " + path); } return mailbox.getMailboxId(); }
private void dispatchFlagsChange(MailboxSession mailboxSession, MailboxId mailboxId, UpdatedFlags updatedFlags) throws MailboxException { if (updatedFlags.flagsChanged()) { Mailbox mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId); dispatcher.flagsUpdated(mailboxSession, updatedFlags.getUid(), mailbox, updatedFlags); } }
Task.Result handleMessageReIndexing(MailboxPath path, MessageUid uid) throws MailboxException { MailboxSession mailboxSession = mailboxManager.createSystemSession(path.getUser()); Mailbox mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession) .findMailboxByPath(path); return handleMessageReIndexing(mailboxSession, mailbox, uid); }
/** * Delete all mailboxes * * @param mailboxSession * @throws MailboxException */ public void deleteEverything(MailboxSession mailboxSession) throws MailboxException { final JPAMailboxMapper mapper = (JPAMailboxMapper) getMapperFactory().getMailboxMapper(mailboxSession); mapper.execute(Mapper.toTransaction(mapper::deleteAllMemberships)); mapper.execute(Mapper.toTransaction(mapper::deleteAllMailboxes)); }
@Override public void applyRightsCommand(MailboxPath mailboxPath, ACLCommand mailboxACLCommand, MailboxSession session) throws MailboxException { assertSharesBelongsToUserDomain(mailboxPath.getUser(), mailboxACLCommand); MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); Mailbox mailbox = mapper.findMailboxByPath(mailboxPath); ACLDiff aclDiff = mapper.updateACL(mailbox, mailboxACLCommand); dispatcher.aclUpdated(session, mailboxPath, aclDiff); }
@Override public void setRights(MailboxPath mailboxPath, MailboxACL mailboxACL, MailboxSession session) throws MailboxException { assertSharesBelongsToUserDomain(mailboxPath.getUser(), mailboxACL.getEntries()); MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); Mailbox mailbox = mapper.findMailboxByPath(mailboxPath); setRights(mailboxACL, mapper, mailbox, session); }
private void removeMessageFromMailboxes(MailboxMessage message, Set<MailboxId> mailboxesToRemove, MailboxSession mailboxSession) throws MailboxException { MessageIdMapper messageIdMapper = mailboxSessionMapperFactory.getMessageIdMapper(mailboxSession); MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession); SimpleMessageMetaData eventPayload = new SimpleMessageMetaData(message); for (MailboxId mailboxId: mailboxesToRemove) { messageIdMapper.delete(message.getMessageId(), mailboxesToRemove); dispatcher.expunged(mailboxSession, eventPayload, mailboxMapper.findMailboxById(mailboxId)); } }
@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))); }
@Test public void eventShouldNotUpdateNewParentWhenRenameMailboxWhichDoesContainLookupRight() throws Exception { Mailbox childMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(childMailboxId); mailboxMapper.getMailboxMapper(mailboxSession).setACL(childMailbox, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write)))); storeMailboxManager.renameMailbox(CHILD_MAILBOX, MailboxPath.forUser(OWNER_USER, "shared1.sub1New"), mailboxSession); MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId1, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualACL.getEntries()) .doesNotContainKeys(SHARED_USER_KEY); }