@Override public Iterator<MessageUid> listAllMessageUids(Mailbox mailbox) throws MailboxException { return Iterators.transform(findInMailbox(mailbox, MessageRange.all(), FetchType.Metadata, UNLIMITED), MailboxMessage::getUid); } }
@Override public Iterator<MessageUid> listAllMessageUids(final Mailbox mailbox) throws MailboxException { return Iterators.transform(findInMailbox(mailbox, MessageRange.all(), FetchType.Full, UNLIMITED), MailboxMessage::getUid); }
private Task.Result moveMessages(CassandraId oldMailboxId, CassandraId newMailboxId, MailboxSession session, MailboxMergingTask.Context context) { return cassandraMessageIdDAO.retrieveMessages(oldMailboxId, MessageRange.all()) .join() .map(ComposedMessageIdWithMetaData::getComposedMessageId) .map(messageId -> moveMessage(newMailboxId, messageId, session, context)) .reduce(Task.Result.COMPLETED, Task::combine); }
@Override public Iterator<MessageUid> listAllMessageUids(Mailbox mailbox) throws MailboxException { CassandraId cassandraId = (CassandraId) mailbox.getMailboxId(); return messageIdDAO.retrieveMessages(cassandraId, MessageRange.all()) .join() .map(metaData -> metaData.getComposedMessageId().getUid()) .iterator(); }
@Test void retrieveDeletedMessageShouldReturnEmptyByDefault() { List<MessageUid> result = testee .retrieveDeletedMessage(MAILBOX_ID, MessageRange.all()) .join() .collect(Guavate.toImmutableList()); assertThat(result).isEmpty(); }
@Test void retrieveDeletedMessageShouldReturnAllMessageForMessageRangeAll() { addMessageForRetrieveTest(); List<MessageUid> result = testee .retrieveDeletedMessage(MAILBOX_ID, MessageRange.all()) .join() .collect(Guavate.toImmutableList()); assertThat(result).containsExactly(UID_1, UID_2, UID_3, UID_4, UID_7, UID_8); }
@Test void removeUnreadShouldReturnEmptyWhenNoData() { testee.removeDeleted(MAILBOX_ID, UID_1).join(); List<MessageUid> result = testee .retrieveDeletedMessage(MAILBOX_ID, MessageRange.all()) .join() .collect(Guavate.toImmutableList()); assertThat(result).isEmpty(); }
@Test void addDeletedMessageShouldBeIdempotent() { testee.addDeleted(MAILBOX_ID, UID_1).join(); testee.addDeleted(MAILBOX_ID, UID_1).join(); List<MessageUid> result = testee.retrieveDeletedMessage(MAILBOX_ID, MessageRange.all()) .join() .collect(Guavate.toImmutableList()); assertThat(result).containsExactly(UID_1); }
@Test void removeDeletedShouldRemoveSpecifiedUID() { testee.addDeleted(MAILBOX_ID, UID_2).join(); testee.removeDeleted(MAILBOX_ID, UID_2).join(); List<MessageUid> result = testee .retrieveDeletedMessage(MAILBOX_ID, MessageRange.all()) .join() .collect(Guavate.toImmutableList()); assertThat(result).isEmpty(); }
@Test void addDeletedMessageShouldThenBeReportedAsDeletedMessage() { testee.addDeleted(MAILBOX_ID, UID_1).join(); testee.addDeleted(MAILBOX_ID, UID_2).join(); List<MessageUid> result = testee.retrieveDeletedMessage(MAILBOX_ID, MessageRange.all()) .join() .collect(Guavate.toImmutableList()); assertThat(result).containsExactly(UID_1, UID_2); }
@Test void removeDeletedMessageShouldNotAffectOtherMessage() { testee.addDeleted(MAILBOX_ID, UID_2).join(); testee.addDeleted(MAILBOX_ID, UID_1).join(); testee.removeDeleted(MAILBOX_ID, UID_1).join(); List<MessageUid> result = testee .retrieveDeletedMessage(MAILBOX_ID, MessageRange.all()) .join() .collect(Guavate.toImmutableList()); assertThat(result).containsExactly(UID_2); }
@Test public void importEmlFileToMailboxShouldNotImportEmlFileWithWrongPathToGivenMailbox() throws Exception { Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY); mapperFactory.createMailboxMapper(session).save(mailbox); String emlpath = ClassLoader.getSystemResource("eml/frnog.eml").getFile(); mailboxManagerManagement.importEmlFileToMailbox(MailboxConstants.USER_NAMESPACE, USER, "name", "wrong_path" + emlpath); assertThat(mapperFactory.getMessageMapper(session).countMessagesInMailbox(mailbox)).isEqualTo(0); Iterator<MailboxMessage> iterator = mapperFactory.getMessageMapper(session).findInMailbox(mailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT); assertThat(iterator.hasNext()).isFalse(); }
@Test(expected = OverQuotaException.class) public void testCopyOverQuotaSize() throws Exception { QuotaSize maxQuotaSize = QuotaSize.size(15L * MockMail.MAIL_TEXT_PLAIN.length()); maxQuotaManager.setMaxStorage(quotaRootResolver.getQuotaRoot(inbox), maxQuotaSize); try { resources.fillMailbox(); } catch (OverQuotaException overQuotaException) { // Silent these exception as we don't want it to disturb the test } mailboxManager.copyMessages(MessageRange.all(), inbox, subFolder, session); }
@Test void appendShouldRemovePathSeparatorAsFirstChar() throws Exception { testee.append(mimeMessage, USER, "." + FOLDER); MessageResultIterator messages = mailboxManager.getMailbox(MailboxPath.forUser(USER, FOLDER), session) .getMessages(MessageRange.all(), new FetchGroupImpl(MessageResult.FetchGroup.FULL_CONTENT), session); assertThat(messages).hasSize(1); }
@Test void appendShouldAddMessageToDesiredMailbox() throws Exception { testee.append(mimeMessage, USER, FOLDER); MessageResultIterator messages = mailboxManager.getMailbox(MailboxPath.forUser(USER, FOLDER), session) .getMessages(MessageRange.all(), new FetchGroupImpl(MessageResult.FetchGroup.FULL_CONTENT), session); assertThat(messages).hasSize(1); }
@Test void appendShouldReplaceSlashBySeparator() throws Exception { testee.append(mimeMessage, USER, FOLDER + "/any"); MessageResultIterator messages = mailboxManager.getMailbox(MailboxPath.forUser(USER, FOLDER + ".any"), session) .getMessages(MessageRange.all(), new FetchGroupImpl(MessageResult.FetchGroup.FULL_CONTENT), session); assertThat(messages).hasSize(1); }
@Test void appendShouldAddMessageToDesiredMailboxWhenMailboxExists() throws Exception { MailboxPath mailboxPath = MailboxPath.forUser(USER, FOLDER); mailboxManager.createMailbox(mailboxPath, session); testee.append(mimeMessage, USER, FOLDER); MessageResultIterator messages = mailboxManager.getMailbox(mailboxPath, session) .getMessages(MessageRange.all(), new FetchGroupImpl(MessageResult.FetchGroup.FULL_CONTENT), session); assertThat(messages).hasSize(1); }
@Test(expected = OverQuotaException.class) public void testCopyOverQuotaMessages() throws Exception { try { resources.fillMailbox(); } catch (OverQuotaException overQuotaException) { // Silent these exception as we don't want it to disturb the test } QuotaCount maxMessageCount = QuotaCount.count(15L); maxQuotaManager.setMaxMessage(quotaRootResolver.getQuotaRoot(inbox), maxMessageCount); mailboxManager.copyMessages(MessageRange.all(), inbox, subFolder, session); }
@Test public void testRetrievalOverMaxStorage() throws Exception { QuotaSize maxQuotaSize = QuotaSize.size(15 * MockMail.MAIL_TEXT_PLAIN.getBytes(StandardCharsets.UTF_8).length + 1); maxQuotaManager.setMaxStorage(quotaRootResolver.getQuotaRoot(inbox), maxQuotaSize); try { resources.fillMailbox(); } catch (OverQuotaException overQuotaException) { // We are here over quota } messageManager.expunge(MessageRange.all(), session); // We have suppressed at list one message. Ensure we can add an other message. If is impossible, an exception will be thrown. resources.appendMessage(messageManager, session, new FlagsBuilder().add(Flags.Flag.SEEN).build()); }
@Test public void testRetrievalOverMaxMessage() throws Exception { QuotaCount maxMessageCount = QuotaCount.count(15L); maxQuotaManager.setMaxMessage(quotaRootResolver.getQuotaRoot(inbox), maxMessageCount); try { resources.fillMailbox(); } catch (OverQuotaException overQuotaException) { // We are here over quota } messageManager.expunge(MessageRange.all(), session); // We have suppressed at list one message. Ensure we can add an other message. If is impossible, an exception will be thrown. resources.appendMessage(messageManager, session, new FlagsBuilder().add(Flags.Flag.SEEN).build()); }