KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > ristretto > imap > IMAPFlags


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is Ristretto Mail API.
15  *
16  * The Initial Developers of the Original Code are
17  * Timo Stich and Frederik Dietz.
18  * Portions created by the Initial Developers are Copyright (C) 2004
19  * All Rights Reserved.
20  *
21  * Contributor(s):
22  *
23  * Alternatively, the contents of this file may be used under the terms of
24  * either the GNU General Public License Version 2 or later (the "GPL"), or
25  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26  * in which case the provisions of the GPL or the LGPL are applicable instead
27  * of those above. If you wish to allow use of your version of this file only
28  * under the terms of either the GPL or the LGPL, and not to allow others to
29  * use your version of this file under the terms of the MPL, indicate your
30  * decision by deleting the provisions above and replace them with the notice
31  * and other provisions required by the GPL or the LGPL. If you do not delete
32  * the provisions above, a recipient may use your version of this file under
33  * the terms of any one of the MPL, the GPL or the LGPL.
34  *
35  * ***** END LICENSE BLOCK ***** */

36 package org.columba.ristretto.imap;
37
38 import java.io.IOException JavaDoc;
39 import java.io.ObjectInputStream JavaDoc;
40
41 import org.columba.ristretto.message.Flags;
42
43 /**
44  * Extends the Flags with JUNK and UID from IMAP.
45  *
46  * <br>
47  * <b>RFC(s):</b> 3105
48  *
49  * @author Timo Stich <tstich@users.sourceforge.net>
50  */

51 public class IMAPFlags extends Flags {
52     
53     /**
54      * Flag used on some IMAP servers for SPAM messages.
55      *
56      */

57     public static final short JUNK = 0x0100;
58     
59     private Object JavaDoc uid;
60     private int index;
61     
62
63     /**
64      * Constructs the IMAPFlags.
65      *
66      */

67     public IMAPFlags() {
68         super();
69     }
70
71     /**
72      * Constructs a new IMAPFlags Object with the given flags
73      *
74      * @param flags
75      */

76     public IMAPFlags(short flags) {
77         super(flags);
78     }
79
80     /**
81      * Contructs a new IMAPFlags Object that can be read from the ObjectInputStream
82      *
83      * @param in The ObjectInputStream to read from
84      * @throws IOException
85      */

86     public IMAPFlags(ObjectInputStream JavaDoc in) throws IOException JavaDoc {
87         super(in);
88     }
89
90     /**
91      * Gets the UID.
92      *
93      * @return the UID or <code>null</code> if no UID was associated.
94      */

95     public Object JavaDoc getUid() {
96         return uid;
97     }
98
99     /**
100      * Sets the UID.
101      *
102      * @param object The UID from the imap-server
103      */

104     public void setUid(Object JavaDoc object) {
105         uid = object;
106     }
107
108     
109     /**
110      * Sets the JUNK flag.
111      *
112      * @param b the value of the JUNK flag.
113      */

114     public void setJunk(boolean b) {
115         set(JUNK,b);
116     }
117     
118     /**
119      * Gets the JUNK flag.
120      *
121      * @return the value of the JUNK flag.
122      */

123     public boolean getJunk() {
124         return get(JUNK);
125     }
126     
127     
128     /**
129      * @see org.columba.ristretto.message.Flags#toString()
130      */

131     public String JavaDoc toString() {
132         boolean first = true;
133         StringBuffer JavaDoc result = new StringBuffer JavaDoc("(");
134         
135         if( getAnswered()) {
136             result.append("\\Answered");
137             first = false;
138         }
139         
140         if( getFlagged()) {
141             if( !first ) result.append(" ");
142             first = false;
143             result.append("\\Flagged");
144         }
145         
146         if( getDeleted()) {
147             if( !first ) result.append(" ");
148             first = false;
149             result.append("\\Deleted");
150         }
151
152         if( getSeen()) {
153             if( !first ) result.append(" ");
154             first = false;
155             result.append("\\Seen");
156         }
157         
158         if( getDraft()) {
159             if( !first ) result.append(" ");
160             first = false;
161             result.append("\\Draft");
162         }
163         
164         /* Recent is only allowed when fetching thus we should never render it
165         if( getRecent()) {
166             result.append(" \\Recent");
167         }
168         */

169         
170         // JUNK is only allowed in a STORE command !
171
if( this.get(JUNK)) {
172             if( !first ) result.append(" ");
173             first = false;
174             result.append("JUNK");
175         }
176         
177         result.append(")");
178         
179         return result.toString();
180
181     }
182     /**
183      * @return Returns the index.
184      */

185     public int getIndex() {
186         return index;
187     }
188     /**
189      * @param index The index to set.
190      */

191     public void setIndex(int index) {
192         this.index = index;
193     }
194 }
195
Popular Tags