001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: /*
038: * @(#)AddressStringTerm.java 1.10 07/05/04
039: */
040:
041: package javax.mail.search;
042:
043: import javax.mail.Message;
044: import javax.mail.Address;
045: import javax.mail.internet.InternetAddress;
046:
047: /**
048: * This abstract class implements string comparisons for Message
049: * addresses. <p>
050: *
051: * Note that this class differs from the <code>AddressTerm</code> class
052: * in that this class does comparisons on address strings rather than
053: * Address objects.
054: *
055: * @since JavaMail 1.1
056: */
057:
058: public abstract class AddressStringTerm extends StringTerm {
059:
060: private static final long serialVersionUID = 3086821234204980368L;
061:
062: /**
063: * Constructor.
064: *
065: * @param pattern the address pattern to be compared.
066: */
067: protected AddressStringTerm(String pattern) {
068: super (pattern, true); // we need case-insensitive comparison.
069: }
070:
071: /**
072: * Check whether the address pattern specified in the constructor is
073: * a substring of the string representation of the given Address
074: * object. <p>
075: *
076: * Note that if the string representation of the given Address object
077: * contains charset or transfer encodings, the encodings must be
078: * accounted for, during the match process. <p>
079: *
080: * @param a The comparison is applied to this Address object.
081: * @return true if the match succeeds, otherwise false.
082: */
083: protected boolean match(Address a) {
084: if (a instanceof InternetAddress) {
085: InternetAddress ia = (InternetAddress) a;
086: // We dont use toString() to get "a"'s String representation,
087: // because InternetAddress.toString() returns a RFC 2047
088: // encoded string, which isn't what we need here.
089:
090: return super .match(ia.toUnicodeString());
091: } else
092: return super .match(a.toString());
093: }
094:
095: /**
096: * Equality comparison.
097: */
098: public boolean equals(Object obj) {
099: if (!(obj instanceof AddressStringTerm))
100: return false;
101: return super.equals(obj);
102: }
103: }
|