@Override protected void initializeMailboxManager() throws Exception { storeMailboxManager = new InMemoryIntegrationResources() .createMailboxManager(new SimpleGroupMembershipResolver()); messageSearchIndex = new SimpleMessageSearchIndex( storeMailboxManager.getMapperFactory(), storeMailboxManager.getMapperFactory(), new PDFTextExtractor()); messageIdManager = new StoreMessageIdManager( storeMailboxManager, storeMailboxManager.getMapperFactory(), storeMailboxManager.getEventDispatcher(), storeMailboxManager.getMessageIdFactory(), storeMailboxManager.getQuotaManager(), storeMailboxManager.getQuotaRootResolver()); storeMailboxManager.setMessageSearchIndex(messageSearchIndex); }
@Test public void doneShouldNotMoveMailFromOutboxToSentWhenNoMetadataProvided() throws Exception { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession); MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); messageManager.appendMessage(AppendCommand.from(message), mailboxSession); testee.done(true); MessageManager mailbox = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); MessageResultIterator resultIterator = mailbox.getMessages(MessageRange.one(UID), FetchGroupImpl.FULL_CONTENT, mailboxSession); assertThat(resultIterator).hasSize(1); }
@Before public void setup() throws Exception { GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver(); InMemoryIntegrationResources.Resources resources = new InMemoryIntegrationResources() .createResources(groupMembershipResolver); storeMailboxManager = resources.getMailboxManager(); storeRightManager = resources.getStoreRightManager(); mailboxMapper = storeMailboxManager.getMapperFactory(); testee = new PropagateLookupRightListener(storeRightManager); storeMailboxManager.addGlobalListener(testee, mailboxSession); parentMailboxId = storeMailboxManager.createMailbox(PARENT_MAILBOX, mailboxSession).get(); parentMailboxId1 = storeMailboxManager.createMailbox(PARENT_MAILBOX1, mailboxSession).get(); childMailboxId = storeMailboxManager.createMailbox(CHILD_MAILBOX, mailboxSession).get(); childMailboxId1 = storeMailboxManager.createMailbox(CHILD_MAILBOX1, mailboxSession).get(); grandChildMailboxId = storeMailboxManager.createMailbox(GRAND_CHILD_MAILBOX, mailboxSession).get(); lookupEntry = new Entry(SHARED_USER, "l"); }
@Override public List<MessageRange> copyMessages(MessageRange set, MailboxId from, MailboxId to, final MailboxSession session) throws MailboxException { final StoreMessageManager toMailbox = (StoreMessageManager) getMailbox(to, session); final StoreMessageManager fromMailbox = (StoreMessageManager) getMailbox(from, session); return copyMessages(set, session, toMailbox, fromMailbox); }
/** * Create a {@link MailboxManager} for the given Mailbox. By default this will return a {@link StoreMessageManager}. If * your implementation needs something different, just override this method * * @param mailbox * @param session * @return storeMailbox */ protected StoreMessageManager createMessageManager(Mailbox mailbox, MailboxSession session) throws MailboxException { return new StoreMessageManager(DEFAULT_NO_MESSAGE_CAPABILITIES, getMapperFactory(), getMessageSearchIndex(), getEventDispatcher(), getLocker(), mailbox, getQuotaManager(), getQuotaRootResolver(), getMessageParser(), getMessageIdFactory(), getBatchSizes(), getImmutableMailboxMessageFactory(), getStoreRightManager()); }
public MessageIdManager createMessageIdManager(StoreMailboxManager mailboxManager, MessageId.Factory factory) { return new StoreMessageIdManager( mailboxManager, mailboxManager.getMapperFactory(), mailboxManager.getEventDispatcher(), factory, mailboxManager.getQuotaManager(), mailboxManager.getQuotaRootResolver()); }
MailboxSession session = mailboxManager.login("foo6", "bar6"); mailboxManager.startProcessingRequest(session); if (!mailboxManager.mailboxExists(mailboxPath, session)) { mailboxManager.createMailbox(mailboxPath, session); bigMail = null; mailboxManager.getMailbox(mailboxPath, session).appendMessage(MessageManager.AppendCommand.builder() .build(out.toByteArray()), session); mailboxManager.startProcessingRequest(session); mailboxManager.deleteMailbox(mailboxPath, session);
@Override public List<MessageRange> moveMessages(MessageRange set, MailboxPath from, MailboxPath to, final MailboxSession session) throws MailboxException { final StoreMessageManager toMailbox = (StoreMessageManager) getMailbox(to, session); final StoreMessageManager fromMailbox = (StoreMessageManager) getMailbox(from, session); return moveBatcher.batchMessages(set, messageRange -> fromMailbox.moveTo(messageRange, toMailbox, session)); }
@Test @SuppressWarnings("unchecked") public void getMailboxesShouldReturnMailboxesWithRoles() throws Exception { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "INBOX"), mailboxSession); mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Archive"), mailboxSession); mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Drafts"), mailboxSession); mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Outbox"), mailboxSession); mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Sent"), mailboxSession); mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Trash"), mailboxSession); mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Spam"), mailboxSession); mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Templates"), mailboxSession); mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "WITHOUT ROLE"), mailboxSession);
public void run() { if (fail.get()){ latch.countDown(); return; } MailboxSession session = getMailboxManager().createSystemSession("test", new SimpleLog("Test")); try { getMailboxManager().startProcessingRequest(session); MessageManager m = getMailboxManager().getMailbox(path, session); System.out.println("Append message with uid=" + m.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), session, false, new Flags())); getMailboxManager().endProcessingRequest(session); getMailboxManager().logout(session,false); } catch (MailboxException e) { e.printStackTrace(); fail.set(true); } finally { latch.countDown(); } } });
@Test public void getParentIdFromMailboxPathShouldReturnParentIdWhenChildOfChildMailbox() throws Exception { MailboxPath mailboxPath = MailboxPath.forUser(user, "inbox.children.mailbox"); mailboxManager.createMailbox(MailboxPath.forUser(user, "inbox"), mailboxSession); MailboxPath parentMailboxPath = MailboxPath.forUser(user, "inbox.children"); mailboxManager.createMailbox(parentMailboxPath, mailboxSession); MailboxId parentId = mailboxManager.getMailbox(parentMailboxPath, mailboxSession).getId(); mailboxManager.createMailbox(mailboxPath, mailboxSession); Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, Optional.empty(), mailboxSession); assertThat(id).contains(parentId); }
final ExecutorService pool = Executors.newFixedThreadPool(APPEND_OPERATIONS/2); MailboxSession session = getMailboxManager().createSystemSession("test", new SimpleLog("Test")); getMailboxManager().startProcessingRequest(session); final MailboxPath path = new MailboxPath(MailboxConstants.USER_NAMESPACE, "username", "INBOX"); getMailboxManager().createMailbox(path, session); getMailboxManager().endProcessingRequest(session); getMailboxManager().logout(session, false); final AtomicBoolean fail = new AtomicBoolean(false);
@Before public void setUp() throws Exception { StoreMailboxManager mailboxManager = new InMemoryIntegrationResources() .createMailboxManager(new SimpleGroupMembershipResolver()); mapperFactory = mailboxManager.getMapperFactory(); mailboxManagerManagement = new MailboxManagerManagement(); mailboxManagerManagement.setMailboxManager(mailboxManager); session = mailboxManager.createSystemSession("TEST"); }
idGenerator = new RandomMailboxSessionIdGenerator(); MailboxSession session = createSystemSession("storeMailboxManager"); if (index == null) { index = new SimpleMessageSearchIndex(mailboxSessionMapperFactory, mailboxSessionMapperFactory, new DefaultTextExtractor()); this.addGlobalListener((MailboxListener) index, session); this.addGlobalListener((MailboxListener) quotaUpdater, session); moveBatcher = new MessageBatcher(MessageBatcher.NO_BATCH_SIZE); if (hasCapability(MailboxCapabilities.Annotation)) { this.addGlobalListener(new MailboxAnnotationListener(mailboxSessionMapperFactory), session);
@Override public QuotaManager createQuotaManager(MaxQuotaManager maxQuotaManager, StoreMailboxManager mailboxManager) throws Exception { QuotaRootResolver quotaRootResolver = createQuotaRootResolver(mailboxManager); InMemoryCurrentQuotaManager currentQuotaManager = createCurrentQuotaManager(mailboxManager); StoreQuotaManager quotaManager = new StoreQuotaManager(currentQuotaManager, maxQuotaManager); ListeningCurrentQuotaUpdater listeningCurrentQuotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager, quotaRootResolver, mailboxManager.getEventDispatcher(), quotaManager); mailboxManager.setQuotaManager(quotaManager); mailboxManager.addGlobalListener(listeningCurrentQuotaUpdater, null); return quotaManager; }
@Before public void setUp() throws Exception { mailboxManager = new InMemoryIntegrationResources().createMailboxManager(new SimpleGroupMembershipResolver()); quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager.getMapperFactory()); maxQuotaManager = new InMemoryPerUserMaxQuotaManager(); CurrentQuotaCalculator quotaCalculator = new CurrentQuotaCalculator(mailboxManager.getMapperFactory(), quotaRootResolver); InMemoryCurrentQuotaManager currentQuotaManager = new InMemoryCurrentQuotaManager(quotaCalculator, mailboxManager); StoreQuotaManager quotaManager = new StoreQuotaManager(currentQuotaManager, maxQuotaManager); usersRepository = mock(UsersRepository.class); testee = new IsOverQuota(quotaRootResolver, quotaManager, mailboxManager, usersRepository); mailboxManager.setQuotaRootResolver(quotaRootResolver); mailboxManager.setQuotaManager(quotaManager); testee.init(FakeMatcherConfig.builder().matcherName("IsOverQuota").build()); when(usersRepository.getUser(MailAddressFixture.ANY_AT_JAMES)).thenReturn(MailAddressFixture.ANY_AT_JAMES.getLocalPart()); when(usersRepository.getUser(MailAddressFixture.OTHER_AT_JAMES)).thenReturn(MailAddressFixture.OTHER_AT_JAMES.getLocalPart()); }
@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); }
@Override public DefaultUserQuotaRootResolver createQuotaRootResolver(StoreMailboxManager mailboxManager) { if (quotaRootResolver == null) { quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager.getMapperFactory()); } return quotaRootResolver; }
@Test public void getMailboxesShouldReturnEmptyListWhenNoMailboxes() { GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() .build(); MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, clientId, mailboxSession).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) .extracting(JmapResponse::getResponse) .hasOnlyElementsOfType(GetMailboxesResponse.class) .extracting(GetMailboxesResponse.class::cast) .flatExtracting(GetMailboxesResponse::getList) .isEmpty(); }
@Test public void getNamespaceShouldReturnDelegatedNamespaceWhenUserMailboxPathAndUserMailboxSessionAreNotTheSame() throws Exception { MailboxPath inbox = MailboxPath.forUser(user, "inbox"); Optional<MailboxId> mailboxId = mailboxManager.createMailbox(inbox, mailboxSession); mailboxManager.applyRightsCommand(inbox, MailboxACL.command() .forUser(otherUser) .rights(MailboxACL.Right.Read, MailboxACL.Right.Lookup) .asAddition(), mailboxSession); Mailbox retrievedMailbox = sut.builder() .id(mailboxId.get()) .session(otherMailboxSession) .build() .get(); assertThat(retrievedMailbox.getNamespace()) .isEqualTo(MailboxNamespace.delegated(user)); }