Skip to content

Package: GmailMessage

GmailMessage

nameinstructionbranchcomplexitylinemethod
GmailMessage(IMAPFolder, int)
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%
GmailMessage(Session)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
clearCachedLabels()
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getLabels()
M: 14 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getMsgId()
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getThrId()
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
setLabels(String[], boolean)
M: 49 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 13 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.util.*;
22: import org.eclipse.angus.mail.iap.*;
23: import org.eclipse.angus.mail.imap.*;
24: import org.eclipse.angus.mail.imap.protocol.*;
25: import org.eclipse.angus.mail.gimap.protocol.*;
26: import org.eclipse.angus.mail.gimap.protocol.GmailProtocol;
27:
28: /**
29: * A Gmail message. Adds methods to access Gmail-specific per-message data.
30: *
31: * @since JavaMail 1.4.6
32: * @author Bill Shannon
33: */
34:
35: public class GmailMessage extends IMAPMessage {
36: /**
37: * Constructor.
38: *
39: * @param        folder        the containing folder
40: * @param        msgnum        the message sequence number
41: */
42: protected GmailMessage(IMAPFolder folder, int msgnum) {
43:         super(folder, msgnum);
44: }
45:
46: /**
47: * Constructor, for use by IMAPNestedMessage.
48: *
49: * @param        session        the Session
50: */
51: protected GmailMessage(Session session) {
52:         super(session);
53: }
54:
55: /**
56: * Return the Gmail unique message ID.
57: *
58: * @return        the message ID
59: * @exception        MessagingException for failures
60: */
61: public long getMsgId() throws MessagingException {
62:         Long msgid = (Long)getItem(GmailProtocol.MSGID_ITEM);
63:•        if (msgid != null)
64:          return msgid.longValue();
65:         else
66:          return -1;
67: }
68:
69: /**
70: * Return the Gmail unique thread ID.
71: *
72: * @return        the thread ID
73: * @exception        MessagingException for failures
74: */
75: public long getThrId() throws MessagingException {
76:         Long thrid = (Long)getItem(GmailProtocol.THRID_ITEM);
77:•        if (thrid != null)
78:          return thrid.longValue();
79:         else
80:          return -1;
81: }
82:
83: /**
84: * Return the Gmail labels associated with this message.
85: *
86: * @return        array of labels, or empty array if none
87: * @exception        MessagingException for failures
88: */
89: public String[] getLabels() throws MessagingException {
90:         String[] labels = (String[])getItem(GmailProtocol.LABELS_ITEM);
91:•        if (labels != null)
92:          return (String[])(labels.clone());
93:         else
94:          return new String[0];
95: }
96:
97: /**
98: * Set/Unset the given labels on this message.
99: *
100: * @param        labels        the labels to add or remove
101: * @param        set        true to add labels, false to remove
102: * @exception        MessagingException for failures
103: * @since JavaMail 1.5.5
104: */
105: public synchronized void setLabels(String[] labels, boolean set)
106:                         throws MessagingException {
107: // Acquire MessageCacheLock, to freeze seqnum.
108: synchronized(getMessageCacheLock()) {
109:          try {
110:                 IMAPProtocol ip = getProtocol();
111:•                assert ip instanceof GmailProtocol;
112:                 GmailProtocol p = (GmailProtocol)ip;
113:                 checkExpunged(); // Insure that this message is not expunged
114:                 p.storeLabels(getSequenceNumber(), labels, set);
115:          } catch (ConnectionException cex) {
116:                 throw new FolderClosedException(folder, cex.getMessage());
117:          } catch (ProtocolException pex) {
118:                 throw new MessagingException(pex.getMessage(), pex);
119:          }
120:         }
121: }
122:
123: /**
124: * Clear any cached labels for this message.
125: * The Gmail labels for a messge will be cached when first accessed
126: * using either the fetch method or the getLabels method. Gmail provides
127: * no notification when the labels have been changed by another application
128: * so applications may need to clear the cache if accessing the labels for
129: * a message more than once while the Folder is open.
130: *
131: * @since JavaMail 1.5.6
132: */
133: public synchronized void clearCachedLabels() {
134:•        if (items != null)
135:          items.remove(GmailProtocol.LABELS_ITEM.getName());
136: }
137: }