Top Description Fields Constructors Methods
jakarta.mail

public abstract Class Folder

extends Object
implements AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable
Imports
jakarta.mail.event.ConnectionEvent, .ConnectionListener, .FolderEvent, .FolderListener, .MailEvent, .MessageChangedEvent, .MessageChangedListener, .MessageCountEvent, .MessageCountListener, jakarta.mail.search.SearchTerm, java.util.ArrayList, .EventListener, .List, .Vector, java.util.concurrent.Executor

Folder is an abstract class that represents a folder for mail messages. Subclasses implement protocol specific Folders.

Folders can contain Messages, other Folders or both, thus providing a tree-like hierarchy rooted at the Store's default folder. (Note that some Folder implementations may not allow both Messages and other Folders in the same Folder).

The interpretation of folder names is implementation dependent. The different levels of hierarchy in a folder's full name are separated from each other by the hierarchy delimiter character.

The case-insensitive full folder name (that is, the full name relative to the default folder for a Store) INBOX is reserved to mean the "primary folder for this user on this server". Not all Stores will provide an INBOX folder, and not all users will have an INBOX folder at all times. The name INBOX is reserved to refer to this folder, when it exists, in Stores that provide it.

A Folder object obtained from a Store need not actually exist in the backend store. The exists method tests whether the folder exists or not. The create method creates a Folder.

A Folder is initially in the closed state. Certain methods are valid in this state; the documentation for those methods note this. A Folder is opened by calling its 'open' method. All Folder methods, except open, delete and renameTo, are valid in this state.

The only way to get a Folder is by invoking the getFolder method on Store, Folder, or Session, or by invoking the list or listSubscribed methods on Folder. Folder objects returned by the above methods are not cached by the Store. Thus, invoking the getFolder method with the same folder name multiple times will return distinct Folder objects. Likewise for the list and listSubscribed methods.

The Message objects within the Folder are cached by the Folder. Thus, invoking getMessage(msgno) on the same message number multiple times will return the same Message object, until an expunge is done on this Folder.

Message objects from a Folder are only valid while a Folder is open and should not be accessed after the Folder is closed, even if the Folder is subsequently reopened. Instead, new Message objects must be fetched from the Folder after the Folder is reopened.

Note that a Message's message number can change within a session if the containing Folder is expunged using the expunge method. Clients that use message numbers as references to messages should be aware of this and should be prepared to deal with this situation (probably by flushing out existing message number references and reloading them). Because of this complexity, it is better for clients to use Message objects as references to messages, rather than message numbers. Expunged Message objects still have to be pruned, but other Message objects in that folder are not affected by the expunge.

Authors
John Mani, Bill Shannon

Field Summary

Modifier and TypeField and Description
private volatile Vector<ConnectionListener>
private volatile Vector<FolderListener>
public static final int
HOLDS_FOLDERS

This folder can contain other folders

public static final int
HOLDS_MESSAGES

This folder can contain messages

private volatile Vector<MessageChangedListener>
private volatile Vector<MessageCountListener>
protected int
mode

The open mode of this folder.

private final EventQueue
q

public static final int
READ_ONLY

The Folder is read only.

public static final int
READ_WRITE

The state and contents of this folder can be modified.

protected Store
store

The parent store.

Constructor Summary

AccessConstructor and Description
protected
Folder(Store
the Store that holds this folder
store
)

Constructor that takes a Store object.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addConnectionListener(ConnectionListener
the Listener for Connection events
l
)

Add a listener for Connection events on this Folder.

public synchronized void
addFolderListener(FolderListener
the Listener for Folder events
l
)

Add a listener for Folder events on this Folder.

public synchronized void
addMessageChangedListener(MessageChangedListener
the Listener for MessageChanged events
l
)

Add a listener for MessageChanged events on this Folder.

public synchronized void
addMessageCountListener(MessageCountListener
the Listener for MessageCount events
l
)

Add a listener for MessageCount events on this Folder.

public abstract void
appendMessages(Message[]
array of Messages to be appended
msgs
)

Append given Messages to this folder.

public abstract void
close(boolean
expunges all deleted messages if this flag is true
expunge
)

Close this Folder.

public void
close()

Implements java.lang.AutoCloseable.close.

Close this Folder and expunge deleted messages.

public void
copyMessages(Message[]
the array of message objects
msgs
,
Folder
the folder to copy the messages to
folder
)

Copy the specified Messages from this Folder into another Folder.

public abstract boolean

Returns:

true if the creation succeeds, else false.
create
(int
The type of this folder.
type
)

Create this folder on the Store.

public abstract boolean

Returns:

true if the Folder is deleted successfully
delete
(boolean
also delete subfolders?
recurse
)

Delete this Folder.

public abstract boolean

Returns:

true if the folder exists, otherwise false
exists
()

Tests if this folder physically exists on the Store.

public abstract Message[]

Returns:

array of expunged Message objects
expunge
()

Expunge (permanently remove) messages marked DELETED.

public void
fetch(Message[]
fetch items for these messages
msgs
,
FetchProfile
the FetchProfile
fp
)

Prefetch the items specified in the FetchProfile for the given Messages.

protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

public synchronized int

Returns:

number of deleted messages. -1 may be returned by certain implementations if this method is invoked on a closed folder.
getDeletedMessageCount
()

Get the number of deleted messages in this Folder.

public abstract Folder

Returns:

Folder object
getFolder
(String
name of the Folder
name
)

Return the Folder object corresponding to the given name.

public abstract String

Returns:

full name of the Folder
getFullName
()

Returns the full name of this Folder.

public abstract Message

Returns:

the Message object
getMessage
(int
the message number
msgnum
)

Get the Message object corresponding to the given message number.

public abstract int

Returns:

total number of messages. -1 may be returned by certain implementations if this method is invoked on a closed folder.
getMessageCount
()

Get total number of messages in this Folder.

public synchronized Message[]

Returns:

the Message objects
getMessages
(int
the number of the first message
start
,
int
the number of the last message
end
)

Get the Message objects for message numbers ranging from start through end, both start and end inclusive.

public synchronized Message[]

Returns:

the array of Message objects.
getMessages
(int[]
the array of message numbers
msgnums
)

Get the Message objects for message numbers specified in the array.

public synchronized Message[]

Returns:

array of Message objects, empty array if folder is empty.
getMessages
()

Get all Message objects from this Folder.

public synchronized int

Returns:

the open mode of this folder
getMode
()

Return the open mode of this folder.

public abstract String

Returns:

name of the Folder
getName
()

Returns the name of this Folder.

public synchronized int

Returns:

number of new messages. -1 may be returned by certain implementations if this method is invoked on a closed folder.
getNewMessageCount
()

Get the number of new messages in this Folder.

public abstract Folder

Returns:

Parent folder
getParent
()

Returns the parent folder of this folder.

public abstract Flags

Returns:

permanent flags, or null if not known
getPermanentFlags
()

Get the permanent flags supported by this Folder.

public abstract char

Returns:

Hierarchy separator character
getSeparator
()

Return the delimiter character that separates this Folder's pathname from the names of immediate subfolders.

public Store

Returns:

the Store
getStore
()

Returns the Store that owns this Folder object.

public abstract int

Returns:

integer with appropriate bits set
getType
()

Returns the type of this Folder, that is, whether this folder can hold messages or subfolders or both.

public synchronized int

Returns:

total number of unread messages. -1 may be returned by certain implementations if this method is invoked on a closed folder.
getUnreadMessageCount
()

Get the total number of unread messages in this Folder.

public URLName

Returns:

the URLName representing this folder
getURLName
()

Return a URLName representing this folder.

public abstract boolean

Returns:

true if the Store has new Messages
hasNewMessages
()

Returns true if this Folder has new messages since the last time this indication was reset.

public abstract boolean

Returns:

true if this Folder is in the 'open' state.
isOpen
()

Indicates whether this Folder is in the 'open' state.

public boolean

Returns:

true if this Folder is subscribed
isSubscribed
()

Returns true if this Folder is subscribed.

public abstract Folder[]

Returns:

array of matching Folder objects. An empty array is returned if no matching Folders exist.
list
(String
the match pattern
pattern
)

Returns a list of Folders belonging to this Folder's namespace that match the specified pattern.

public Folder[]

Returns:

array of Folder objects under this Folder. An empty array is returned if no subfolders exist.
list
()

Convenience method that returns the list of folders under this Folder.

public Folder[]

Returns:

array of matching subscribed Folder objects. An empty array is returned if no matching subscribed folders exist.
listSubscribed
(String
the match pattern
pattern
)

Returns a list of subscribed Folders belonging to this Folder's namespace that match the specified pattern.

public Folder[]

Returns:

array of subscribed Folder objects under this Folder. An empty array is returned if no subscribed subfolders exist.
listSubscribed
()

Convenience method that returns the list of subscribed folders under this Folder.

protected void
notifyConnectionListeners(int
the ConnectionEvent type
type
)

Notify all ConnectionListeners.

protected void
notifyFolderListeners(int
type of FolderEvent
type
)

Notify all FolderListeners registered on this Folder and this folder's Store.

protected void
notifyFolderRenamedListeners(Folder
Folder representing the new name.
folder
)

Notify all FolderListeners registered on this Folder and this folder's Store about the renaming of this folder.

protected void
notifyMessageAddedListeners(Message[]
the messages that were added
msgs
)

Notify all MessageCountListeners about the addition of messages into this folder.

protected void
notifyMessageChangedListeners(int
the MessageChangedEvent type
type
,
Message
the message that changed
msg
)

Notify all MessageChangedListeners.

protected void
notifyMessageRemovedListeners(boolean
was the message removed by this client?
removed
,
Message[]
the messages that were removed
msgs
)

Notify all MessageCountListeners about the removal of messages from this Folder.

public abstract void
open(int
open the Folder READ_ONLY or READ_WRITE
mode
)

Open this Folder.

private void
queueEvent(MailEvent event, Vector<? extends EventListener> vector)

public synchronized void
removeConnectionListener(ConnectionListener
the listener
l
)

Remove a Connection event listener.

public synchronized void
removeFolderListener(FolderListener
the listener
l
)

Remove a Folder event listener.

public synchronized void
removeMessageChangedListener(MessageChangedListener
the listener
l
)

Remove a MessageChanged listener.

public synchronized void
removeMessageCountListener(MessageCountListener
the listener
l
)

Remove a MessageCount listener.

public abstract boolean

Returns:

true if the Folder is renamed successfully
renameTo
(Folder
a folder representing the new name for this Folder
f
)

Rename this Folder.

public Message[]

Returns:

array of matching messages
search
(SearchTerm
the search criterion
term
)

Search this Folder for messages matching the specified search criterion.

public Message[]

Returns:

array of matching messages
search
(SearchTerm
the search criterion
term
,
Message[]
the messages to be searched
msgs
)

Search the given array of messages for those that match the specified search criterion.

public synchronized void
setFlags(Message[]
the array of message objects
msgs
,
Flags
Flags object containing the flags to be set
flag
,
boolean
set the flags to this boolean value
value
)

Set the specified flags on the messages specified in the array.

public synchronized void
setFlags(int
the number of the first message
start
,
int
the number of the last message
end
,
Flags
Flags object containing the flags to be set
flag
,
boolean
set the flags to this boolean value
value
)

Set the specified flags on the messages numbered from start through end, both start and end inclusive.

public synchronized void
setFlags(int[]
the array of message numbers
msgnums
,
Flags
Flags object containing the flags to be set
flag
,
boolean
set the flags to this boolean value
value
)

Set the specified flags on the messages whose message numbers are in the array.

public void
setSubscribed(boolean
true to subscribe, false to unsubscribe
subscribe
)

Subscribe or unsubscribe this Folder.

public String
toString()

Overrides java.lang.Object.toString.

override the default toString(), it will return the String from Folder.getFullName() or if that is null, it will use the default toString() behavior.

Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAllwaitwaitwait