Skip to content

Package: AddressStringTerm

AddressStringTerm

nameinstructionbranchcomplexitylinemethod
AddressStringTerm(String)
M: 0 C: 5
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(Address)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 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: import jakarta.mail.Address;
21: import jakarta.mail.internet.InternetAddress;
22:
23: /**
24: * This abstract class implements string comparisons for Message
25: * addresses. <p>
26: *
27: * Note that this class differs from the <code>AddressTerm</code> class
28: * in that this class does comparisons on address strings rather than
29: * Address objects.
30: *
31: * @since JavaMail 1.1
32: */
33:
34: public abstract class AddressStringTerm extends StringTerm {
35:
36: private static final long serialVersionUID = 3086821234204980368L;
37:
38: /**
39: * Constructor.
40: *
41: * @param pattern the address pattern to be compared.
42: */
43: protected AddressStringTerm(String pattern) {
44:         super(pattern, true); // we need case-insensitive comparison.
45: }
46:
47: /**
48: * Check whether the address pattern specified in the constructor is
49: * a substring of the string representation of the given Address
50: * object. <p>
51: *
52: * Note that if the string representation of the given Address object
53: * contains charset or transfer encodings, the encodings must be
54: * accounted for, during the match process. <p>
55: *
56: * @param a         The comparison is applied to this Address object.
57: * @return true if the match succeeds, otherwise false.
58: */
59: protected boolean match(Address a) {
60:•        if (a instanceof InternetAddress) {
61:          InternetAddress ia = (InternetAddress)a;
62:          // We dont use toString() to get "a"'s String representation,
63:          // because InternetAddress.toString() returns a RFC 2047
64:          // encoded string, which isn't what we need here.
65:
66:          return super.match(ia.toUnicodeString());
67:         } else
68:          return super.match(a.toString());
69: }
70:
71: /**
72: * Equality comparison.
73: */
74: @Override
75: public boolean equals(Object obj) {
76:•        if (!(obj instanceof AddressStringTerm))
77:          return false;
78:         return super.equals(obj);
79: }
80: }