1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.geronimo.javamail.store.imap.connection;
19
20 import java.util.List;
21
22 import javax.mail.MessagingException;
23
24 /**
25 * Utility class to aggregate status responses for a mailbox.
26 */
27 public class IMAPStatusResponse extends IMAPUntaggedResponse {
28 // the mail box name
29 public String mailbox;
30 // number of messages in the box
31 public int messages = -1;
32 // number of recent messages
33 public int recentMessages = -1;
34 // the number of unseen messages
35 public int unseenMessages = -1;
36 // the next UID for this mailbox
37 public long uidNext = -1L;
38 // the UID validity item
39 public long uidValidity = -1L;
40
41 public IMAPStatusResponse(byte[] data, IMAPResponseTokenizer source) throws MessagingException {
42 super("STATUS", data);
43
44 // the mail box name is supposed to be encoded, so decode it now.
45 mailbox = source.readEncodedString();
46
47 // parse the list of flag values
48 List flags = source.readStringList();
49
50 for (int i = 0; i < flags.size(); i += 2) {
51 String field = ((String)flags.get(i)).toUpperCase();
52 String stringValue = ((String)flags.get(i + 1));
53 long value;
54 try {
55 value = Long.parseLong(stringValue);
56 } catch (NumberFormatException e) {
57 throw new MessagingException("Invalid IMAP Status response", e);
58 }
59
60
61 if (field.equals("MESSAGES")) {
62 messages = (int)value;
63 }
64 else if (field.equals("RECENT")) {
65 recentMessages = (int)value;
66 }
67 else if (field.equals("UIDNEXT")) {
68 uidNext = value;
69 }
70 else if (field.equals("UIDVALIDITY")) {
71 uidValidity = value;
72 }
73 else if (field.equals("UNSEEN")) {
74 unseenMessages = (int)value;
75 }
76 }
77 }
78 }
79