Skip to contentMethod: match(Message)
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.search;
18:
19: import jakarta.mail.Address;
20: import jakarta.mail.Message;
21:
22: /**
23: * This class implements comparisons for the From Address header.
24: *
25: * @author Bill Shannon
26: * @author John Mani
27: */
28: public final class FromTerm extends AddressTerm {
29:
30: private static final long serialVersionUID = 5214730291502658665L;
31:
32: /**
33: * Constructor
34: *
35: * @param address The Address to be compared
36: */
37: public FromTerm(Address address) {
38: super(address);
39: }
40:
41: /**
42: * The address comparator.
43: *
44: * @param msg The address comparison is applied to this Message
45: * @return true if the comparison succeeds, otherwise false
46: */
47: @Override
48: public boolean match(Message msg) {
49: Address[] from;
50:
51: try {
52: from = msg.getFrom();
53: } catch (Exception e) {
54: return false;
55: }
56:
57:• if (from == null)
58: return false;
59:
60:• for (int i = 0; i < from.length; i++)
61:• if (super.match(from[i]))
62: return true;
63: return false;
64: }
65:
66: /**
67: * Equality comparison.
68: */
69: @Override
70: public boolean equals(Object obj) {
71: if (!(obj instanceof FromTerm))
72: return false;
73: return super.equals(obj);
74: }
75: }