1. /*
  2. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. package javax.mail.search;
  6. import javax.mail.Message;
  7. /**
  8. * This class implements comparisons for the Message Subject header.
  9. * The comparison is case-insensitive.
  10. *
  11. * @author Bill Shannon
  12. * @author John Mani
  13. */
  14. public final class SubjectTerm extends StringTerm {
  15. /**
  16. * Constructor.
  17. *
  18. * @param pattern the pattern to search for
  19. */
  20. public SubjectTerm(String pattern) {
  21. // Note: comparison is case-insensitive
  22. super(pattern);
  23. }
  24. /**
  25. * The match method.
  26. *
  27. * @param msg the pattern match is applied to this Message's
  28. * subject header
  29. * @return true if the pattern match succeeds, otherwise false
  30. */
  31. public boolean match(Message msg) {
  32. String subj;
  33. try {
  34. subj = msg.getSubject();
  35. } catch (Exception e) {
  36. return false;
  37. }
  38. if (subj == null)
  39. return false;
  40. return super.match(subj);
  41. }
  42. /**
  43. * Equality comparison.
  44. */
  45. public boolean equals(Object obj) {
  46. if (!(obj instanceof SubjectTerm))
  47. return false;
  48. return super.equals(obj);
  49. }
  50. }