Skip to content

Package: GmailFolder

GmailFolder

nameinstructionbranchcomplexitylinemethod
GmailFolder(ListInfo, IMAPStore)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
GmailFolder(String, char, IMAPStore, Boolean)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
newIMAPMessage(int)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setLabels(Message[], String[], boolean)
M: 62 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 18 C: 0
0%
M: 1 C: 0
0%
setLabels(int, int, String[], boolean)
M: 31 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
setLabels(int[], String[], boolean)
M: 28 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 1 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.gimap;
18:
19: import jakarta.mail.*;
20:
21: import org.eclipse.angus.mail.iap.*;
22: import org.eclipse.angus.mail.imap.*;
23: import org.eclipse.angus.mail.imap.protocol.*;
24: import org.eclipse.angus.mail.gimap.protocol.*;
25: import org.eclipse.angus.mail.gimap.protocol.GmailProtocol;
26:
27: /**
28: * A Gmail folder. Defines new FetchProfile items and
29: * uses GmailMessage to store additional Gmail message attributes.
30: *
31: * @since JavaMail 1.4.6
32: * @author Bill Shannon
33: */
34:
35: public class GmailFolder extends IMAPFolder {
36: /**
37: * A fetch profile item for fetching headers.
38: * This inner class extends the <code>FetchProfile.Item</code>
39: * class to add new FetchProfile item types, specific to Gmail.
40: *
41: * @see FetchProfile
42: */
43: public static class FetchProfileItem extends FetchProfile.Item {
44:         protected FetchProfileItem(String name) {
45:          super(name);
46:         }
47:
48:         /**
49:          * MSGID is a fetch profile item that can be included in a
50:          * <code>FetchProfile</code> during a fetch request to a Folder.
51:          * This item indicates that the Gmail unique message ID for messages
52:          * in the specified range are desired to be prefetched. <p>
53:          *
54:          * An example of how a client uses this is below:
55:          * <blockquote><pre>
56:          *
57:          *         FetchProfile fp = new FetchProfile();
58:          *        fp.add(GmailFolder.FetchProfileItem.MSGID);
59:          *        folder.fetch(msgs, fp);
60:          *
61:          * </pre></blockquote>
62:          */
63:         public static final FetchProfileItem MSGID =
64:                 new FetchProfileItem("X-GM-MSGID");
65:
66:         /**
67:          * THRID is a fetch profile item that can be included in a
68:          * <code>FetchProfile</code> during a fetch request to a Folder.
69:          * This item indicates that the Gmail unique thread ID for messages
70:          * in the specified range are desired to be prefetched. <p>
71:          *
72:          * An example of how a client uses this is below:
73:          * <blockquote><pre>
74:          *
75:          *         FetchProfile fp = new FetchProfile();
76:          *        fp.add(GmailFolder.FetchProfileItem.THRID);
77:          *        folder.fetch(msgs, fp);
78:          *
79:          * </pre></blockquote>
80:          */
81:         public static final FetchProfileItem THRID =
82:                 new FetchProfileItem("X-GM-THRID");
83:
84:         /**
85:          * LABELS is a fetch profile item that can be included in a
86:          * <code>FetchProfile</code> during a fetch request to a Folder.
87:          * This item indicates that the Gmail labels for messages
88:          * in the specified range are desired to be prefetched. <p>
89:          *
90:          * An example of how a client uses this is below:
91:          * <blockquote><pre>
92:          *
93:          *         FetchProfile fp = new FetchProfile();
94:          *        fp.add(GmailFolder.FetchProfileItem.LABELS);
95:          *        folder.fetch(msgs, fp);
96:          *
97:          * </pre></blockquote>
98:          */
99:         public static final FetchProfileItem LABELS =
100:                 new FetchProfileItem("X-GM-LABELS");
101: }
102:
103: /**
104: * Set the specified labels for the given array of messages.
105: *
106: * @param        msgs        the messages
107: * @param        labels        the labels to add or remove
108: * @param        set        true to add, false to remove
109: * @exception        MessagingException        for failures
110: * @since        JavaMail 1.5.5
111: */
112: public synchronized void setLabels(Message[] msgs,
113:                                 String[] labels, boolean set)
114:                                 throws MessagingException {
115:         checkOpened();
116:
117:•        if (msgs.length == 0) // boundary condition
118:          return;
119:
120:         synchronized(messageCacheLock) {
121:          try {
122:                 IMAPProtocol ip = getProtocol();
123:•                assert ip instanceof GmailProtocol;
124:                 GmailProtocol p = (GmailProtocol)ip;
125:                 MessageSet[] ms = Utility.toMessageSetSorted(msgs, null);
126:•                if (ms == null)
127:                  throw new MessageRemovedException(
128:                                         "Messages have been removed");
129:                 p.storeLabels(ms, labels, set);
130:          } catch (ConnectionException cex) {
131:                 throw new FolderClosedException(this, cex.getMessage());
132:          } catch (ProtocolException pex) {
133:                 throw new MessagingException(pex.getMessage(), pex);
134:          }
135:         }
136: }
137:
138: /**
139: * Set the specified labels for the given range of message numbers.
140: *
141: * @param        start        first message number
142: * @param        end        last message number
143: * @param        labels        the labels to add or remove
144: * @param        set        true to add, false to remove
145: * @exception        MessagingException        for failures
146: * @since        JavaMail 1.5.5
147: */
148: public synchronized void setLabels(int start, int end,
149:                                 String[] labels, boolean set)
150:                                 throws MessagingException {
151:         checkOpened();
152:         Message[] msgs = new Message[end - start + 1];
153:         int i = 0;
154:•        for (int n = start; n <= end; n++)
155:          msgs[i++] = getMessage(n);
156:         setLabels(msgs, labels, set);
157: }
158:
159: /**
160: * Set the specified labels for the given array of message numbers.
161: *
162: * @param        msgnums        the message numbers
163: * @param        labels        the labels to add or remove
164: * @param        set        true to add, false to remove
165: * @exception        MessagingException        for failures
166: * @since        JavaMail 1.5.5
167: */
168: public synchronized void setLabels(int[] msgnums,
169:                                 String[] labels, boolean set)
170:                                 throws MessagingException {
171:         checkOpened();
172:         Message[] msgs = new Message[msgnums.length];
173:•        for (int i = 0; i < msgnums.length; i++)
174:          msgs[i] = getMessage(msgnums[i]);
175:         setLabels(msgs, labels, set);
176: }
177:
178: /**
179: * Constructor used to create a possibly non-existent folder.
180: *
181: * @param fullName        fullname of this folder
182: * @param separator the default separator character for this
183: *                        folder's namespace
184: * @param store        the Store
185: * @param isNamespace does this name represent a namespace?
186: */
187: protected GmailFolder(String fullName, char separator, IMAPStore store,
188:                                 Boolean isNamespace) {
189:         super(fullName, separator, store, isNamespace);
190: }
191:
192: /**
193: * Constructor used to create an existing folder.
194: *
195: * @param        li        the ListInfo for this folder
196: * @param        store        the store containing this folder
197: */
198: protected GmailFolder(ListInfo li, IMAPStore store) {
199:         super(li, store);
200: }
201:
202: /**
203: * Create a new IMAPMessage object to represent the given message number.
204: */
205: protected IMAPMessage newIMAPMessage(int msgnum) {
206:         return new GmailMessage(this, msgnum);
207: }
208: }