Skip to content

Package: Status

Status

nameinstructionbranchcomplexitylinemethod
Status(Response)
M: 167 C: 0
0%
M: 30 C: 0
0%
M: 16 C: 0
0%
M: 44 C: 0
0%
M: 1 C: 0
0%
add(Status, Status)
M: 68 C: 0
0%
M: 16 C: 0
0%
M: 9 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
getItem(String)
M: 73 C: 0
0%
M: 16 C: 0
0%
M: 9 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 24 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package org.eclipse.angus.mail.imap.protocol;
18:
19: import java.util.Map;
20: import java.util.HashMap;
21: import java.util.Locale;
22:
23: import org.eclipse.angus.mail.iap.*;
24: import org.eclipse.angus.mail.iap.ParsingException;
25: import org.eclipse.angus.mail.iap.Response;
26:
27: /**
28: * STATUS response.
29: *
30: * @author John Mani
31: * @author Bill Shannon
32: */
33:
34: public class Status {
35: public String mbox = null;
36: public int total = -1;
37: public int recent = -1;
38: public long uidnext = -1;
39: public long uidvalidity = -1;
40: public int unseen = -1;
41: public long highestmodseq = -1;
42: public Map<String,Long> items;        // any unknown items
43:
44: static final String[] standardItems =
45:         { "MESSAGES", "RECENT", "UNSEEN", "UIDNEXT", "UIDVALIDITY" };
46:
47: public Status(Response r) throws ParsingException {
48:         // mailbox := astring
49:         mbox = r.readAtomString();
50:•        if (!r.supportsUtf8())
51:          mbox = BASE64MailboxDecoder.decode(mbox);
52:
53:         // Workaround buggy IMAP servers that don't quote folder names
54:         // with spaces.
55:         final StringBuilder buffer = new StringBuilder();
56:         boolean onlySpaces = true;
57:
58:•        while (r.peekByte() != '(' && r.peekByte() != 0) {
59:          final char next = (char)r.readByte();
60:
61:          buffer.append(next);
62:
63:•         if (next != ' ') {
64:                 onlySpaces = false;
65:          }
66:         }
67:
68:•        if (!onlySpaces) {
69:          mbox = (mbox + buffer).trim();
70:         }
71:
72:•        if (r.readByte() != '(')
73:          throw new ParsingException("parse error in STATUS");
74:         
75:         do {
76:          String attr = r.readAtom();
77:•         if (attr == null)
78:                 throw new ParsingException("parse error in STATUS");
79:•         if (attr.equalsIgnoreCase("MESSAGES"))
80:                 total = r.readNumber();
81:•         else if (attr.equalsIgnoreCase("RECENT"))
82:                 recent = r.readNumber();
83:•         else if (attr.equalsIgnoreCase("UIDNEXT"))
84:                 uidnext = r.readLong();
85:•         else if (attr.equalsIgnoreCase("UIDVALIDITY"))
86:                 uidvalidity = r.readLong();
87:•         else if (attr.equalsIgnoreCase("UNSEEN"))
88:                 unseen = r.readNumber();
89:•         else if (attr.equalsIgnoreCase("HIGHESTMODSEQ"))
90:                 highestmodseq = r.readLong();
91:          else {
92:•                if (items == null)
93:                  items = new HashMap<>();
94:                 items.put(attr.toUpperCase(Locale.ENGLISH),
95:                          Long.valueOf(r.readLong()));
96:          }
97:•        } while (!r.isNextNonSpace(')'));
98: }
99:
100: /**
101: * Get the value for the STATUS item.
102: *
103: * @param        item        the STATUS item
104: * @return                the value
105: * @since        JavaMail 1.5.2
106: */
107: public long getItem(String item) {
108:         item = item.toUpperCase(Locale.ENGLISH);
109:         Long v;
110:         long ret = -1;
111:•        if (items != null && (v = items.get(item)) != null)
112:          ret = v.longValue();
113:•        else if (item.equals("MESSAGES"))
114:          ret = total;
115:•        else if (item.equals("RECENT"))
116:          ret = recent;
117:•        else if (item.equals("UIDNEXT"))
118:          ret = uidnext;
119:•        else if (item.equals("UIDVALIDITY"))
120:          ret = uidvalidity;
121:•        else if (item.equals("UNSEEN"))
122:          ret = unseen;
123:•        else if (item.equals("HIGHESTMODSEQ"))
124:          ret = highestmodseq;
125:         return ret;
126: }
127:
128: public static void add(Status s1, Status s2) {
129:•        if (s2.total != -1)
130:          s1.total = s2.total;
131:•        if (s2.recent != -1)
132:          s1.recent = s2.recent;
133:•        if (s2.uidnext != -1)
134:          s1.uidnext = s2.uidnext;
135:•        if (s2.uidvalidity != -1)
136:          s1.uidvalidity = s2.uidvalidity;
137:•        if (s2.unseen != -1)
138:          s1.unseen = s2.unseen;
139:•        if (s2.highestmodseq != -1)
140:          s1.highestmodseq = s2.highestmodseq;
141:•        if (s1.items == null)
142:          s1.items = s2.items;
143:•        else if (s2.items != null)
144:          s1.items.putAll(s2.items);
145: }
146: }