Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

javax.mail
Class Folder  view Folder download Folder.java

java.lang.Object
  extended byjavax.mail.Folder
Direct Known Subclasses:
SimpleFolder

public abstract class Folder
extends java.lang.Object

An abstract representation of a folder in a mail system; subclasses would implement Folders for each supported protocol.

Depending on protocol and implementation, folders may contain other folders, messages, or both as indicated by the HOLDS_FOLDERS 55 and HOLDS_MESSAGES 55 flags. If the immplementation supports hierarchical folders, the format of folder names is implementation dependent; however, components of the name are separated by the delimiter character returned by getSeparator() 55 .

The case-insensitive folder name "INBOX" is reserved to refer to the primary folder for the current user on the current server; not all stores will provide an INBOX and it may not be available at all times.

Version:
$Rev: 126350 $ $Date: 2005-01-24 22:35:47 -0800 (Mon, 24 Jan 2005) $

Field Summary
private  java.util.List connectionListeners
           
private  java.util.List folderListeners
           
static int HOLDS_FOLDERS
          Flag that indicates that a folder can contain other folders.
static int HOLDS_MESSAGES
          Flag that indicates that a folder can contain messages.
private  java.util.List messageChangedListeners
           
private  java.util.List messageCountListeners
           
protected  int mode
          The current mode of this folder.
private  EventQueue queue
           
static int READ_ONLY
          Flag indicating that this folder cannot be modified.
static int READ_WRITE
          Flag indictaing that this folder can be modified.
protected  Store store
          The store that this folder is part of.
 
Constructor Summary
protected Folder(Store store)
          Constructor that initializes the Store.
 
Method Summary
 void addConnectionListener(javax.mail.event.ConnectionListener listener)
           
 void addFolderListener(javax.mail.event.FolderListener listener)
           
 void addMessageChangedListener(javax.mail.event.MessageChangedListener listener)
           
 void addMessageCountListener(javax.mail.event.MessageCountListener listener)
           
abstract  void appendMessages(Message[] messages)
          Append the supplied messages to this folder.
abstract  void close(boolean expunge)
          Close this folder; it must already be open.
 void copyMessages(Message[] messages, Folder folder)
          Copy the specified messages to another folder.
abstract  boolean create(int type)
          Create a new folder capable of containing subfoldera and/or messages as determined by the type parameter.
abstract  boolean delete(boolean recurse)
          Delete this folder and possibly any subfolders.
abstract  boolean exists()
          Check to see if this folder physically exists in the store.
abstract  Message[] expunge()
          Permanently delete all supplied messages that have the DELETED flag set from the Store.
 void fetch(Message[] messages, FetchProfile profile)
          Hint to the store to prefetch information on the supplied messaged.
protected  void finalize()
          Unregisters all listeners.
private  int getCount(Flags.Flag flag, boolean value)
           
 int getDeletedMessageCount()
          Return the numbew of messages in this folder that have the Flag.DELETED flag set.
abstract  Folder getFolder(java.lang.String name)
          Get the Folder determined by the supplied name; if the name is relative then it is interpreted relative to this folder.
abstract  java.lang.String getFullName()
          Return the full absolute name of this folder.
abstract  Message getMessage(int index)
          Retrieve the message with the specified index in this Folder; messages indices start at 1 not zero.
abstract  int getMessageCount()
          Return the number of messages this folder contains.
 Message[] getMessages()
          Retrieve all messages.
 Message[] getMessages(int[] ids)
          Retrieve messages with the specified indices.
 Message[] getMessages(int start, int end)
          Retrieve messages with index between start and end inclusive
 int getMode()
          Return the mode of this folder ass passed to open(int) 55 , or -1 if the folder is closed.
abstract  java.lang.String getName()
          Return the name of this folder.
 int getNewMessageCount()
          Return the numbew of messages in this folder that have the Flag.RECENT flag set.
abstract  Folder getParent()
          Return the parent for this folder; if the folder is at the root of a heirarchy this returns null.
abstract  Flags getPermanentFlags()
          Get the flags supported by this folder.
abstract  char getSeparator()
          Return the character used by this folder's Store to separate path components.
 Store getStore()
          Return the store that this folder is part of.
abstract  int getType()
          Return the type of this folder, indicating whether it can contain subfolders, messages, or both.
 int getUnreadMessageCount()
          Return the numbew of messages in this folder that do not have the Flag.SEEN flag set.
 URLName getURLName()
          Return the URLName for this folder, which includes the location of the store.
abstract  boolean hasNewMessages()
          Check to see if this Folder conatins messages with the Flag.RECENT flag set.
abstract  boolean isOpen()
          Indicates that the folder has been opened.
 boolean isSubscribed()
          Determine if the user is subscribed to this Folder.
 Folder[] list()
          Convenience method that invokes list(String) 55 with the pattern "%".
abstract  Folder[] list(java.lang.String pattern)
          Return a list of folders from this Folder's namespace that match the supplied pattern.
 Folder[] listSubscribed()
          Convenience method that invokes listSubscribed(String) 55 with the pattern "%".
 Folder[] listSubscribed(java.lang.String pattern)
          Return a list of folders to which the user is subscribed and which match the supplied pattern.
protected  void notifyConnectionListeners(int type)
           
protected  void notifyFolderListeners(int type)
           
protected  void notifyFolderRenamedListeners(Folder newFolder)
           
protected  void notifyMessageAddedListeners(Message[] messages)
           
protected  void notifyMessageChangedListeners(int type, Message message)
           
protected  void notifyMessageRemovedListeners(boolean removed, Message[] messages)
           
abstract  void open(int mode)
          Open this folder; the folder must be able to contain messages and must currently be closed.
 void removeConnectionListener(javax.mail.event.ConnectionListener listener)
           
 void removeFolderListener(javax.mail.event.FolderListener listener)
           
 void removeMessageChangedListener(javax.mail.event.MessageChangedListener listener)
           
 void removeMessageCountListener(javax.mail.event.MessageCountListener listener)
           
abstract  boolean renameTo(Folder newName)
          Rename this folder; the folder must be closed.
 Message[] search(javax.mail.search.SearchTerm term)
          Search this folder for messages matching the supplied search criteria.
 Message[] search(javax.mail.search.SearchTerm term, Message[] messages)
          Search the supplied messages for those that match the supplied criteria; messages must belong to this folder.
 void setFlags(int[] ids, Flags flags, boolean value)
          Set flags on a set of messages to the supplied value.
 void setFlags(int start, int end, Flags flags, boolean value)
          Set flags on a range of messages to the supplied value.
 void setFlags(Message[] messages, Flags flags, boolean value)
          Set flags on the messages to the supplied value; all messages must belong to this folder.
 void setSubscribed(boolean subscribed)
          Set the user's subscription to this folder.
 java.lang.String toString()
          Returns the full name of this folder; if null, returns the value from the superclass.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HOLDS_MESSAGES

public static final int HOLDS_MESSAGES
Flag that indicates that a folder can contain messages.

See Also:
Constant Field Values

HOLDS_FOLDERS

public static final int HOLDS_FOLDERS
Flag that indicates that a folder can contain other folders.

See Also:
Constant Field Values

READ_ONLY

public static final int READ_ONLY
Flag indicating that this folder cannot be modified.

See Also:
Constant Field Values

READ_WRITE

public static final int READ_WRITE
Flag indictaing that this folder can be modified. Question: what does it mean if both are set?

See Also:
Constant Field Values

store

protected Store store
The store that this folder is part of.


mode

protected int mode
The current mode of this folder. When open, this can be READ_ONLY 55 or READ_WRITE 55 ; otherwise is set to -1.


connectionListeners

private final java.util.List connectionListeners

folderListeners

private final java.util.List folderListeners

messageChangedListeners

private final java.util.List messageChangedListeners

messageCountListeners

private final java.util.List messageCountListeners

queue

private final EventQueue queue
Constructor Detail

Folder

protected Folder(Store store)
Constructor that initializes the Store.

Method Detail

getName

public abstract java.lang.String getName()
Return the name of this folder. This can be invoked when the folder is closed.


getFullName

public abstract java.lang.String getFullName()
Return the full absolute name of this folder. This can be invoked when the folder is closed.


getURLName

public URLName getURLName()
                   throws MessagingException
Return the URLName for this folder, which includes the location of the store.


getStore

public Store getStore()
Return the store that this folder is part of.


getParent

public abstract Folder getParent()
                          throws MessagingException
Return the parent for this folder; if the folder is at the root of a heirarchy this returns null. This can be invoked when the folder is closed.


exists

public abstract boolean exists()
                        throws MessagingException
Check to see if this folder physically exists in the store. This can be invoked when the folder is closed.


list

public abstract Folder[] list(java.lang.String pattern)
                       throws MessagingException
Return a list of folders from this Folder's namespace that match the supplied pattern. Patterns may contain the following wildcards:
  • '%' which matches any characater except hierarchy delimiters
  • '*' which matches any character including hierarchy delimiters
This can be invoked when the folder is closed.


listSubscribed

public Folder[] listSubscribed(java.lang.String pattern)
                        throws MessagingException
Return a list of folders to which the user is subscribed and which match the supplied pattern. If the store does not support the concept of subscription then this should match against all folders; the default implementation of this method achieves this by defaulting to the list(String) 55 method.


list

public Folder[] list()
              throws MessagingException
Convenience method that invokes list(String) 55 with the pattern "%".


listSubscribed

public Folder[] listSubscribed()
                        throws MessagingException
Convenience method that invokes listSubscribed(String) 55 with the pattern "%".


getSeparator

public abstract char getSeparator()
                           throws MessagingException
Return the character used by this folder's Store to separate path components.


getType

public abstract int getType()
                     throws MessagingException
Return the type of this folder, indicating whether it can contain subfolders, messages, or both. The value returned is a bitmask with the appropriate bits set.


create

public abstract boolean create(int type)
                        throws MessagingException
Create a new folder capable of containing subfoldera and/or messages as determined by the type parameter. Any hierarchy defined by the folder name will be recursively created. If the folder was sucessfully created, a CREATED FolderEvent 55 is sent to all FolderListeners registered with this Folder or with the Store.


isSubscribed

public boolean isSubscribed()
Determine if the user is subscribed to this Folder. The default implementation in this class always returns true.


setSubscribed

public void setSubscribed(boolean subscribed)
                   throws MessagingException
Set the user's subscription to this folder. Not all Stores support subscription; the default implementation in this class always throws a MethodNotSupportedException


hasNewMessages

public abstract boolean hasNewMessages()
                                throws MessagingException
Check to see if this Folder conatins messages with the Flag.RECENT flag set. This can be used when the folder is closed to perform a light-weight check for new mail; to perform an incremental check for new mail the folder must be opened.


getFolder

public abstract Folder getFolder(java.lang.String name)
                          throws MessagingException
Get the Folder determined by the supplied name; if the name is relative then it is interpreted relative to this folder. This does not check that the named folder actually exists.


delete

public abstract boolean delete(boolean recurse)
                        throws MessagingException
Delete this folder and possibly any subfolders. This operation can only be performed on a closed folder. If recurse is true, then all subfolders are deleted first, then any messages in this folder are removed and it is finally deleted; FolderEvent.DELETED>FolderEvent.DELETED 55 events are sent as appropriate. If recurse is false, then the behaviour depends on the folder type and store implementation as followd:
  • If the folder can only conrain messages, then all messages are removed and then the folder is deleted; a FolderEvent.DELETED>FolderEvent.DELETED 55 event is sent.
  • If the folder can onlu contain subfolders, then if it is empty it will be deleted and a FolderEvent.DELETED>FolderEvent.DELETED 55 event is sent; if the folder is not empty then the delete fails and this method returns false.
  • If the folder can contain both subfolders and messages, then if the folder does not contain any subfolders, any messages are deleted, the folder itself is deleted and a FolderEvent.DELETED>FolderEvent.DELETED 55 event is sent; if the folder does contain subfolders then the implementation may choose from the following three behaviors:
    1. it may return false indicting the operation failed
    2. it may remove all messages within the folder, send a FolderEvent.DELETED>FolderEvent.DELETED 55 event, and then return true to indicate the delete was performed. Note this does not delete the folder itself and the exists() 55 operation for this folder will return true
    3. it may remove all messages within the folder as per the previous option; in addition it may change the type of the Folder to only HOLDS_FOLDERS indictaing that messages may no longer be added
FolderEvents are sent to all listeners registered with this folder or with the Store.


renameTo

public abstract boolean renameTo(Folder newName)
                          throws MessagingException
Rename this folder; the folder must be closed. If the rename is successfull, a FolderEvent.RENAMED>FolderEvent.RENAMED 55 event is sent to all listeners registered with this folder or with the store.


open

public abstract void open(int mode)
                   throws MessagingException
Open this folder; the folder must be able to contain messages and must currently be closed. If the folder is opened successfully then a ConnectionEvent.OPENED>ConnectionEvent.OPENED 55 event is sent to listeners registered with this Folder.

Whether the Store allows multiple connections or if it allows multiple writers is implementation defined.


close

public abstract void close(boolean expunge)
                    throws MessagingException
Close this folder; it must already be open. A ConnectionEvent.CLOSED>ConnectionEvent.CLOSED 55 event is sent to all listeners registered with this folder.


isOpen

public abstract boolean isOpen()
Indicates that the folder has been opened.


getMode

public int getMode()
Return the mode of this folder ass passed to open(int) 55 , or -1 if the folder is closed.


getPermanentFlags

public abstract Flags getPermanentFlags()
Get the flags supported by this folder.


getMessageCount

public abstract int getMessageCount()
                             throws MessagingException
Return the number of messages this folder contains. If this operation is invoked on a closed folder, the implementation may choose to return -1 to avoid the expense of opening the folder.


getNewMessageCount

public int getNewMessageCount()
                       throws MessagingException
Return the numbew of messages in this folder that have the Flag.RECENT flag set. If this operation is invoked on a closed folder, the implementation may choose to return -1 to avoid the expense of opening the folder. The default implmentation of this method iterates over all messages in the folder; subclasses should override if possible to provide a more efficient implementation.


getUnreadMessageCount

public int getUnreadMessageCount()
                          throws MessagingException
Return the numbew of messages in this folder that do not have the Flag.SEEN flag set. If this operation is invoked on a closed folder, the implementation may choose to return -1 to avoid the expense of opening the folder. The default implmentation of this method iterates over all messages in the folder; subclasses should override if possible to provide a more efficient implementation.


getDeletedMessageCount

public int getDeletedMessageCount()
                           throws MessagingException
Return the numbew of messages in this folder that have the Flag.DELETED flag set. If this operation is invoked on a closed folder, the implementation may choose to return -1 to avoid the expense of opening the folder. The default implmentation of this method iterates over all messages in the folder; subclasses should override if possible to provide a more efficient implementation.


getCount

private int getCount(Flags.Flag flag,
                     boolean value)
              throws MessagingException

getMessage

public abstract Message getMessage(int index)
                            throws MessagingException
Retrieve the message with the specified index in this Folder; messages indices start at 1 not zero. Clients should note that the index for a specific message may change if the folder is expunged; Message objects should be used as references instead.


getMessages

public Message[] getMessages(int start,
                             int end)
                      throws MessagingException
Retrieve messages with index between start and end inclusive


getMessages

public Message[] getMessages(int[] ids)
                      throws MessagingException
Retrieve messages with the specified indices.


getMessages

public Message[] getMessages()
                      throws MessagingException
Retrieve all messages.


appendMessages

public abstract void appendMessages(Message[] messages)
                             throws MessagingException
Append the supplied messages to this folder. A javax.mail.event.MessageCountEvent is sent to all listeners registered with this folder when all messages have been appended. If the array contains a previously expunged message, it must be re-appended to the Store and implementations must not abort this operation.


fetch

public void fetch(Message[] messages,
                  FetchProfile profile)
           throws MessagingException
Hint to the store to prefetch information on the supplied messaged. Subclasses should override this method to provide an efficient implementation; the default implementation in this class simply returns.


setFlags

public void setFlags(Message[] messages,
                     Flags flags,
                     boolean value)
              throws MessagingException
Set flags on the messages to the supplied value; all messages must belong to this folder. This method may be overridden by subclasses that can optimize the setting of flags on multiple messages at once; the default implementation simply calls Message.setFlags(Flags, boolean) 55 for each supplied messages.


setFlags

public void setFlags(int start,
                     int end,
                     Flags flags,
                     boolean value)
              throws MessagingException
Set flags on a range of messages to the supplied value. This method may be overridden by subclasses that can optimize the setting of flags on multiple messages at once; the default implementation simply gets each message and then calls Message.setFlags(Flags, boolean) 55 .


setFlags

public void setFlags(int[] ids,
                     Flags flags,
                     boolean value)
              throws MessagingException
Set flags on a set of messages to the supplied value. This method may be overridden by subclasses that can optimize the setting of flags on multiple messages at once; the default implementation simply gets each message and then calls Message.setFlags(Flags, boolean) 55 .


copyMessages

public void copyMessages(Message[] messages,
                         Folder folder)
                  throws MessagingException
Copy the specified messages to another folder. The default implementation simply appends the supplied messages to the target folder using appendMessages(Message[]) 55 .


expunge

public abstract Message[] expunge()
                           throws MessagingException
Permanently delete all supplied messages that have the DELETED flag set from the Store. The original message indices of all messages actually deleted are returned and a javax.mail.event.MessageCountEvent event is sent to all listeners with this folder. The expunge may cause the indices of all messaged that remain in the folder to change.


search

public Message[] search(javax.mail.search.SearchTerm term)
                 throws MessagingException
Search this folder for messages matching the supplied search criteria. The default implementation simply invoke search(term, getMessages()) applying the search over all messages in the folder; subclasses may provide a more efficient mechanism.


search

public Message[] search(javax.mail.search.SearchTerm term,
                        Message[] messages)
                 throws MessagingException
Search the supplied messages for those that match the supplied criteria; messages must belong to this folder. The default implementation iterates through the messages, returning those whose Message.match(javax.mail.search.SearchTerm) 55 method returns true; subclasses may provide a more efficient implementation.


addConnectionListener

public void addConnectionListener(javax.mail.event.ConnectionListener listener)

removeConnectionListener

public void removeConnectionListener(javax.mail.event.ConnectionListener listener)

notifyConnectionListeners

protected void notifyConnectionListeners(int type)

addFolderListener

public void addFolderListener(javax.mail.event.FolderListener listener)

removeFolderListener

public void removeFolderListener(javax.mail.event.FolderListener listener)

notifyFolderListeners

protected void notifyFolderListeners(int type)

notifyFolderRenamedListeners

protected void notifyFolderRenamedListeners(Folder newFolder)

addMessageCountListener

public void addMessageCountListener(javax.mail.event.MessageCountListener listener)

removeMessageCountListener

public void removeMessageCountListener(javax.mail.event.MessageCountListener listener)

notifyMessageAddedListeners

protected void notifyMessageAddedListeners(Message[] messages)

notifyMessageRemovedListeners

protected void notifyMessageRemovedListeners(boolean removed,
                                             Message[] messages)

addMessageChangedListener

public void addMessageChangedListener(javax.mail.event.MessageChangedListener listener)

removeMessageChangedListener

public void removeMessageChangedListener(javax.mail.event.MessageChangedListener listener)

notifyMessageChangedListeners

protected void notifyMessageChangedListeners(int type,
                                             Message message)

finalize

protected void finalize()
                 throws java.lang.Throwable
Unregisters all listeners.


toString

public java.lang.String toString()
Returns the full name of this folder; if null, returns the value from the superclass.