KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > mail > imap > protocol > MailboxInfo


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21
22 /*
23  * @(#)MailboxInfo.java 1.9 05/08/29
24  *
25  * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
26  */

27
28 package com.sun.mail.imap.protocol;
29
30 import javax.mail.Flags JavaDoc;
31 import com.sun.mail.iap.*;
32
33 /**
34  * This class
35  *
36  * @version 1.9, 05/08/29
37  * @author John Mani
38  */

39
40 public class MailboxInfo {
41     public Flags JavaDoc availableFlags = null;
42     public Flags JavaDoc permanentFlags = null;
43     public int total = -1;
44     public int recent = -1;
45     public int first = -1;
46     public int uidvalidity = -1;
47     public int uidnext = -1;
48     public int mode;
49
50     public MailboxInfo(Response[] r) throws ParsingException {
51     for (int i = 0; i < r.length; i++) {
52         if (r[i] == null || !(r[i] instanceof IMAPResponse))
53         continue;
54
55         IMAPResponse ir = (IMAPResponse)r[i];
56
57         if (ir.keyEquals("EXISTS")) {
58         total = ir.getNumber();
59         r[i] = null; // remove this response
60
}
61         else if (ir.keyEquals("RECENT")) {
62         recent = ir.getNumber();
63         r[i] = null; // remove this response
64
}
65         else if (ir.keyEquals("FLAGS")) {
66         availableFlags = new FLAGS(ir);
67         r[i] = null; // remove this response
68
}
69         else if (ir.isUnTagged() && ir.isOK()) {
70         /* should be one of:
71             * OK [UNSEEN 12]
72             * OK [UIDVALIDITY 3857529045]
73             * OK [PERMANENTFLAGS (\Deleted)]
74             * OK [UIDNEXT 44]
75         */

76         ir.skipSpaces();
77
78         if (ir.readByte() != '[') { // huh ???
79
ir.reset();
80             continue;
81         }
82
83         boolean handled = true;
84         String JavaDoc s = ir.readAtom();
85         if (s.equalsIgnoreCase("UNSEEN"))
86             first = ir.readNumber();
87         else if (s.equalsIgnoreCase("UIDVALIDITY"))
88             uidvalidity = ir.readNumber();
89         else if (s.equalsIgnoreCase("PERMANENTFLAGS"))
90             permanentFlags = new FLAGS(ir);
91         else if (s.equalsIgnoreCase("UIDNEXT"))
92             uidnext = ir.readNumber();
93         else
94             handled = false; // possibly an ALERT
95

96         if (handled)
97             r[i] = null; // remove this response
98
else
99             ir.reset(); // so ALERT can be read
100
}
101     }
102
103     /*
104      * The PERMANENTFLAGS response code is optional, and if
105      * not present implies that all flags in the required FLAGS
106      * response can be changed permanently.
107      */

108     if (permanentFlags == null) {
109         if (availableFlags != null)
110         permanentFlags = new Flags JavaDoc(availableFlags);
111         else
112         permanentFlags = new Flags JavaDoc();
113     }
114     }
115 }
116
Popular Tags