001 /* 002 * Copyright 2010 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package com.hs.mail.imap.message.responder.ext; 017 018 import javax.mail.Quota; 019 020 import org.jboss.netty.channel.Channel; 021 022 import com.hs.mail.imap.message.request.ImapRequest; 023 import com.hs.mail.imap.message.responder.DefaultImapResponder; 024 import com.hs.mail.imap.message.response.ext.QuotaResponse; 025 026 /** 027 * 028 * @author Won Chul Doh 029 * @since Apr 19, 2010 030 * 031 */ 032 public class QuotaResponder extends DefaultImapResponder { 033 034 public QuotaResponder(Channel channel, ImapRequest request) { 035 super(channel, request); 036 } 037 038 public void respond(QuotaResponse response) { 039 composeQuotaRoot(response); 040 composeQuota(response.getQuota()); 041 } 042 043 private void composeQuotaRoot(QuotaResponse response) { 044 if (response.getMailbox() != null) { 045 untagged("QUOTAROOT"); 046 quote(response.getMailbox()); 047 quote(response.getQuota().quotaRoot); 048 end(); 049 } 050 } 051 052 private void composeQuota(Quota quota) { 053 untagged("QUOTA"); 054 quote(quota.quotaRoot); 055 openParen("("); 056 composeResouces(quota.resources); 057 closeParen(")"); 058 end(); 059 } 060 061 private void composeResouces(Quota.Resource[] resources) { 062 if (resources != null) { 063 for (int i = 0; i < resources.length; i++) { 064 message(resources[i].name); 065 message(resources[i].usage); 066 message(resources[i].limit); 067 } 068 } 069 } 070 071 }