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 term models the RFC822 "MessageId" - a message-id for
  9. * Internet messages that is supposed to be unique per message.
  10. * Clients can use this term to search a folder for a message given
  11. * its MessageId. <p>
  12. *
  13. * The MessageId is represented as a String.
  14. *
  15. * @author Bill Shannon
  16. * @author John Mani
  17. */
  18. public final class MessageIDTerm extends StringTerm {
  19. /**
  20. * Constructor.
  21. *
  22. * @param msgid the msgid to search for
  23. */
  24. public MessageIDTerm(String msgid) {
  25. // Note: comparison is case-insensitive
  26. super(msgid);
  27. }
  28. /**
  29. * The match method.
  30. *
  31. * @param msg the match is applied to this Message's
  32. * Message-ID header
  33. * @return true if the match succeeds, otherwise false
  34. */
  35. public boolean match(Message msg) {
  36. String[] s;
  37. try {
  38. s = msg.getHeader("Message-ID");
  39. } catch (Exception e) {
  40. return false;
  41. }
  42. if (s == null)
  43. return false;
  44. for (int i=0; i < s.length; i++)
  45. if (super.match(s[i]))
  46. return true;
  47. return false;
  48. }
  49. /**
  50. * Equality comparison.
  51. */
  52. public boolean equals(Object obj) {
  53. if (!(obj instanceof MessageIDTerm))
  54. return false;
  55. return super.equals(obj);
  56. }
  57. }