View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package javax.mail;
21  
22  /**
23   * @version $Rev: 582797 $ $Date: 2007-10-08 08:29:12 -0400 (Mon, 08 Oct 2007) $
24   */
25  public interface UIDFolder {
26      /**
27       * A special value than can be passed as the <code>end</code> parameter to
28       * {@link Folder#getMessages(int, int)} to indicate the last message in this folder.
29       */
30      public static final long LASTUID = -1;
31  
32      /**
33       * Get the UID validity value for this Folder.
34       * 
35       * @return The current UID validity value, as a long. 
36       * @exception MessagingException
37       */
38      public abstract long getUIDValidity() throws MessagingException;
39  
40      /**
41       * Retrieve a message using the UID rather than the 
42       * message sequence number.  Returns null if the message
43       * doesn't exist.
44       * 
45       * @param uid    The target UID.
46       * 
47       * @return the Message object.  Returns null if the message does
48       *         not exist.
49       * @exception MessagingException
50       */
51      public abstract Message getMessageByUID(long uid)
52              throws MessagingException;
53  
54      /**
55       * Get a series of messages using a UID range.  The 
56       * special value LASTUID can be used to mark the 
57       * last available message.
58       * 
59       * @param start  The start of the UID range.
60       * @param end    The end of the UID range.  The special value
61       *               LASTUID can be used to request all messages up
62       *               to the last UID.
63       * 
64       * @return An array containing all of the messages in the 
65       *         range.
66       * @exception MessagingException
67       */
68      public abstract Message[] getMessagesByUID(long start, long end)
69              throws MessagingException;
70  
71      /**
72       * Retrieve a set of messages by explicit UIDs.  If 
73       * any message in the list does not exist, null 
74       * will be returned for the corresponding item.
75       * 
76       * @param ids    An array of UID values to be retrieved.
77       * 
78       * @return An array of Message items the same size as the ids
79       *         argument array.  This array will contain null
80       *         entries for any UIDs that do not exist.
81       * @exception MessagingException
82       */
83      public abstract Message[] getMessagesByUID(long[] ids)
84              throws MessagingException;
85  
86      /**
87       * Retrieve the UID for a message from this Folder.
88       * The argument Message MUST belong to this Folder
89       * instance, otherwise a NoSuchElementException will 
90       * be thrown.
91       * 
92       * @param message The target message.
93       * 
94       * @return The UID associated with this message.
95       * @exception MessagingException
96       */
97      public abstract long getUID(Message message) throws MessagingException;
98  
99      /**
100      * Special profile item used for fetching UID information.
101      */
102     public static class FetchProfileItem extends FetchProfile.Item {
103         public static final FetchProfileItem UID = new FetchProfileItem("UID");
104 
105         protected FetchProfileItem(String name) {
106             super(name);
107         }
108     }
109 }