Java 类javax.mail.Quota 实例源码

项目:greenmail    文件:QuotaCommand.java   
@Override
protected void doProcess(final ImapRequestLineReader request, final ImapResponse response,
                         final ImapSession session) throws ProtocolException, FolderException, AuthorizationException {
    if(!session.getHost().getStore().isQuotaSupported()) {
        response.commandFailed(this,"Quota is not supported. Activate quota capability first");
    }

    String root = parser.mailbox(request);
    // NAME root (name usage limit)

    Quota[] quota = session.getHost().getStore().getQuota(
            root, session.getUser().getQualifiedMailboxName());
    for(Quota q: quota) {
        StringBuilder buf = new StringBuilder();
        appendQuota(q, buf);
        response.untaggedResponse(buf.toString());
    }

    response.commandComplete(this);
}
项目:greenmail    文件:QuotaCommand.java   
protected void appendQuota(Quota quota, StringBuilder buf) {
    buf.append("QUOTA ");
    appendQuotaRootName(quota, buf);
    buf.append(SP);
    buf.append('(');
    boolean pad = false;
    for(Quota.Resource resource:quota.resources) {
        if(pad) {
           buf.append(SP);
        }
        buf.append(resource.name);
        buf.append(SP).append(resource.usage);
        buf.append(SP).append(resource.limit);
        pad = true;
    }
    buf.append(')');
}
项目:greenmail    文件:SetQuotaCommand.java   
@Override
protected void doProcess(final ImapRequestLineReader request, final ImapResponse response,
                         final ImapSession session) {
    if(!session.getHost().getStore().isQuotaSupported()) {
        response.commandFailed(this,"Quota is not supported. Activate quota capability first");
    }
    try {
        String root = parser.mailbox(request);
        Quota quota = new Quota(root);
        parser.consumeChar(request, ' ');
        parser.consumeChar(request, '(');
        quota.setResourceLimit(parser.astring(request), parser.consumeLong(request));
        char c =request.nextWordChar();
        if(')' != c) {
            quota.setResourceLimit(parser.astring(request), parser.consumeLong(request));
        }
        parser.consumeChar(request, ')');
        session.getHost().getStore().setQuota(
                quota, session.getUser().getQualifiedMailboxName());
        response.commandComplete(this);
    } catch (ProtocolException e) {
        response.commandFailed(this, "Can not parse command"+e.getMessage());
    }
}
项目:greenmail    文件:InMemoryStore.java   
@Override
public Quota[] getQuota(final String root, final String qualifiedRootPrefix) {
    Set<String> rootPaths = new HashSet<>();
    if (!root.contains(ImapConstants.HIERARCHY_DELIMITER)) {
        rootPaths.add(qualifiedRootPrefix + root);
    } else {
        for (String r : root.split(ImapConstants.HIERARCHY_DELIMITER)) {
            rootPaths.add(qualifiedRootPrefix + r);
        }
    }
    rootPaths.add(qualifiedRootPrefix); // Add default root

    Set<Quota> collectedQuotas = new HashSet<>();
    for (String p : rootPaths) {
        Set<Quota> quotas = quotaMap.get(p);
        if (null != quotas) {
            collectedQuotas.addAll(quotas);
        }
    }
    updateQuotas(collectedQuotas, qualifiedRootPrefix);
    return collectedQuotas.toArray(new Quota[collectedQuotas.size()]);
}
项目:greenmail    文件:InMemoryStore.java   
private void updateQuota(final Quota quota, final String pQualifiedRootPrefix) {
    MailFolder folder = getMailbox(
            ImapConstants.USER_NAMESPACE + ImapConstants.HIERARCHY_DELIMITER +
                    pQualifiedRootPrefix + ImapConstants.HIERARCHY_DELIMITER +
                    quota.quotaRoot);
    try {
        for (Quota.Resource r : quota.resources) {
            if (STORAGE.equals(r.name)) {
                long size = 0;
                for (StoredMessage m : folder.getMessages()) {
                    size += m.getMimeMessage().getSize();
                }
                r.usage = size;
            } else if (MESSAGES.equals(r.name)) {
                r.usage = folder.getMessageCount();
            } else {
                throw new IllegalStateException("Quota " + r.name + " not supported");
            }
        }
    } catch (MessagingException ex) {
        throw new IllegalStateException("Can not update/verify quota " + quota, ex);
    }
}
项目:greenmail    文件:InMemoryStore.java   
@Override
public void setQuota(final Quota quota, String qualifiedRootPrefix) {
    // Validate
    for (Quota.Resource r : quota.resources) {
        if (!STORAGE.equals(r.name) && !MESSAGES.equals(r.name)) {
            throw new IllegalStateException("Quota " + r.name + " not supported");
        }
    }

    // Save quota
    Set<Quota> quotas = quotaMap.get(qualifiedRootPrefix + quota.quotaRoot);
    if (null == quotas) {
        quotas = new HashSet<>();
        quotaMap.put(qualifiedRootPrefix + quota.quotaRoot, quotas);
    } else {
        quotas.clear(); // " Any previous resource limits for the named quota root are discarded"
    }
    quotas.add(quota);
}
项目:greenmail    文件:QuotaCommand.java   
protected void appendQuotaRootName(Quota quota, StringBuilder buf) {
    String rootName = quota.quotaRoot;
    if(null == rootName || rootName.length()==0) {
        rootName = "\"\"";
    }
    buf.append('\"').append(rootName).append('\"');
}
项目:javamail-mock2    文件:IMAPMockStore.java   
@Override
public synchronized Quota[] getQuota(final String root) throws MessagingException {
    throw new MessagingException("QUOTA not supported");
}
项目:javamail-mock2    文件:IMAPMockFolder.java   
@Override
public Quota[] getQuota() throws MessagingException {
    throw new MessagingException("QUOTA not supported");
}
项目:javamail-mock2    文件:IMAPMockFolder.java   
@Override
public void setQuota(final Quota quota) throws MessagingException {
    throw new MessagingException("QUOTA not supported");
}
项目:greenmail    文件:InMemoryStore.java   
private void updateQuotas(final Set<Quota> quotas,
                          final String qualifiedRootPrefix) {
    for (Quota q : quotas) {
        updateQuota(q, qualifiedRootPrefix);
    }
}
项目:javamail-mock2    文件:IMAPMockStore.java   
@Override
public synchronized void setQuota(final Quota quota) throws MessagingException {

    throw new MessagingException("QUOTA not supported");

}
项目:greenmail    文件:Store.java   
/**
 * Gets the quotas.
 *
 * @link http://www.ietf.org/rfc/rfc2087.txt
 * @see com.sun.mail.imap.IMAPStore#getQuota(String)
 * @param root the quota root
 * @param qualifiedRootPrefix the user specific prefix
 * @return the quotas, or an empty array.
 */
Quota[] getQuota(String root, String qualifiedRootPrefix);
项目:greenmail    文件:Store.java   
/**
 * Sets the quota.
 *
 * @link http://www.ietf.org/rfc/rfc2087.txt
 * @see com.sun.mail.imap.IMAPStore#setQuota(javax.mail.Quota)
 * @param quota the quota.
 * @param qualifiedRootPrefix the user specific prefix
 */
void setQuota(Quota quota, String qualifiedRootPrefix);