Top Description Inners Fields Constructors Methods
com.sun.mail.imap

public Class IMAPFolder

Additional top-level classes in compilation unit: MessageLiteral, LengthCounter.

extends Folder
implements UIDFolder, ResponseHandler
Class Inheritance
All Implemented Interfaces
com.sun.mail.iap.ResponseHandler, javax.mail.UIDFolder
Known Direct Subclasses
com.sun.mail.imap.DefaultFolder
Imports
java.util.Date, .Vector, .Hashtable, .List, .ArrayList, .Map, .NoSuchElementException, .Locale, java.util.logging.Level, java.io.*, java.net.SocketTimeoutException, java.nio.channels.SocketChannel, javax.mail.*, javax.mail.event.*, javax.mail.internet.*, javax.mail.search.*, com.sun.mail.util.PropUtil, .MailLogger, .CRLFOutputStream, com.sun.mail.iap.*, com.sun.mail.imap.protocol.*

This class implements an IMAP folder.

A closed IMAPFolder object shares a protocol connection with its IMAPStore object. When the folder is opened, it gets its own protocol connection.

Applications that need to make use of IMAP-specific features may cast a Folder object to an IMAPFolder object and use the methods on this class.

The getQuota and setQuota methods support the IMAP QUOTA extension. Refer to RFC 2087 for more information.

The getACL, addACL, removeACL, addRights, removeRights, listRights, and myRights methods support the IMAP ACL extension. Refer to RFC 2086 for more information.

The getSortedMessages methods support the IMAP SORT extension. Refer to RFC 5256 for more information.

The open(int,ResyncData) method and ResyncData class supports the IMAP CONDSTORE and QRESYNC extensions. Refer to RFC 4551 and RFC 5162 for more information.

The doCommand method and IMAPFolder.ProtocolCommand interface support use of arbitrary IMAP protocol commands.

See the com.sun.mail.imap package documentation for further information on the IMAP protocol provider.

Warning

The APIs unique to this class should be considered EXPERIMENTAL. They may be changed in the future in ways that are incompatible with applications using the current APIs.

Authors
John Mani, Bill Shannon, Jim Glennon

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
IMAPFolder.FetchProfileItem

A fetch profile item for fetching headers.

public static interface
IMAPFolder.ProtocolCommand

A simple interface for user-defined IMAP protocol commands.

Field Summary

Modifier and TypeField and Description
private static final int
protected volatile String[]
protected Flags
private Status
private long
private MailLogger
private boolean
protected volatile boolean
protected volatile String
private boolean
private volatile long
private static final int
private IdleManager
private int
protected boolean
protected MailLogger
protected MessageCache
protected final Object
protected String
private volatile boolean
protected Flags
protected volatile IMAPProtocol
private boolean
private int
private volatile int
private static final int
protected char
private volatile int
protected int
private long
private boolean
protected Hashtable<Long, IMAPMessage>
private long
protected static final char
Inherited from javax.mail.Folder:
HOLDS_FOLDERSHOLDS_MESSAGESmodeREAD_ONLYREAD_WRITEstore

Constructor Summary

AccessConstructor and Description
protected
IMAPFolder(String
fullname of this folder
fullName
,
char
the default separator character for this folder's namespace
separator
,
IMAPStore
the Store
store
,
Boolean
if this folder represents a namespace
isNamespace
)

Constructor used to create a possibly non-existent folder.

protected
IMAPFolder(ListInfo
the ListInfo for this folder
li
,
IMAPStore
the store containing this folder
store
)

Constructor used to create an existing folder.

Method Summary

Modifier and TypeMethod and Description
public void
addACL(ACL
the access control list entry to add
acl
)

Add an access control list entry to the access control list for this folder.

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

Overrides javax.mail.Folder.addMessageCountListener.

Add a listener for MessageCount events on this Folder.
public synchronized Message[]

Returns:

the messages in this folder
addMessages
(Message[]
the messages to add
msgs
)

Append the given messages into this folder.

public void
addRights(ACL
the identifer and rights to add
acl
)

Add the rights specified in the ACL to the entry for the identifier specified in the ACL.

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

Implements abstract javax.mail.Folder.appendMessages.

Append the given messages into this folder.
public synchronized AppendUID[]

Returns:

array of AppendUID objects
appendUIDMessages
(Message[]
the messages to append
msgs
)

Append the given messages into this folder.

protected void
protected void
private void
protected void
protected void
checkRange(int msgno)

private void
cleanup(boolean returnToPool)

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

Implements abstract javax.mail.Folder.close.

Close this folder.
private void
close(boolean expunge, boolean force)

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

Overrides javax.mail.Folder.copyMessages.

Copy the specified messages from this folder, to the specified destination.
private synchronized void
copymoveMessages(Message[] msgs, Folder folder, boolean move)

Copy or move the specified messages from this folder, to the specified destination.

private synchronized AppendUID[]

Returns:

array of AppendUID objects
copymoveUIDMessages
(Message[]
the messages to copy
msgs
,
Folder
the folder to copy the messages to
folder
,
boolean
move instead of copy?
move
)

Copy or move the specified messages from this folder, to the specified destination.

public synchronized AppendUID[]

Returns:

array of AppendUID objects
copyUIDMessages
(Message[]
the messages to copy
msgs
,
Folder
the folder to copy the messages to
folder
)

Copy the specified messages from this folder, to the specified destination.

public synchronized boolean
create(final int
The type of this folder.
type
)

Implements abstract javax.mail.Folder.create.

Create this folder, with the specified type.
private String
createHeaderCommand(String[] hdrs, boolean isRev1)

Create the appropriate IMAP FETCH command items to fetch the requested headers.

private Message[]
createMessagesForUIDs(long[] uids)

Get or create Message objects for the UIDs.

public synchronized boolean
delete(boolean
also delete subfolders?
recurse
)

Implements abstract javax.mail.Folder.delete.

Delete this folder.
public Object

Returns:

the result of the command
doCommand
(IMAPFolder.ProtocolCommand
the protocol command
cmd
)

Execute a user-supplied IMAP command.

public Object
private synchronized Folder[]
doList(final String pattern, final boolean subscribed)

public Object
protected synchronized Object
public synchronized boolean
exists()

Implements abstract javax.mail.Folder.exists.

Check whether this folder really exists on the server.
public synchronized Message[]
expunge()

Implements abstract javax.mail.Folder.expunge.

Expunge all messages marked as DELETED.
public synchronized Message[]

Returns:

the expunged messages
expunge
(Message[]
the messages to expunge
msgs
)

Expunge the indicated messages, which must have been marked as DELETED.

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

Overrides javax.mail.Folder.fetch.

Prefetch attributes, based on the given FetchProfile.
private int
findName(ListInfo[] li, String lname)

Which entry in li matches lname?

public synchronized void
forceClose()

Close this folder without waiting for the server.

public ACL[]

Returns:

array of access control list entries
getACL
()

Get the access control list entries for this folder.

public synchronized String[]

Returns:

array of attributes for this folder
getAttributes
()

Get the attributes that the IMAP server returns with the LIST response.

pack-priv SocketChannel
getChannel()

Return the SocketChannel for this connection, if any, for use in IdleManager.

public synchronized int
getDeletedMessageCount()

Overrides javax.mail.Folder.getDeletedMessageCount.

Get the deleted message count.
protected String

Returns:

the IMAP FETCH items to request
getEnvelopeCommand
()

Return the IMAP FETCH items to request in order to load all the "envelope" data.

public synchronized Folder
getFolder(String
name of the Folder
name
)

Implements abstract javax.mail.Folder.getFolder.

Get the named subfolder.
public String
getFullName()

Implements abstract javax.mail.Folder.getFullName.

Get the fullname of this folder.
public synchronized long

Returns:

the HIGHESTMODSEQ value
getHighestModSeq
()

Returns the HIGHESTMODSEQ for this folder.

public synchronized Message
getMessage(int
the message number
msgnum
)

Implements abstract javax.mail.Folder.getMessage.

Get the specified message.
protected IMAPMessage

Returns:

the IMAPMessage object
getMessageBySeqNumber
(int
the message sequence number
seqnum
)

Get the message object for the given sequence number.

public synchronized Message
getMessageByUID(long
UID for the desired message
uid
)

Implements javax.mail.UIDFolder.getMessageByUID.

Get the Message corresponding to the given UID.
public synchronized int
getMessageCount()

Implements abstract javax.mail.Folder.getMessageCount.

Get the total message count.
public synchronized Message[]
getMessages()

Overrides javax.mail.Folder.getMessages.

Get all Message objects from this Folder.
protected IMAPMessage[]

Returns:

the IMAPMessage objects
getMessagesBySeqNumbers
(int[]
the array of message sequence numbers
seqnums
)

Get the message objects for the given sequence numbers.

public synchronized Message[]
getMessagesByUID(long
start UID
start
,
long
end UID
end
)

Implements javax.mail.UIDFolder.getMessagesByUID.

Get the Messages specified by the given range.
public synchronized Message[]
getMessagesByUID(long[]
array of UIDs
uids
)

Implements javax.mail.UIDFolder.getMessagesByUID.

Get the Messages specified by the given array.
public synchronized Message[]

Returns:

the changed messages
getMessagesByUIDChangedSince
(long
the first message number
start
,
long
the last message number
end
,
long
the MODSEQ value
modseq
)

Get the messages that have been changed since the given MODSEQ value.

public synchronized String
getName()

Implements abstract javax.mail.Folder.getName.

Get the name of this folder.
public synchronized int
getNewMessageCount()

Overrides javax.mail.Folder.getNewMessageCount.

Get the new message count.
public synchronized Folder
getParent()

Implements abstract javax.mail.Folder.getParent.

Get this folder's parent.
public synchronized Flags
getPermanentFlags()

Implements abstract javax.mail.Folder.getPermanentFlags.

Return the permanent flags supported by the server.
protected IMAPProtocol

Returns:

the IMAPProtocol object used when the folder is open
getProtocol
()

Return the IMAPProtocol object for this folder.

public Quota[]

Returns:

array of Quota objects for the quotaroots associated with this folder
getQuota
()

Get the quotas for the quotaroot associated with this folder.

public synchronized char
getSeparator()

Implements abstract javax.mail.Folder.getSeparator.

Get the separator character.
public synchronized Message[]

Returns:

the messages in sorted order
getSortedMessages
(SortTerm[]
the SortTerms
term
)

Sort the messages in the folder according to the sort criteria.

public synchronized Message[]

Returns:

the messages in sorted order
getSortedMessages
(SortTerm[]
the SortTerms
term
,
SearchTerm
the SearchTerm
sterm
)

Sort the messages in the folder according to the sort criteria.

private Status
public synchronized long

Returns:

the value of the STATUS item, or -1
getStatusItem
(String
the STATUS item to fetch
item
)

Use the IMAP STATUS command to get the indicated item.

protected synchronized IMAPProtocol

Returns:

the IMAPProtocol for the Store's connection
getStoreProtocol
()

Get this folder's Store's protocol connection.

public synchronized int
getType()

Implements abstract javax.mail.Folder.getType.

Get the type of this folder.
public synchronized long
getUID(Message
Message from this folder
message
)

Implements javax.mail.UIDFolder.getUID.

Get the UID for the specified message.
public synchronized long

Returns:

the UIDNEXT value, or -1 if unknown
getUIDNext
()

Implements javax.mail.UIDFolder.getUIDNext.

Returns the predicted UID that will be assigned to the next message that is appended to this folder.
public synchronized boolean

Returns:

true if UIDs are not sticky
getUIDNotSticky
()

Servers that support the UIDPLUS extension (RFC 4315) may indicate that this folder does not support persistent UIDs; that is, UIDVALIDITY will be different each time the folder is opened.

public synchronized long
getUIDValidity()

Implements javax.mail.UIDFolder.getUIDValidity.

Returns the UIDValidity for this folder.
public synchronized int
getUnreadMessageCount()

Overrides javax.mail.Folder.getUnreadMessageCount.

Get the unread message count.
pack-priv boolean

Returns:

true if we should look for more IDLE responses, false if IDLE is done
handleIdle
(boolean
only do one notification?
once
)

Read a response from the server while we're in the IDLE state.

public void
pack-priv void
handleResponses(Response[] r)

Handle the given array of Responses.

public synchronized boolean
hasNewMessages()

Implements abstract javax.mail.Folder.hasNewMessages.

Check whether this folder has new messages.
public Map<String, String>

Returns:

a Map of keys and values identifying the server
id
(final Map<String, String>
a Map of keys and values identifying the client
clientParams
)

Send the IMAP ID command (if supported by the server) and return the result from the server.

public void
idle()

Use the IMAP IDLE command (see RFC 2177), if supported by the server, to enter idle mode so that the server can send unsolicited notifications of new messages arriving, etc. without the need for the client to constantly poll the server.

public void
idle(boolean
only do one notification?
once
)

Like idle, but if once is true, abort the IDLE command after the first notification, to allow the caller to process any notification synchronously.

pack-priv void
pack-priv void
private boolean
public synchronized boolean
isOpen()

Implements abstract javax.mail.Folder.isOpen.

Check whether this connection is really open.
private boolean
public synchronized boolean
isSubscribed()

Overrides javax.mail.Folder.isSubscribed.

Check whether this folder is subscribed.
protected void
keepConnectionAlive(boolean
keep the Store alive too?
keepStoreAlive
)

Issue a noop command for the connection if the connection has not been used in more than a second.

public Folder[]
list(String
the match pattern
pattern
)

Implements abstract javax.mail.Folder.list.

List all subfolders matching the specified pattern.
public Rights[]

Returns:

array of Rights objects representing possible rights for the identifier
listRights
(final String
the identifier to list rights for
name
)

Get all the rights that may be allowed to the given identifier.

public Folder[]
listSubscribed(String
the match pattern
pattern
)

Overrides javax.mail.Folder.listSubscribed.

List all subscribed subfolders matching the specified pattern.
private MessagingException
public synchronized void
moveMessages(Message[]
the messages to move
msgs
,
Folder
the folder to move the messages to
folder
)

Move the specified messages from this folder, to the specified destination.

public synchronized AppendUID[]

Returns:

array of AppendUID objects
moveUIDMessages
(Message[]
the messages to move
msgs
,
Folder
the folder to move the messages to
folder
)

Move the specified messages from this folder, to the specified destination.

public Rights

Returns:

the rights granted to the current user
myRights
()

Get the rights allowed to the currently authenticated user.

protected IMAPMessage

Returns:

the new IMAPMessage object
newIMAPMessage
(int
the message sequence number
msgnum
)

Create a new IMAPMessage object to represent the given message number.

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

Implements abstract javax.mail.Folder.open.

Open this folder in the given mode.
public synchronized List<MailEvent>

Returns:

a List of MailEvent instances, or null if none
open
(int
the open mode (Folder.READ_WRITE or Folder.READ_ONLY)
mode
,
ResyncData
the ResyncData instance
rd
)

Open this folder in the given mode, with the given resynchronization data.

private Message
processFetchResponse(FetchResponse fr)

Process a FETCH response.

protected void
releaseProtocol(boolean
return the protocol object to the pool?
returnToPool
)

Release the protocol object.

protected synchronized void
releaseStoreProtocol(IMAPProtocol
the IMAPProtocol object
p
)

Release the store protocol object.

public void
removeACL(final String
the identifier for which to remove all ACL entries
name
)

Remove any access control list entry for the given identifier from the access control list for this folder.

public void
removeRights(ACL
the identifer and rights to remove
acl
)

Remove the rights specified in the ACL from the entry for the identifier specified in the ACL.

public synchronized boolean
renameTo(final Folder
a folder representing the new name for this Folder
f
)

Implements abstract javax.mail.Folder.renameTo.

Rename this folder.
public synchronized Message[]

Returns:

the messages that match
search
(SearchTerm
the search term
term
)

Overrides javax.mail.Folder.search.

Search whole folder for messages matching the given term.
public synchronized Message[]
search(SearchTerm
the search criterion
term
,
Message[]
the messages to be searched
msgs
)

Overrides javax.mail.Folder.search.

Search the folder for messages matching the given term.
private void
setACL(final ACL acl, final char mod)

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
)

Overrides javax.mail.Folder.setFlags.

Set the specified flags for the given array of messages.
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
)

Overrides javax.mail.Folder.setFlags.

Set the specified flags for the given range of message numbers.
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
)

Overrides javax.mail.Folder.setFlags.

Set the specified flags for the given array of message numbers.
public void
setQuota(final Quota
the quota to set
quota
)

Set the quotas for the quotaroot specified in the quota argument.

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

Overrides javax.mail.Folder.setSubscribed.

Subscribe/Unsubscribe this folder.
pack-priv boolean

Returns:

true if IDLE started, false otherwise
startIdle
(final IdleManager im)

Start the IDLE command and put this folder into the IDLE state.

protected synchronized void
throwClosedException(ConnectionException
the ConnectionException
cex
)

Throw the appropriate 'closed' exception.

pack-priv void
Inherited from javax.mail.Folder:
addConnectionListeneraddFolderListeneraddMessageChangedListenerclosefinalizegetMessagesgetMessagesgetModegetStoregetURLNamelistlistSubscribednotifyConnectionListenersnotifyFolderListenersnotifyFolderRenamedListenersnotifyMessageAddedListenersnotifyMessageChangedListenersnotifyMessageRemovedListenersremoveConnectionListenerremoveFolderListenerremoveMessageChangedListenerremoveMessageCountListenertoString