/** * Return a {@link MailboxPath} which represent the INBOX of the given * session * * @param session * @return inbox */ public static MailboxPath inbox(MailboxSession session) { return MailboxPath.forUser(session.getUser().asString(), MailboxConstants.INBOX); }
@Test public void getHierarchyLevelsShouldBeOrdered() { assertThat(MailboxPath.forUser("user", "inbox.folder.subfolder") .getHierarchyLevels('.')) .containsExactly( MailboxPath.forUser("user", "inbox"), MailboxPath.forUser("user", "inbox.folder"), MailboxPath.forUser("user", "inbox.folder.subfolder")); }
@Override public Stream<MessageManager> getMailboxByRole(Role aRole, MailboxSession session) throws MailboxException { MailboxPath mailboxPath = MailboxPath.forUser(session.getUser().getUserName(), aRole.getDefaultMailbox()); try { return Stream.of(mailboxManager.getMailbox(mailboxPath, session)); } catch (MailboxNotFoundException e) { return searchMessageManagerByMailboxRole(aRole, session); } }
@Test public void listShouldNotListMailboxWithOtherUserKOREA() throws Exception { system.createMailbox(MailboxPath.forUser(USER + "2", "Other")); simpleScriptedTestProtocol .withLocale(Locale.KOREA) .run("ListMailboxes"); } }
private static void createSubSubMailboxes(MailboxManager mailboxManager,MailboxSession mailboxSession, String subFolderName) { IntStream.range(0, SUB_SUB_MAILBOXES_COUNT) .mapToObj(i -> subFolderName + ".SUBSUB_FOLDER_" + i) .forEach(name -> createMailbox(mailboxManager, mailboxSession, MailboxPath.forUser(mailboxSession.getUser().asString(), name))); }
@Given("^\"([^\"]*)\" mailbox \"([^\"]*)\" contains a message \"([^\"]*)\" with an inlined attachment \"([^\"]*)\"$") public void appendMessageWithInlinedAttachmentToMailbox(String user, String mailbox, String messageId, String attachmentId) throws Throwable { MailboxPath mailboxPath = MailboxPath.forUser(user, mailbox); ComposedMessageId composedMessageId = mainStepdefs.mailboxProbe.appendMessage(user, mailboxPath, AppendCommand.from(ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"))); retrieveAndSaveAttachmentDetails(user, messageId, attachmentId, composedMessageId); }
@Test public void getNamespaceShouldReturnPersonalNamespaceWhenUserMailboxPathAndUserMailboxSessionAreTheSame() throws Exception { MailboxPath inbox = MailboxPath.forUser(user, "inbox"); Optional<MailboxId> mailboxId = mailboxManager.createMailbox(inbox, mailboxSession); Mailbox retrievedMailbox = sut.builder() .id(mailboxId.get()) .session(mailboxSession) .build() .get(); assertThat(retrievedMailbox.getNamespace()) .isEqualTo(MailboxNamespace.personal()); }
private static void provisionUser(MailboxManager mailboxManager, String user) throws MailboxException { MailboxSession mailboxSession = mailboxManager.createSystemSession(user); mailboxManager.startProcessingRequest(mailboxSession); createMailbox(mailboxManager, mailboxSession, MailboxPath.inbox(mailboxSession)); IntStream.range(0, SUB_MAILBOXES_COUNT) .mapToObj(i -> MailboxConstants.INBOX + ".SUB_FOLDER_" + i) .peek(name -> createMailbox(mailboxManager, mailboxSession, MailboxPath.forUser(user, name))) .forEach(name -> createSubSubMailboxes(mailboxManager, mailboxSession, name)); mailboxManager.endProcessingRequest(mailboxSession); mailboxManager.logout(mailboxSession, true); }
@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 public void creatingConcurrentlyMailboxesWithSameParentShouldNotFail() throws Exception { MailboxSession session = mailboxManager.createSystemSession(USER_1); String mailboxName = "a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z"; ConcurrentTestRunner.builder() .operation((a, b) -> mailboxManager.createMailbox(MailboxPath.forUser(USER_1, mailboxName + a), session)) .threadCount(10) .runSuccessfullyWithin(Duration.ofMinutes(1)); }
@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 default void groupListenersShouldNotReceiveNoopEvents() throws Exception { MailboxListener listener = newListener(); eventBus().register(listener, GROUP_A); MailboxListener.Added noopEvent = new MailboxListener.Added(MailboxSession.SessionId.of(18), User.fromUsername("bob"), MailboxPath.forUser("bob", "mailbox"), TestId.of(58), ImmutableSortedMap.of(), Event.EventId.random()); eventBus().dispatch(noopEvent, NO_KEYS).block(); verify(listener, after(FIVE_HUNDRED_MS.toMillis()).never()) .event(any()); }
@Test default void registeredListenersShouldNotReceiveNoopEvents() throws Exception { MailboxListener listener = newListener(); eventBus().register(listener, KEY_1); MailboxListener.Added noopEvent = new MailboxListener.Added(MailboxSession.SessionId.of(18), User.fromUsername("bob"), MailboxPath.forUser("bob", "mailbox"), TestId.of(58), ImmutableSortedMap.of(), Event.EventId.random()); eventBus().dispatch(noopEvent, KEY_1).block(); verify(listener, after(FIVE_HUNDRED_MS.toMillis()).never()) .event(any()); }