Skip to content

Package: FromStringTerm

FromStringTerm

nameinstructionbranchcomplexitylinemethod
FromStringTerm(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: 29 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: import jakarta.mail.Address;
21:
22: /**
23: * This class implements string comparisons for the From Address
24: * header. <p>
25: *
26: * Note that this class differs from the <code>FromTerm</code> class
27: * in that this class does comparisons on address strings rather than Address
28: * objects. The string comparisons are case-insensitive.
29: *
30: * @since JavaMail 1.1
31: */
32:
33: public final class FromStringTerm extends AddressStringTerm {
34:
35: private static final long serialVersionUID = 5801127523826772788L;
36:
37: /**
38: * Constructor.
39: *
40: * @param pattern the address pattern to be compared.
41: */
42: public FromStringTerm(String pattern) {
43:         super(pattern);
44: }
45:
46: /**
47: * Check whether the address string specified in the constructor is
48: * a substring of the From address of this Message.
49: *
50: * @param msg         The comparison is applied to this Message's From
51: *                         address.
52: * @return true if the match succeeds, otherwise false.
53: */
54: @Override
55: public boolean match(Message msg) {
56:         Address[] from;
57:
58:         try {
59:          from = msg.getFrom();
60:         } catch (Exception e) {
61:          return false;
62:         }
63:
64:•        if (from == null)
65:          return false;
66:         
67:•        for (int i=0; i < from.length; i++)
68:•         if (super.match(from[i]))
69:                 return true;
70:         return false;
71: }
72:
73: /**
74: * Equality comparison.
75: */
76: @Override
77: public boolean equals(Object obj) {
78:•        if (!(obj instanceof FromStringTerm))
79:          return false;
80:         return super.equals(obj);
81: }
82: }