/[classpathx]/mail/source/javax/mail/search/RecipientStringTerm.java
ViewVC logotype

Contents of /mail/source/javax/mail/search/RecipientStringTerm.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Thu Dec 9 17:22:13 2004 UTC (19 years, 5 months ago) by dog
Branch: MAIN
Changes since 1.6: +13 -13 lines
2004-12-08  Chris Burdess  <dog@bluezoo.org>

        * Makefile.am: Fixed relative META-INF.
        * all: Reformatted according to GNU Classpath guidelines.

1 /*
2 * RecipientStringTerm.java
3 * Copyright(C) 2002 The Free Software Foundation
4 *
5 * This file is part of GNU JavaMail, a library.
6 *
7 * GNU JavaMail is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 *(at your option) any later version.
11 *
12 * GNU JavaMail is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * As a special exception, if you link this library with other files to
22 * produce an executable, this library does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * This exception does not however invalidate any other reasons why the
25 * executable file might be covered by the GNU General Public License.
26 */
27
28 package javax.mail.search;
29
30 import javax.mail.Address;
31 import javax.mail.Message;
32
33 /**
34 * This class implements string comparisons for the Recipient Address headers.
35 * <p>
36 * Note that this class differs from the RecipientTerm class in that this
37 * class does comparisons on address strings rather than Address objects.
38 * The string comparisons are case-insensitive.
39 *
40 * @author <a href="mailto:dog@gnu.org">Chris Burdess</a>
41 * @version 1.3
42 */
43 public final class RecipientStringTerm
44 extends AddressStringTerm
45 {
46
47 /**
48 * The recipient type.
49 */
50 protected Message.RecipientType type;
51
52 /**
53 * Constructor.
54 * @param type the recipient type
55 * @param address the address pattern to be compared.
56 */
57 public RecipientStringTerm(Message.RecipientType type, String pattern)
58 {
59 super(pattern);
60 this.type = type;
61 }
62
63 /**
64 * Return the type of recipient to match with.
65 */
66 public Message.RecipientType getRecipientType()
67 {
68 return type;
69 }
70
71 /**
72 * Check whether the address specified in the constructor is a substring of
73 * the recipient address of this Message.
74 * @param msg The comparison is applied to this Message's recepient address.
75 * @return true if the match succeeds, otherwise false.
76 */
77 public boolean match(Message msg)
78 {
79 try
80 {
81 Address[] addresses = msg.getRecipients(type);
82 if (addresses != null)
83 {
84 for (int i = 0; i < addresses.length; i++)
85 {
86 if (super.match(addresses[i]))
87 {
88 return true;
89 }
90 }
91 }
92 }
93 catch (Exception e)
94 {
95 }
96 return false;
97 }
98
99 /**
100 * Equality comparison.
101 */
102 public boolean equals(Object other)
103 {
104 return (other instanceof RecipientStringTerm &&
105 ((RecipientStringTerm) other).type.equals(type) &&
106 super.equals(other));
107 }
108
109 /**
110 * Compute a hashCode for this object.
111 */
112 public int hashCode()
113 {
114 return type.hashCode() + super.hashCode();
115 }
116
117 }

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26