Skip to content

Package: MessageIDTerm

MessageIDTerm

nameinstructionbranchcomplexitylinemethod
MessageIDTerm(String)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
equals(Object)
M: 2 C: 7
78%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 2
67%
M: 0 C: 1
100%
match(Message)
M: 30 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2021 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.search;
18:
19: import jakarta.mail.Message;
20:
21: /**
22: * This term models the RFC822 "MessageId" - a message-id for
23: * Internet messages that is supposed to be unique per message.
24: * Clients can use this term to search a folder for a message given
25: * its MessageId. <p>
26: *
27: * The MessageId is represented as a String.
28: *
29: * @author Bill Shannon
30: * @author John Mani
31: */
32: public final class MessageIDTerm extends StringTerm {
33:
34: private static final long serialVersionUID = -2121096296454691963L;
35:
36: /**
37: * Constructor.
38: *
39: * @param msgid the msgid to search for
40: */
41: public MessageIDTerm(String msgid) {
42:         // Note: comparison is case-insensitive
43:         super(msgid);
44: }
45:
46: /**
47: * The match method.
48: *
49: * @param msg        the match is applied to this Message's
50: *                        Message-ID header
51: * @return                true if the match succeeds, otherwise false
52: */
53: @Override
54: public boolean match(Message msg) {
55:         String[] s;
56:
57:         try {
58:          s = msg.getHeader("Message-ID");
59:         } catch (Exception e) {
60:          return false;
61:         }
62:
63:•        if (s == null)
64:          return false;
65:
66:•        for (int i=0; i < s.length; i++)
67:•         if (super.match(s[i]))
68:                 return true;
69:         return false;
70: }
71:
72: /**
73: * Equality comparison.
74: */
75: @Override
76: public boolean equals(Object obj) {
77:•        if (!(obj instanceof MessageIDTerm))
78:          return false;
79:         return super.equals(obj);
80: }
81: }