public abstract class Folder
extends java.lang.Object
Folder names are implementation dependent; the hierarchy components in a folder's full name are separated by the folder's ancestors' hierarchy delimiter characters.
The special (case-insensitive) folder name INBOX is reserved to mean the primary folder for the authenticated user in the store. Not all stores support INBOX folders, and not all users will have an INBOX folder.
Unless documented otherwise, a folder must be opened in order to invoke a method on it.
Modifier and Type | Field and Description |
---|---|
static int |
HOLDS_FOLDERS
This folder can contain other folders.
|
static int |
HOLDS_MESSAGES
This folder can contain messages.
|
protected int |
mode
The folder mode: Folder.READ_ONLY, Folder.READ_WRITE, or -1 if not known.
|
static int |
READ_ONLY
This folder is read only.
|
static int |
READ_WRITE
This folder can be modified.
|
protected Store |
store
The parent store.
|
Modifier | Constructor and Description |
---|---|
protected |
Folder(Store store)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addConnectionListener(ConnectionListener l)
Add a listener for connection events on this folder.
|
void |
addFolderListener(FolderListener l)
Add a listener for folder events on this folder.
|
void |
addMessageChangedListener(MessageChangedListener l)
Add a listener for message changed events on this folder.
|
void |
addMessageCountListener(MessageCountListener l)
Add a listener for message count events on this folder.
|
abstract void |
appendMessages(Message[] msgs)
Appends the specified messages to this folder.
|
abstract void |
close(boolean expunge)
Closes this folder.
|
void |
copyMessages(Message[] msgs,
Folder folder)
Copies the specified messages into another folder.
|
abstract boolean |
create(int type)
Create this folder in the store.
|
abstract boolean |
delete(boolean recurse)
Deletes this folder.
|
abstract boolean |
exists()
Indicates whether this folder exists in the Store.
|
abstract Message[] |
expunge()
Expunges (permanently removing) all the messages marked DELETED.
|
void |
fetch(Message[] msgs,
FetchProfile fp)
Fetches the items specified in the given fetch profile for the specified
messages.
|
int |
getDeletedMessageCount()
Returns the number of deleted messages in this folder.
|
abstract Folder |
getFolder(java.lang.String name)
Return a folder corresponding to the given name.
|
abstract java.lang.String |
getFullName()
Returns the full name of this folder.
|
abstract Message |
getMessage(int msgnum)
Returns the message with the given number.
|
abstract int |
getMessageCount()
Returns the number of messages in this folder.
|
Message[] |
getMessages()
Returns all messages in this folder.
|
Message[] |
getMessages(int[] msgnums)
Returns the messages for the specified message numbers.
|
Message[] |
getMessages(int start,
int end)
Returns the messages in the given range (inclusive).
|
int |
getMode()
Return the mode this folder is open in.
|
abstract java.lang.String |
getName()
Returns the name of this folder.
|
int |
getNewMessageCount()
Returns the number of new messages in this folder.
|
abstract Folder |
getParent()
Returns the parent folder of this folder, or
null
if this folder is the root of a folder hierarchy. |
abstract Flags |
getPermanentFlags()
Returns the permanent flags supported by this folder.
|
abstract char |
getSeparator()
Return the hierarchy delimiter character for this folder.
|
Store |
getStore()
Returns the parent store.
|
abstract int |
getType()
Returns the type of this Folder, i.e.
|
int |
getUnreadMessageCount()
Returns the number of unread messages in this folder.
|
URLName |
getURLName()
Return a URLName that can be used as a handle to access this folder.
|
abstract boolean |
hasNewMessages()
Indicates whether this folder has new messages.
|
abstract boolean |
isOpen()
Indicates whether this folder is open.
|
boolean |
isSubscribed()
Indicates whether this folder is subscribed.
|
Folder[] |
list()
Returns the list of subfolders of this folder.
|
abstract Folder[] |
list(java.lang.String pattern)
Returns a list of subfolders matching the specified pattern.
|
Folder[] |
listSubscribed()
Returns the list of subscribed subfolders of this folder.
|
Folder[] |
listSubscribed(java.lang.String pattern)
Returns a list of subscribed subfolders matching the specified pattern.
|
protected void |
notifyConnectionListeners(int type)
Notify all connection listeners.
|
protected void |
notifyFolderListeners(int type)
Notify all folder listeners registered on this Folder and
this folder's store.
|
protected void |
notifyFolderRenamedListeners(Folder folder)
Notify all folder listeners registered on this folder and
this folder's store about the renaming of this folder.
|
protected void |
notifyMessageAddedListeners(Message[] msgs)
Notify all message count listeners about the addition of messages
into this folder.
|
protected void |
notifyMessageChangedListeners(int type,
Message msg)
Notify all message changed event listeners.
|
protected void |
notifyMessageRemovedListeners(boolean removed,
Message[] msgs)
Notify all message count listeners about the removal of messages from
this folder.
|
abstract void |
open(int mode)
Opens this folder.
|
void |
removeConnectionListener(ConnectionListener l)
Remove a connection event listener.
|
void |
removeFolderListener(FolderListener l)
Remove a folder event listener.
|
void |
removeMessageChangedListener(MessageChangedListener l)
Remove a message changed event listener.
|
void |
removeMessageCountListener(MessageCountListener l)
Remove a message count event listener.
|
abstract boolean |
renameTo(Folder folder)
Renames this folder.
|
Message[] |
search(SearchTerm term)
Searches this folder for messages matching the specified search term.
|
Message[] |
search(SearchTerm term,
Message[] msgs)
Searches the given messages for those matching the specified search
term.
|
void |
setFlags(int[] msgnums,
Flags flag,
boolean value)
Sets the specified flags on each of the specified messages.
|
void |
setFlags(int start,
int end,
Flags flag,
boolean value)
Set the specified flags on the given range of messages (inclusive).
|
void |
setFlags(Message[] msgs,
Flags flag,
boolean value)
Sets the specified flags on each specified message.
|
void |
setSubscribed(boolean flag)
Subscribe to or unsubscribe from this folder.
|
java.lang.String |
toString()
Returns the value of Folder.getFullName(), or, if that is null,
returns the default toString().
|
public static final int HOLDS_MESSAGES
public static final int HOLDS_FOLDERS
public static final int READ_ONLY
public static final int READ_WRITE
protected Store store
protected int mode
protected Folder(Store store)
store
- the parent storepublic abstract java.lang.String getName()
This method can be invoked on a closed folder.
public abstract java.lang.String getFullName()
This method can be invoked on a closed folder.
public URLName getURLName() throws MessagingException
This method can be invoked on a closed folder.
MessagingException
public Store getStore()
public abstract Folder getParent() throws MessagingException
null
if this folder is the root of a folder hierarchy.
This method can be invoked on a closed folder.
MessagingException
public abstract boolean exists() throws MessagingException
This method can be invoked on a closed folder.
MessagingException
public abstract Folder[] list(java.lang.String pattern) throws MessagingException
This method can be invoked on a closed folder.
pattern
- the match patternMessagingException
public Folder[] listSubscribed(java.lang.String pattern) throws MessagingException
list
method.
The pattern can contain wildcards.
This method can be invoked on a closed folder.
pattern
- the match patternMessagingException
public Folder[] list() throws MessagingException
This method can be invoked on a closed folder.
MessagingException
public Folder[] listSubscribed() throws MessagingException
This method can be invoked on a closed folder.
MessagingException
public abstract char getSeparator() throws MessagingException
This method can be invoked on a closed folder.
MessagingException
public abstract int getType() throws MessagingException
This method can be invoked on a closed folder.
MessagingException
public abstract boolean create(int type) throws MessagingException
If the creation is successful, a CREATED FolderEvent is delivered to any FolderListeners registered on this Folder and this Store.
type
- the desired type of the folderMessagingException
public boolean isSubscribed()
This method can be invoked on a closed folder.
public void setSubscribed(boolean flag) throws MessagingException
This method can be invoked on a closed folder.
MessagingException
public abstract boolean hasNewMessages() throws MessagingException
This method can be invoked on a closed folder that can contain messages.
MessagingException
public abstract Folder getFolder(java.lang.String name) throws MessagingException
In some stores, name
can be an absolute path if it starts
with the hierarchy delimiter. Otherwise, it is interpreted relative to
this folder.
This method can be invoked on a closed folder.
name
- the name of the folderMessagingException
public abstract boolean delete(boolean recurse) throws MessagingException
recurse
- delete any subfoldersFolderNotFoundException
- if this folder does not existjava.lang.IllegalStateException
- if this folder is not closedMessagingException
public abstract boolean renameTo(Folder folder) throws MessagingException
folder
- a folder representing the new name for this folderFolderNotFoundException
- if this folder does not existjava.lang.IllegalStateException
- if this folder is not closedMessagingException
public abstract void open(int mode) throws MessagingException
mode
- open the Folder READ_ONLY or READ_WRITEFolderNotFoundException
- if this folder does not existjava.lang.IllegalStateException
- if this folder is not closedMessagingException
public abstract void close(boolean expunge) throws MessagingException
expunge
- if true, expunge all deleted messagesMessagingException
public abstract boolean isOpen()
public int getMode()
Folder.READ_ONLY
, Folder.READ_WRITE
,
or -1
if the open mode is not known.java.lang.IllegalStateException
- if this folder is not openpublic abstract Flags getPermanentFlags()
public abstract int getMessageCount() throws MessagingException
This method can be invoked on a closed folder; however, note that for some stores, getting the message count can be an expensive operation involving actually opening the folder. In such cases, a provider can choose to return -1 here when the folder is closed.
MessagingException
public int getNewMessageCount() throws MessagingException
This method can be invoked on a closed folder; however, note that for some stores, getting the message count can be an expensive operation involving actually opening the folder. In such cases, a provider can choose to return -1 here when the folder is closed.
MessagingException
public int getUnreadMessageCount() throws MessagingException
This method can be invoked on a closed folder; however, note that for some stores, getting the message count can be an expensive operation involving actually opening the folder. In such cases, a provider can choose to return -1 here when the folder is closed.
MessagingException
public int getDeletedMessageCount() throws MessagingException
This method can be invoked on a closed folder; however, note that for some stores, getting the message count can be an expensive operation involving actually opening the folder. In such cases, a provider can choose to return -1 here when the folder is closed.
FolderNotFoundException
- if this folder does not existMessagingException
public abstract Message getMessage(int msgnum) throws MessagingException
Note that message numbers can change within a session if the folder is expunged, therefore the use of message numbers as references to messages is inadvisable.
msgnum
- the message numberFolderNotFoundException
- if this folder does not existjava.lang.IllegalStateException
- if this folder is closedjava.lang.IndexOutOfBoundsException
- if the message number is out of
rangeMessagingException
public Message[] getMessages(int start, int end) throws MessagingException
start
- the number of the first messageend
- the number of the last messageFolderNotFoundException
- if this folder does not existjava.lang.IllegalStateException
- if this folder is closedjava.lang.IndexOutOfBoundsException
- if the start or end message
numbers are out of range.MessagingException
public Message[] getMessages(int[] msgnums) throws MessagingException
msgnums
- the array of message numbersFolderNotFoundException
- if this folder does not existjava.lang.IllegalStateException
- if this folder is closedjava.lang.IndexOutOfBoundsException
- if any message number in the
given array is out of rangeMessagingException
public Message[] getMessages() throws MessagingException
FolderNotFoundException
- if this folder does not existjava.lang.IllegalStateException
- if this folder is closedMessagingException
public abstract void appendMessages(Message[] msgs) throws MessagingException
This method can be invoked on a closed folder.
msgs
- array of messages to be appendedFolderNotFoundException
- if this folder does not existMessagingException
- if the append operation failedpublic void fetch(Message[] msgs, FetchProfile fp) throws MessagingException
msgs
- the messages to fetch the items forfp
- the fetch profileMessagingException
public void setFlags(Message[] msgs, Flags flag, boolean value) throws MessagingException
msgnums
- the messagesflag
- the flags to be setvalue
- set the flags to this valuejava.lang.IllegalStateException
- if this folder is closed or READ_ONLYMessagingException
public void setFlags(int start, int end, Flags flag, boolean value) throws MessagingException
start
- the number of the first messageend
- the number of the last messageflag
- the flags to be setvalue
- set the flags to this valuejava.lang.IllegalStateException
- if this folder is closed or READ_ONLYjava.lang.IndexOutOfBoundsException
- if the start or end message
numbers are out of rangeMessagingException
public void setFlags(int[] msgnums, Flags flag, boolean value) throws MessagingException
msgnums
- the message numbersflag
- the flags to be setvalue
- set the flags to this valuejava.lang.IllegalStateException
- if this folder is closed or READ_ONLYjava.lang.IndexOutOfBoundsException
- if any message number in the
given array is out of rangeMessagingException
public void copyMessages(Message[] msgs, Folder folder) throws MessagingException
The destination folder does not have to be open.
msgs
- the messagesfolder
- the folder to copy the messages toMessagingException
public abstract Message[] expunge() throws MessagingException
Expunge causes the renumbering of any messages with numbers higher than the message number of the lowest-numbered expunged message.
After a message has been expunged, only the isExpunged
and
getMessageNumber
methods are still valid on the
corresponding Message object; other methods may throw
MessageRemovedException
.
FolderNotFoundException
- if this folder does not existjava.lang.IllegalStateException
- if this folder is closedMessagingException
public Message[] search(SearchTerm term) throws MessagingException
term
- the search termSearchException
- if there was a problem with the searchFolderNotFoundException
- if this folder does not existjava.lang.IllegalStateException
- if this folder is closedMessagingException
public Message[] search(SearchTerm term, Message[] msgs) throws MessagingException
term
- the search termmsgs
- the messages to be searchedSearchException
- if there was a problem with the searchjava.lang.IllegalStateException
- if this folder is closedMessagingException
public void addConnectionListener(ConnectionListener l)
public void removeConnectionListener(ConnectionListener l)
protected void notifyConnectionListeners(int type)
public void addFolderListener(FolderListener l)
public void removeFolderListener(FolderListener l)
protected void notifyFolderListeners(int type)
protected void notifyFolderRenamedListeners(Folder folder)
public void addMessageCountListener(MessageCountListener l)
public void removeMessageCountListener(MessageCountListener l)
protected void notifyMessageAddedListeners(Message[] msgs)
protected void notifyMessageRemovedListeners(boolean removed, Message[] msgs)
public void addMessageChangedListener(MessageChangedListener l)
public void removeMessageChangedListener(MessageChangedListener l)
protected void notifyMessageChangedListeners(int type, Message msg)
public java.lang.String toString()
toString
in class java.lang.Object