class IsOverQuota extends GenericMatcher {

    @Override
    public Collection<MailAddress> match(Mail mail) throws MessagingException {
        try {
            List<MailAddress> result = new ArrayList<>();
            for (MailAddress mailAddress : mail.getRecipients()) {
                Username userName = usersRepository.getUsername(mailAddress);
                MailboxPath mailboxPath = MailboxPath.inbox(userName);
                QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(mailboxPath);

                if (quotaManager.getMessageQuota(quotaRoot).isOverQuotaWithAdditionalValue(SINGLE_EMAIL) ||
                    quotaManager.getStorageQuota(quotaRoot).isOverQuotaWithAdditionalValue(mail.getMessageSize())) {
                    result.add(mailAddress);
                }
            }
            return result;
        } catch (MailboxException e) {
            throw new MessagingException("Exception while checking quotas", e);
        } catch (UsersRepositoryException e) {
            throw new MessagingException("Exception while retrieving username", e);
        }
    }

    @Inject public  IsOverQuota(QuotaRootResolver quotaRootResolver, QuotaManager quotaManager, UsersRepository usersRepository);

}