KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > mail > providers > imap4 > IMAPResponse


1 /*
2  * IMAPResponse.java
3  * Copyright (C) 2003 Chris Burdess <dog@gnu.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * You also have permission to link it with the Sun Microsystems, Inc.
11  * JavaMail(tm) extension and run that combination.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  */

22
23 package gnu.mail.providers.imap4;
24
25 import java.util.List JavaDoc;
26
27 /**
28  * An IMAP4rev1 server response.
29  *
30  * @author <a HREF='mailto:dog@gnu.org'>Chris Burdess</a>
31  * @version 0.1
32  */

33 public class IMAPResponse
34 {
35
36   /**
37    * The untagged response tag.
38    */

39   public static final String JavaDoc UNTAGGED = "*".intern();
40
41   /**
42    * The continuation response tag.
43    */

44   public static final String JavaDoc CONTINUATION = "+".intern();
45
46   /**
47    * The tag for this response.
48    */

49   protected String JavaDoc tag;
50   
51   /**
52    * The response ID.
53    */

54   protected String JavaDoc id;
55
56   /**
57    * The message count (for responses returning counts).
58    */

59   protected int count = -1;
60
61   /**
62    * The mailbox (for STATUS responses).
63    */

64   protected String JavaDoc mailbox;
65
66   /**
67    * The response code.
68    */

69   protected List JavaDoc code;
70
71   /**
72    * The content of a FETCH response.
73    */

74   protected byte[] content;
75
76   /**
77    * The human-readable text.
78    */

79   protected String JavaDoc text;
80
81   public String JavaDoc getTag()
82   {
83     return tag;
84   }
85
86   public boolean isTagged()
87   {
88     return (tag!=UNTAGGED && tag!=CONTINUATION);
89   }
90
91   public boolean isUntagged()
92   {
93     return (tag==UNTAGGED);
94   }
95
96   public boolean isContinuation()
97   {
98     return (tag==CONTINUATION);
99   }
100
101   public String JavaDoc getID()
102   {
103     return id;
104   }
105
106   public int getCount()
107   {
108     return count;
109   }
110
111   public List JavaDoc getResponseCode()
112   {
113     return code;
114   }
115
116   public byte[] getContent()
117   {
118     return content;
119   }
120   
121   public String JavaDoc getText()
122   {
123     return text;
124   }
125
126   /**
127    * ANSI-coloured toString for debugging.
128    */

129   public String JavaDoc toString()
130   {
131     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
132     buffer.append(tag);
133     if (count!=-1)
134     {
135       buffer.append(" \u001b[00;31m");
136       buffer.append(count);
137       buffer.append("\u001b[00m");
138     }
139     buffer.append(" \u001b[01m");
140     buffer.append(id);
141     buffer.append("\u001b[00m");
142     if (mailbox!=null)
143     {
144       buffer.append(" \u001b[00;35m");
145       buffer.append(mailbox);
146       buffer.append("\u001b[00m");
147     }
148     if (code!=null)
149     {
150       buffer.append(" \u001b[00;36m");
151       buffer.append(code);
152       buffer.append("\u001b[00m");
153     }
154     if (content!=null)
155     {
156       buffer.append(" \u001b[00;31m{");
157       buffer.append(content.length);
158       buffer.append("}\u001b[00m");
159     }
160     if (text!=null)
161     {
162       buffer.append(" \u001b[00;33m");
163       buffer.append(text);
164       buffer.append("\u001b[00m");
165     }
166     return buffer.toString();
167   }
168
169 }
170
Popular Tags