001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.geronimo.javamail.store.imap.connection; 019 020 import java.util.ArrayList; 021 import java.util.List; 022 023 import javax.mail.MessagingException; 024 import javax.mail.Quota; 025 026 /** 027 * Util class to represent a list response from a IMAP server 028 * 029 * @version $Rev: 594520 $ $Date: 2007-11-13 07:57:39 -0500 (Tue, 13 Nov 2007) $ 030 */ 031 032 public class IMAPQuotaResponse extends IMAPUntaggedResponse { 033 // the returned quota item 034 public Quota quota; 035 036 /** 037 * Construct a LIST response item. This can be either 038 * a response from a LIST command or an LSUB command, 039 * and will be tagged accordingly. 040 * 041 * @param type The type of resonse (LIST or LSUB). 042 * @param data The raw response data. 043 * @param source The tokenizer source. 044 * 045 * @exception MessagingException 046 */ 047 public IMAPQuotaResponse(byte[] data, IMAPResponseTokenizer source) throws MessagingException { 048 super("QUOTA", data); 049 050 // first token is the root name, which can be either an atom or a string. 051 String tokenName = source.readString(); 052 053 // create a quota item for this 054 quota = new Quota(tokenName); 055 056 source.checkLeftParen(); 057 058 List resources = new ArrayList(); 059 060 while (source.notListEnd()) { 061 // quotas are returned as a set of triplets. The first element is the 062 // resource name, followed by the current usage and the limit value. 063 Quota.Resource resource = new Quota.Resource(source.readAtom(), source.readLong(), source.readLong()); 064 resources.add(resource); 065 } 066 067 quota.resources = (Quota.Resource[])resources.toArray(new Quota.Resource[resources.size()]); 068 } 069 } 070