KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > mail > search > FromTerm


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21
22 /*
23  * @(#)FromTerm.java 1.8 05/08/29
24  *
25  * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
26  */

27
28 package javax.mail.search;
29
30 import javax.mail.Message JavaDoc;
31 import javax.mail.Address JavaDoc;
32
33 /**
34  * This class implements comparisons for the From Address header.
35  *
36  * @author Bill Shannon
37  * @author John Mani
38  */

39 public final class FromTerm extends AddressTerm JavaDoc {
40
41     private static final long serialVersionUID = 5214730291502658665L;
42
43     /**
44      * Constructor
45      * @param address The Address to be compared
46      */

47     public FromTerm(Address JavaDoc address) {
48     super(address);
49     }
50
51     /**
52      * The address comparator.
53      *
54      * @param msg The address comparison is applied to this Message
55      * @return true if the comparison succeeds, otherwise false
56      */

57     public boolean match(Message JavaDoc msg) {
58     Address JavaDoc[] from;
59
60     try {
61         from = msg.getFrom();
62     } catch (Exception JavaDoc e) {
63         return false;
64     }
65
66     if (from == null)
67         return false;
68
69     for (int i=0; i < from.length; i++)
70         if (super.match(from[i]))
71         return true;
72     return false;
73     }
74
75     /**
76      * Equality comparison.
77      */

78     public boolean equals(Object JavaDoc obj) {
79     if (!(obj instanceof FromTerm JavaDoc))
80         return false;
81     return super.equals(obj);
82     }
83 }
84
Popular Tags