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. import javax.mail.Address;
  8. /**
  9. * This class implements comparisons for the From Address header.
  10. *
  11. * @author Bill Shannon
  12. * @author John Mani
  13. */
  14. public final class FromTerm extends AddressTerm {
  15. /**
  16. * Constructor
  17. * @param address The Address to be compared
  18. */
  19. public FromTerm(Address address) {
  20. super(address);
  21. }
  22. /**
  23. * The address comparator.
  24. *
  25. * @param msg The address comparison is applied to this Message
  26. * @return true if the comparison succeeds, otherwise false
  27. */
  28. public boolean match(Message msg) {
  29. Address[] from;
  30. try {
  31. from = msg.getFrom();
  32. } catch (Exception e) {
  33. return false;
  34. }
  35. if (from == null)
  36. return false;
  37. for (int i=0; i < from.length; i++)
  38. if (super.match(from[i]))
  39. return true;
  40. return false;
  41. }
  42. /**
  43. * Equality comparison.
  44. */
  45. public boolean equals(Object obj) {
  46. if (!(obj instanceof FromTerm))
  47. return false;
  48. return super.equals(obj);
  49. }
  50. }