@Override public void save(MailboxMessage mailboxMessage) throws MailboxException { Mailbox mailbox = mailboxMapper.findMailboxById(mailboxMessage.getMailboxId()); messageMapper.save(mailbox, mailboxMessage); }
@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 void delete(MessageId messageId, Collection<MailboxId> mailboxIds) { find(ImmutableList.of(messageId), MessageMapper.FetchType.Metadata) .stream() .filter(message -> mailboxIds.contains(message.getMailboxId())) .forEach(Throwing.consumer( message -> messageMapper.delete( mailboxMapper.findMailboxById(message.getMailboxId()), message))); }
private QuotaRoot retrieveQuotaRoot(MailboxMapper mailboxMapper, MailboxId mailboxId) throws MailboxException { Mailbox mailbox = mailboxMapper.findMailboxById(mailboxId); return quotaRootResolver.getQuotaRoot(mailbox.generateAssociatedPath()); }
@Override public void delete(MessageId messageId) { find(ImmutableList.of(messageId), MessageMapper.FetchType.Metadata) .forEach(Throwing.consumer( message -> messageMapper.delete( mailboxMapper.findMailboxById(message.getMailboxId()), message))); }
private void delete(MessageIdMapper messageIdMapper, List<MailboxMessage> messageList, MailboxSession mailboxSession) throws MailboxException { ImmutableList<MetadataWithMailboxId> metadataWithMailbox = messageList.stream() .map(StoreMessageIdManager::toMetadataWithMailboxId) .collect(Guavate.toImmutableList()); messageIdMapper.delete( messageList.stream() .collect(Guavate.toImmutableListMultimap( Message::getMessageId, MailboxMessage::getMailboxId))); MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession); for (MetadataWithMailboxId metadataWithMailboxId : metadataWithMailbox) { dispatcher.expunged(mailboxSession, metadataWithMailboxId.messageMetaData, mailboxMapper.findMailboxById(metadataWithMailboxId.mailboxId)); } }
@Override public void copyInMailbox(MailboxMessage mailboxMessage) throws MailboxException { CassandraId mailboxId = (CassandraId) mailboxMessage.getMailboxId(); mailboxMapper.findMailboxById(mailboxId); ComposedMessageIdWithMetaData composedMessageIdWithMetaData = createMetadataFor(mailboxMessage); CompletableFuture.allOf( imapUidDAO.insert(composedMessageIdWithMetaData), messageIdDAO.insert(composedMessageIdWithMetaData)) .thenCompose(voidValue -> indexTableHandler.updateIndexOnAdd(mailboxMessage, mailboxId)) .join(); }
@Override public void save(MailboxMessage mailboxMessage) throws MailboxException { CassandraId mailboxId = (CassandraId) mailboxMessage.getMailboxId(); mailboxMapper.findMailboxById(mailboxId); ComposedMessageIdWithMetaData composedMessageIdWithMetaData = createMetadataFor(mailboxMessage); messageDAO.save(mailboxMessage) .thenCompose(voidValue -> CompletableFuture.allOf( imapUidDAO.insert(composedMessageIdWithMetaData), messageIdDAO.insert(composedMessageIdWithMetaData))) .thenCompose(voidValue -> indexTableHandler.updateIndexOnAdd(mailboxMessage, mailboxId)) .join(); }
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); }
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); } }
@Override public MessageManager getMailbox(MailboxId mailboxId, MailboxSession session) throws MailboxException { MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); Mailbox mailboxRow = mapper.findMailboxById(mailboxId); if (mailboxRow == null) { LOGGER.info("Mailbox '{}' not found.", mailboxId.serialize()); throw new MailboxNotFoundException(mailboxId); } if (! assertUserHasAccessTo(mailboxRow, session)) { LOGGER.info("Mailbox '{}' does not belong to user '{}' but to '{}'", mailboxId.serialize(), session.getUser(), mailboxRow.getUser()); throw new MailboxNotFoundException(mailboxId); } LOGGER.debug("Loaded mailbox {}", mailboxId.serialize()); return createMessageManager(mailboxRow, 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)); } }
private Function<MailboxMessage, Pair<MailboxId, UpdatedFlags>> updateMessage(Flags newState, FlagsUpdateMode updateMode) { return Throwing.function((MailboxMessage message) -> { FlagsUpdateCalculator flagsUpdateCalculator = new FlagsUpdateCalculator(newState, updateMode); if (flagsUpdateCalculator.buildNewFlags(message.createFlags()).equals(message.createFlags())) { UpdatedFlags updatedFlags = UpdatedFlags.builder() .modSeq(message.getModSeq()) .uid(message.getUid()) .oldFlags(message.createFlags()) .newFlags(newState) .build(); return Pair.of(message.getMailboxId(), updatedFlags); } return Pair.of(message.getMailboxId(), messageMapper.updateFlags( mailboxMapper.findMailboxById(message.getMailboxId()), flagsUpdateCalculator, message.getUid().toRange()) .next()); }); } }
@Test public void eventShouldUpdateNewParentWhenRenameMailboxWhichContainLookupRight() 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, Right.Lookup)))); 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()) .contains(lookupEntry); }
@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); }
@Test public void eventShouldUpdateAllNewParentWhenRenameMailboxWhichContainLookupRight() throws Exception { Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId); mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write, Right.Lookup)))); storeMailboxManager.renameMailbox(GRAND_CHILD_MAILBOX, MailboxPath.forUser(OWNER_USER, "shared1.sub1.sub2"), mailboxSession); MailboxACL parentActualACL = storeMailboxManager.getMailbox(parentMailboxId1, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); MailboxACL childActualACL = storeMailboxManager.getMailbox(childMailboxId1, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(parentActualACL.getEntries()) .contains(lookupEntry); assertThat(childActualACL.getEntries()) .contains(lookupEntry); }
@Test public void eventShouldDoNothingWhenMailboxACLRemoveLookupRight() throws Exception { Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId); mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write, Right.Lookup)))); storeRightManager.applyRightsCommand( GRAND_CHILD_MAILBOX, MailboxACL.command() .key(SHARED_USER_KEY) .rights(Right.Lookup) .asRemoval(), mailboxSession); MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualACL.getEntries()) .doesNotContainKeys(SHARED_USER_KEY); }
@Test public void eventShouldDoNothingWhenNewACLIsTheSameAsTheOldOne() throws Exception { Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId); mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Lookup)))); storeRightManager.applyRightsCommand( GRAND_CHILD_MAILBOX, MailboxACL.command() .key(SHARED_USER_KEY) .rights(Right.Lookup) .asAddition(), mailboxSession); MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualACL.getEntries()) .doesNotContainKeys(SHARED_USER_KEY); }
@Test public void eventShouldUpdateParentWhenMailboxACLUpdateLookupRight() throws Exception { Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId); mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write)))); storeRightManager.setRights( GRAND_CHILD_MAILBOX, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Lookup))), mailboxSession); MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualACL.getEntries()) .hasSize(2) .contains(lookupEntry); }