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;
  6. import java.util.NoSuchElementException;
  7. /**
  8. * The <code>UIDFolder</code> interface is implemented by Folders
  9. * that can support the "disconnected" mode of operation, by providing
  10. * unique-ids for messages in the folder. This interface is based on
  11. * the IMAP model for supporting disconnected operation. <p>
  12. *
  13. * A Unique identifier (UID) is a positive long value, assigned to
  14. * each message in a specific folder. Unique identifiers are assigned
  15. * in a strictly <strong>ascending</strong> fashion in the mailbox.
  16. * That is, as each message is added to the mailbox it is assigned a
  17. * higher UID than the message(s) which were added previously. Unique
  18. * identifiers persist across sessions. This permits a client to
  19. * resynchronize its state from a previous session with the server. <p>
  20. *
  21. * Associated with every mailbox is a unique identifier validity value.
  22. * If unique identifiers from an earlier session fail to persist to
  23. * this session, the unique identifier validity value
  24. * <strong>must</strong> be greater than the one used in the earlier
  25. * session. <p>
  26. *
  27. * Refer to RFC 2060 <A HREF="http://www.ietf.org/rfc/rfc2060.txt">
  28. * http://www.ietf.org/rfc/rfc2060.txt</A> for more information.
  29. *
  30. * @author John Mani
  31. */
  32. public interface UIDFolder {
  33. /**
  34. * A fetch profile item for fetching UIDs.
  35. * This inner class extends the <code>FetchProfile.Item</code>
  36. * class to add new FetchProfile item types, specific to UIDFolders.
  37. * The only item currently defined here is the <code>UID</code> item.
  38. *
  39. * @see FetchProfile
  40. */
  41. public static class FetchProfileItem extends FetchProfile.Item {
  42. protected FetchProfileItem(String name) {
  43. super(name);
  44. }
  45. /**
  46. * UID is a fetch profile item that can be included in a
  47. * <code>FetchProfile</code> during a fetch request to a Folder.
  48. * This item indicates that the UIDs for messages in the specified
  49. * range are desired to be prefetched. <p>
  50. *
  51. * An example of how a client uses this is below: <p>
  52. * <blockquote><pre>
  53. *
  54. * FetchProfile fp = new FetchProfile();
  55. * fp.add(UIDFolder.FetchProfileItem.UID);
  56. * folder.fetch(msgs, fp);
  57. *
  58. * </pre></blockquote><p>
  59. */
  60. public static final FetchProfileItem UID =
  61. new FetchProfileItem("UID");
  62. }
  63. /**
  64. * This is a special value that can be used as the <code>end</code>
  65. * parameter in <code>getMessages(start, end)</code>, to denote the
  66. * last UID in this folder.
  67. *
  68. * @see #getMessagesByUID
  69. */
  70. public final static long LASTUID = -1;
  71. /**
  72. * Returns the UIDValidity value associated with this folder. <p>
  73. *
  74. * Clients typically compare this value against a UIDValidity
  75. * value saved from a previous session to insure that any cached
  76. * UIDs not stale.
  77. *
  78. * @return UIDValidity
  79. */
  80. public long getUIDValidity() throws MessagingException;
  81. /**
  82. * Get the Message corresponding to the given UID. If no such
  83. * message exists, <code>null</code> is returned.
  84. *
  85. * @param uid UID for the desired message
  86. * @return the Message object. <code>null</code> is returned
  87. * if no message corresponding to this UID is obtained.
  88. * @exception MessagingException
  89. */
  90. public Message getMessageByUID(long uid) throws MessagingException;
  91. /**
  92. * Get the Messages specified by the given range. The special
  93. * value LASTUID can be used for the <code>end</code> parameter
  94. * to indicate the last available UID.
  95. *
  96. * @param start start UID
  97. * @param end end UID
  98. * @return array of Message objects
  99. * @exception MessagingException
  100. * @see #LASTUID
  101. */
  102. public Message[] getMessagesByUID(long start, long end)
  103. throws MessagingException;
  104. /**
  105. * Get the Messages specified by the given array of UIDs. If any UID is
  106. * invalid, <code>null</code> is returned for that entry. <p>
  107. *
  108. * Note that the returned array will be of the same size as the specified
  109. * array of UIDs, and <code>null</code> entries may be present in the
  110. * array to indicate invalid UIDs.
  111. *
  112. * @param uids array of UIDs
  113. * @return array of Message objects
  114. * @exception MessagingException
  115. */
  116. public Message[] getMessagesByUID(long[] uids)
  117. throws MessagingException;
  118. /**
  119. * Get the UID for the specified message. Note that the message
  120. * <strong>must</strong> belong to this folder. Else the
  121. * java.util.NoSuchElementException is thrown.
  122. *
  123. * @param message Message from this folder
  124. * @return UID for this message
  125. * @exception NoSuchElementException if the given Message
  126. * is not in this Folder.
  127. */
  128. public long getUID(Message message) throws MessagingException;
  129. }