@Override public boolean equals(Object o) { if (o == null || ! (o instanceof Quota)) { return false; } Quota<?> other = (Quota<?>) o; return Objects.equal(used, other.getUsed()) && Objects.equal(limit,other.getLimit()); }
@Override public String toString() { StringBuilder result = new StringBuilder() .append(ImapConstants.QUOTA_RESPONSE_NAME) .append(' ') .append(quotaRoot) .append(' ') .append('(') .append(resourceName) .append(' ') .append(quota.getUsed()) .append(' ') .append(quota.getLimit()) .append(')'); return result.toString(); }
private HashMap<String, Object> computeScopes() { HashMap<String, Object> scopes = new HashMap<>(); scopes.put("hasExceededSizeThreshold", sizeThreshold.isPresent()); scopes.put("hasExceededCountThreshold", countThreshold.isPresent()); sizeThreshold.ifPresent(value -> scopes.put("sizeThreshold", value.getQuotaOccupationRatioAsPercent())); countThreshold.ifPresent(value -> scopes.put("countThreshold", value.getQuotaOccupationRatioAsPercent())); scopes.put("usedSize", SizeFormat.format(sizeQuota.getUsed().asLong())); scopes.put("hasSizeLimit", sizeQuota.getLimit().isLimited()); if (sizeQuota.getLimit().isLimited()) { scopes.put("limitSize", SizeFormat.format(sizeQuota.getLimit().asLong())); } scopes.put("usedCount", countQuota.getUsed().asLong()); scopes.put("hasCountLimit", countQuota.getLimit().isLimited()); if (countQuota.getLimit().isLimited()) { scopes.put("limitCount", sizeQuota.getLimit().asLong()); } return scopes; }
public static <U extends QuotaValue<U>> SerializableQuota<U> newInstance(Quota<U> quota) { return newInstance(quota.getUsed(), quota.getLimit()); }
private <T extends QuotaValue<T>> Quotas.Value<T> quotaToValue(Quota<T> quota) { return new Quotas.Value<>( quotaValueToNumber(quota.getUsed()), quotaValueToOptionalNumber(quota.getLimit())); }
private void writeMessagesCount(ImapResponseComposer composer, Quota<?> quota) throws IOException { composer.message(quota.getUsed().asLong()); composer.message(quota.getLimit().asLong()); }
private void writeMessagesSize(ImapResponseComposer composer, Quota<?> quota) throws IOException { composer.message(quota.getUsed().asLong() / 1024); composer.message(quota.getLimit().asLong() / 1024); }
private void trySizeAddition(long size) throws OverQuotaException { Quota<QuotaSize> afterAdditionQuotaSize = sizeQuota.addValueToQuota(QuotaSize.size(size)); if (afterAdditionQuotaSize.isOverQuota()) { throw new OverQuotaException( "You use too much space in " + quotaRoot.getValue(), afterAdditionQuotaSize.getLimit(), afterAdditionQuotaSize.getUsed()); } }
private void tryCountAddition(long count) throws OverQuotaException { Quota<QuotaCount> afterAdditionQuotaCount = messageQuota.addValueToQuota(QuotaCount.count(count)); if (afterAdditionQuotaCount.isOverQuota()) { throw new OverQuotaException( "You have too many messages in " + quotaRoot.getValue(), messageQuota.getLimit(), messageQuota.getUsed()); } }
@Override protected void doProcess(GetQuotaRequest message, ImapSession session, String tag, ImapCommand command, Responder responder) { try { QuotaRoot quotaRoot = quotaRootResolver.fromString(message.getQuotaRoot()); if (hasRight(quotaRoot, session)) { Quota<QuotaCount> messageQuota = quotaManager.getMessageQuota(quotaRoot); Quota<QuotaSize> storageQuota = quotaManager.getStorageQuota(quotaRoot); if (messageQuota.getLimit().isLimited()) { responder.respond(new QuotaResponse(ImapConstants.MESSAGE_QUOTA_RESOURCE, quotaRoot.getValue(), messageQuota)); } if (storageQuota.getLimit().isLimited()) { responder.respond(new QuotaResponse(ImapConstants.STORAGE_QUOTA_RESOURCE, quotaRoot.getValue(), storageQuota)); } okComplete(command, tag, responder); } else { Object[] params = new Object[]{ MailboxACL.Right.Read.toString(), command.getName(), "Any mailbox of this user USER" }; HumanReadableText humanReadableText = new HumanReadableText(HumanReadableText.UNSUFFICIENT_RIGHTS_KEY, HumanReadableText.UNSUFFICIENT_RIGHTS_DEFAULT_VALUE, params); no(command, tag, responder, humanReadableText); } } catch (MailboxException me) { taggedBad(command, tag, responder, HumanReadableText.FAILURE_NO_SUCH_MAILBOX); } }
Quota<QuotaSize> storageQuota = quotaManager.getStorageQuota(quotaRoot); responder.respond(new QuotaRootResponse(message.getMailboxName(), quotaRoot.getValue())); if (messageQuota.getLimit().isLimited()) { responder.respond(new QuotaResponse(ImapConstants.MESSAGE_QUOTA_RESOURCE, quotaRoot.getValue(), messageQuota)); if (storageQuota.getLimit().isLimited()) { responder.respond(new QuotaResponse(ImapConstants.STORAGE_QUOTA_RESOURCE, quotaRoot.getValue(), storageQuota));