Java Reference
In-Depth Information
folders and messages, getType() returns the bitwise union Folder.HOLDS_FOLDERS |
Folder.HOLDS_MESSAGES .
The getMode() method tells you whether a folder allows writing. It returns one of the
two named constants ( Folder.READ_ONLY or Folder.READ_WRITE ) or -1 if the mode is
unknown. Finally, the getStore() method returns the Store object from which this
folder was retrieved.
Managing Folders
The create() method creates a new folder in this folder's Store :
public abstract boolean create ( int type ) throws MessagingException
The type of the folder should be one of the named constants Folder.HOLDS_MESSAGES
or Folder.HOLDS_FOLDERS , depending on whether it will hold other folders or messages.
It returns true if the creation succeeded, false if it didn't.
The delete() method deletes this folder, but only if the folder is closed. Otherwise, it
throws an IllegalStateException :
public abstract boolean delete ( boolean recurse ) throws
IllegalStateException , FolderNotFoundException , MessagingException
If there are messages in this folder, they are deleted along with the folder. If the folder
contains subfolders, the subfolders are deleted if the recurse argument is true . If the
recurse argument is not true , the folder will only be deleted if it does not contain any
subfolders. If it does contain subfolders, the delete fails. If the folder does contain sub‐
folders and also contains messages, it's implementation-dependent whether the mes‐
sages will be deleted even though the folder itself isn't. If the delete succeeds, the method
returns true ; otherwise, it returns false .
The renameTo() method changes the name of this folder. A folder must be closed to be
renamed. Otherwise, an IllegalStateException is thrown. This method returns true
if the folder is successfully renamed, false if it isn't:
public abstract boolean renameTo ( Folder f ) throws
IllegalStateException , FolderNotFoundException , MessagingException
Managing Messages in Folders
On occasion, you may find a need to put a message in a folder. For instance, after sending
a message, a mail program may place it in a “Sent” folder. There's only one method to
do this, appendMessages() :
public abstract void appendMessages ( Message [] messages )
throws FolderNotFoundException , MessagingException
Search WWH ::




Custom Search