@Override public DefaultUserQuotaRootResolver createQuotaRootResolver(StoreMailboxManager mailboxManager) { if (quotaRootResolver == null) { quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager.getMapperFactory()); } return quotaRootResolver; }
@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); }
@Test public void matchShouldSupportVirtualHosting() throws Exception { when(usersRepository.getUser(MailAddressFixture.ANY_AT_JAMES)).thenReturn(MailAddressFixture.ANY_AT_JAMES.asString()); when(usersRepository.getUser(MailAddressFixture.OTHER_AT_JAMES)).thenReturn(MailAddressFixture.OTHER_AT_JAMES.asString()); String username = MailAddressFixture.ANY_AT_JAMES.asString(); QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(MailboxPath.inbox(mailboxManager.createSystemSession(username))); maxQuotaManager.setMaxStorage(quotaRoot, QuotaSize.size(100)); FakeMail fakeMail = FakeMail.builder() .recipient(MailAddressFixture.ANY_AT_JAMES) .recipient(MailAddressFixture.OTHER_AT_JAMES) .size(150) .build(); Collection<MailAddress> result = testee.match(fakeMail); assertThat(result).containsOnly(MailAddressFixture.ANY_AT_JAMES); }
@Test public void matchShouldNotIncludeRecipientNotOverQuota() throws Exception { String username = MailAddressFixture.ANY_AT_JAMES.getLocalPart(); QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(MailboxPath.inbox(mailboxManager.createSystemSession(username))); maxQuotaManager.setMaxStorage(quotaRoot, QuotaSize.size(100)); FakeMail fakeMail = FakeMail.builder() .recipient(MailAddressFixture.ANY_AT_JAMES) .recipient(MailAddressFixture.OTHER_AT_JAMES) .size(150) .build(); Collection<MailAddress> result = testee.match(fakeMail); assertThat(result).containsOnly(MailAddressFixture.ANY_AT_JAMES); }
public static StoreMessageIdManager createMessageIdManager(CassandraMailboxSessionMapperFactory mapperFactory, QuotaManager quotaManager, MailboxEventDispatcher dispatcher) throws Exception { return new StoreMessageIdManager( createMailboxManager(mapperFactory), mapperFactory, dispatcher, new CassandraMessageId.Factory(), quotaManager, new DefaultUserQuotaRootResolver(mapperFactory)); }
@Override public QuotaRoot fromString(String serializedQuotaRoot) throws MailboxException { List<String> parts = toParts(serializedQuotaRoot); User user = User.fromUsername(parts.get(1)); return QuotaRoot.quotaRoot(serializedQuotaRoot, user.getDomainPart()); }
quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxSessionMapperFactory);
@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()); }
messageIdFactory, quotaManager, new DefaultUserQuotaRootResolver(mapperFactory)); return new MessageIdManagerTestSystem(messageIdManager, messageIdFactory, mapperFactory, mailboxManager);
CassandraCurrentQuotaManager currentQuotaUpdater = new CassandraCurrentQuotaManager(session); StoreQuotaManager storeQuotaManager = new StoreQuotaManager(currentQuotaUpdater, maxQuotaManager); QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mapperFactory);