Skip to content

Package: MessageCountEvent

MessageCountEvent

nameinstructionbranchcomplexitylinemethod
MessageCountEvent(Folder, int, boolean, Message[])
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
dispatch(Object)
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%
getMessages()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getType()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isRemoved()
M: 3 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 jakarta.mail.event;
18:
19: import jakarta.mail.Folder;
20: import jakarta.mail.Message;
21:
22: /**
23: * This class notifies changes in the number of messages in a folder. <p>
24: *
25: * Note that some folder types may only deliver MessageCountEvents at
26: * certain times or after certain operations. IMAP in particular will
27: * only notify the client of MessageCountEvents when a client issues a
28: * new command. Refer to
29: * <A HREF="http://www.ietf.org/rfc/rfc3501.txt" TARGET="_top">RFC 3501</A>
30: * for details.
31: * A client may want to "poll" the folder by occasionally calling the
32: * {@link jakarta.mail.Folder#getMessageCount getMessageCount} or
33: * {@link jakarta.mail.Folder#isOpen isOpen} methods
34: * to solicit any such notifications.
35: *
36: * @author John Mani
37: */
38:
39: public class MessageCountEvent extends MailEvent {
40:
41: /**
42: * The messages were added to their folder
43: */
44: public static final int ADDED = 1;
45: /**
46: * The messages were removed from their folder
47: */
48: public static final int REMOVED = 2;
49:
50: /**
51: * The event type.
52: *
53: * @serial
54: */
55: protected int type;
56:
57: /**
58: * If true, this event is the result of an explicit
59: * expunge by this client, and the messages in this
60: * folder have been renumbered to account for this.
61: * If false, this event is the result of an expunge
62: * by external sources.
63: *
64: * @serial
65: */
66: protected boolean removed;
67:
68: /**
69: * The messages.
70: */
71: transient protected Message[] msgs;
72:
73: private static final long serialVersionUID = -7447022340837897369L;
74:
75: /**
76: * Constructor.
77: *
78: * @param folder The containing folder
79: * @param type The event type
80: * @param removed If true, this event is the result of an explicit
81: * expunge by this client, and the messages in this
82: * folder have been renumbered to account for this.
83: * If false, this event is the result of an expunge
84: * by external sources.
85: * @param msgs The messages added/removed
86: */
87: public MessageCountEvent(Folder folder, int type,
88: boolean removed, Message[] msgs) {
89: super(folder);
90: this.type = type;
91: this.removed = removed;
92: this.msgs = msgs;
93: }
94:
95: /**
96: * Return the type of this event.
97: *
98: * @return type
99: */
100: public int getType() {
101: return type;
102: }
103:
104: /**
105: * Indicates whether this event is the result of an explicit
106: * expunge by this client, or due to an expunge from external
107: * sources. If <code>true</code>, this event is due to an
108: * explicit expunge and hence all remaining messages in this
109: * folder have been renumbered. If <code>false</code>, this event
110: * is due to an external expunge. <p>
111: *
112: * Note that this method is valid only if the type of this event
113: * is <code>REMOVED</code>
114: *
115: * @return true if the message has been removed
116: */
117: public boolean isRemoved() {
118: return removed;
119: }
120:
121: /**
122: * Return the array of messages added or removed.
123: *
124: * @return array of messages
125: */
126: public Message[] getMessages() {
127: return msgs;
128: }
129:
130: /**
131: * Invokes the appropriate MessageCountListener method.
132: */
133: @Override
134: public void dispatch(Object listener) {
135:• if (type == ADDED)
136: ((MessageCountListener) listener).messagesAdded(this);
137: else // REMOVED
138: ((MessageCountListener) listener).messagesRemoved(this);
139: }
140: }