|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.mail.Folder org.apache.geronimo.javamail.store.imap.IMAPFolder
public class IMAPFolder
The base IMAP implementation of the javax.mail.Folder This is a base class for both the Root IMAP server and each IMAP group folder.
Folder
Nested Class Summary | |
---|---|
static class |
IMAPFolder.FetchProfileItem
Special profile item used for fetching SIZE and HEADER information. |
Field Summary | |
---|---|
protected Flags |
availableFlags
|
protected IMAPMailboxStatus |
cachedStatus
|
protected IMAPConnection |
currentConnection
|
protected boolean |
folderOpen
|
protected int |
folderType
|
protected String |
fullname
|
protected long |
lastStatusTimeStamp
|
protected IMAPListResponse |
listInfo
|
protected int |
maxSequenceNumber
|
protected LinkedList |
messages
|
protected String |
name
|
protected int |
nextMessageID
|
protected Flags |
permanentFlags
|
protected int |
recentMessages
|
protected char |
separator
|
protected Session |
session
|
protected long |
statusCacheTimeout
|
protected boolean |
subscribed
|
protected Map |
uidCache
|
protected long |
uidNext
|
protected long |
uidValidity
|
protected static char |
UNDETERMINED
|
protected int |
unseenMessages
|
Fields inherited from class javax.mail.Folder |
---|
HOLDS_FOLDERS, HOLDS_MESSAGES, mode, READ_ONLY, READ_WRITE, store |
Fields inherited from interface javax.mail.UIDFolder |
---|
LASTUID |
Constructor Summary | |
---|---|
protected |
IMAPFolder(IMAPStore store,
String fullname,
char separator)
Super class constructor the base IMAPFolder class. |
Method Summary | |
---|---|
void |
addACL(ACL acl)
Add an entry to the access control list for this folder. |
void |
addRights(ACL acl)
Add Rights to a given ACL entry. |
protected void |
addToUidCache(Long key,
Message msg)
Add a message to the UID mapping cache, ensuring that the UID value is updated. |
protected void |
appendMessage(Message msg)
Append a single message to the IMAP Folder. |
void |
appendMessages(Message[] msgs)
Append the supplied messages to this folder. |
protected void |
checkClosed()
Ensure the folder is not open for operations that require the folder to be closed. |
protected void |
checkFolderValidity()
Verify that this folder exists on the server before performning an operation that requires a valid Folder instance. |
protected void |
checkMessageFolder(Message msg)
Check if a Message is properly within the target folder. |
protected void |
checkMessageValidity(int messageNumber)
Validate that a target message number is considered valid by the IMAP server. |
protected void |
checkOpen()
Ensure the folder is open. |
protected void |
checkOpenReadWrite()
Check that the folder is open and in read/write mode. |
protected void |
checkReadWrite()
Ensure that the folder is open for read/write mode before doing an operation that would make a change. |
protected void |
cleanupFolder(boolean expunge,
boolean disconnected)
Do folder cleanup. |
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. |
boolean |
create(int newType)
Create a new folder capable of containing subfolder and/or messages as determined by the type parameter. |
boolean |
delete(boolean recurse)
Delete this folder and possibly any subfolders. |
boolean |
exists()
Check to see if this folder physically exists in the store. |
Message[] |
expunge()
Permanently delete all supplied messages that have the DELETED flag set from the Store. |
protected Message |
expungeMessage(int sequenceNumber)
Process an EXPUNGE response for a message, removing the message from the message cache. |
void |
fetch(Message[] messages,
FetchProfile profile)
Hint to the store to prefetch information on the supplied messages. |
protected Folder[] |
filterFolders(String pattern,
boolean subscribed)
Retrieve the list of matching groups from the IMAP server using the LIST or LSUB command. |
protected IMAPListResponse |
findListResponse(List responses,
String name)
Search a list of LIST responses for one containing information for a particular mailbox name. |
protected String |
generateMessageSet(List messages)
Generate a message set string from a List of messages rather than an array. |
protected String |
generateMessageSet(Message[] messages)
Take an array of messages and generate a String |
String[] |
getAttributes()
Get the set of attributes defined for the folder as the set of capabilities returned when the folder was opened. |
protected IMAPConnection |
getConnection()
Retrieve the connection attached to this folder. |
int |
getDeletedMessageCount()
Return the number of messages in this folder that have the Flag.DELETED flag set. |
Folder |
getFolder(String name)
Get the Folder determined by the supplied name; if the name is relative then it is interpreted relative to this folder. |
String |
getFullName()
Retrieve the folder's full name (including hierarchy information). |
protected String |
getMailBoxName()
Protected class intended for subclass overrides. |
Message |
getMessage(int msgNum)
Retrieve the message with the specified index in this Folder; messages indices start at 1 not zero. |
Message |
getMessageByUID(long uid)
Retrieve a message using the UID rather than the message sequence number. |
int |
getMessageCount()
Return the number of messages this folder contains. |
Message[] |
getMessages(int start,
int end)
Retrieve a range of messages for this folder. |
Message[] |
getMessagesByUID(long[] ids)
Retrieve a set of messages by explicit UIDs. |
Message[] |
getMessagesByUID(long start,
long end)
Get a series of messages using a UID range. |
String |
getName()
Retrieve the folder name. |
int |
getNewMessageCount()
Return the numbew of messages in this folder that have the Flag.RECENT flag set. |
Folder |
getParent()
Return the parent for this folder; if the folder is at the root of a heirarchy this returns null. |
Flags |
getPermanentFlags()
Get the permanentFlags |
Quota[] |
getQuota()
Get the quota values assigned to the current folder. |
char |
getSeparator()
Return the character used by this folder's Store to separate path components. |
int |
getType()
Return whether this folder can hold just messages or also subfolders. |
long |
getUID(Message message)
Retrieve the UID for a message from this Folder. |
long |
getUIDValidity()
Get the UID validity value for this Folder. |
int |
getUnreadMessageCount()
Return the number of messages in this folder that do not have the Flag.SEEN flag set. |
boolean |
handleResponse(IMAPUntaggedResponse response)
Handle an unsolicited response from the server. |
boolean |
hasNewMessages()
Check to see if this Folder conatins messages with the Flag.RECENT flag set. |
protected boolean |
holdsFolders()
Test if a folder can hold sub folders. |
boolean |
isOpen()
Tests the open status of the folder. |
boolean |
isSubscribed()
Return the subscription status of this folder. |
Folder[] |
list(String pattern)
Return a list of folders from this Folder's namespace that match the supplied pattern. |
Rights[] |
listRights(String name)
List the rights associated with a given name. |
Folder[] |
listSubscribed(String pattern)
Return a list of folders to which the user is subscribed and which match the supplied pattern. |
Rights |
myRights()
List the rights for the currently authenticated user. |
void |
notifyMessageChangedListeners(int type,
Message m)
Notify the message changed listeners that a message contained in the folder has been updated. |
void |
open(int mode)
Open this folder; the folder must be able to contain messages and must currently be closed. |
protected void |
populateMessageCache()
Populate the message cache with dummy messages, ensuring we're filled up to the server-reported number of messages. |
protected void |
refreshStatus(boolean force)
Refresh the status information on this folder. |
protected void |
releaseConnection(IMAPConnection connection)
Release our connection back to the Store. |
void |
removeACL(ACL acl)
Remove an entry from the access control list for this folder. |
void |
removeRights(ACL acl)
Remove ACL Rights from a folder. |
boolean |
renameTo(Folder f)
Rename this folder; the folder must be closed. |
protected Message[] |
resolveMessages(int[] messageNumbers)
Resolve an array of message numbers into an array of the referenced messages. |
protected Message |
retrieveMessageByUid(Long key,
int msgNumber)
Retrieve a message from a UID/message mapping. |
Message[] |
search(SearchTerm term)
Search the supplied messages for those that match the supplied criteria; messages must belong to this folder. |
Message[] |
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 set)
Set flags on the messages to the supplied value; all messages must belong to this folder. |
void |
setQuota(Quota quota)
Set the quota value for a quota root |
void |
setSubscribed(boolean flag)
Set or clear the subscription status of a file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final char UNDETERMINED
protected Session session
protected LinkedList messages
protected Map uidCache
protected char separator
protected String fullname
protected String name
protected boolean folderOpen
protected int folderType
protected boolean subscribed
protected int nextMessageID
protected int maxSequenceNumber
protected int recentMessages
protected int unseenMessages
protected long uidValidity
protected long uidNext
protected Flags permanentFlags
protected Flags availableFlags
protected IMAPMailboxStatus cachedStatus
protected IMAPListResponse listInfo
protected long statusCacheTimeout
protected long lastStatusTimeStamp
protected IMAPConnection currentConnection
Constructor Detail |
---|
protected IMAPFolder(IMAPStore store, String fullname, char separator)
store
- The javamail store this folder is attached to.fullname
- The fully qualified name of this folder.separator
- The separtor character used to delimit the different
levels of the folder hierarchy. This is used to
decompose the full name into smaller parts and
create the names of subfolders.Method Detail |
---|
public String getName()
getName
in class Folder
public String getFullName()
getFullName
in class Folder
public Folder getParent() throws MessagingException
getParent
in class Folder
MessagingException
public boolean exists() throws MessagingException
exists
in class Folder
MessagingException
- if there was a problem accessing the storepublic Folder[] list(String pattern) throws MessagingException
list
in class Folder
pattern
- the pattern to search for
MessagingException
- if there was a problem accessing the storepublic Folder[] listSubscribed(String pattern) throws MessagingException
list(String)
method.
listSubscribed
in class Folder
pattern
- the pattern to search for
MessagingException
- if there was a problem accessing the storepublic char getSeparator() throws MessagingException
getSeparator
in class Folder
MessagingException
- if there was a problem accessing the storepublic int getType() throws MessagingException
getType
in class Folder
MessagingException
public boolean create(int newType) throws MessagingException
CREATED FolderEvent
is sent to all FolderListeners registered with this Folder or with the Store.
create
in class Folder
newType
- the type, indicating if this folder should contain subfolders, messages or both
MessagingException
- if there was a problem accessing the storepublic boolean isSubscribed()
isSubscribed
in class Folder
public void setSubscribed(boolean flag) throws MessagingException
setSubscribed
in class Folder
flag
- The new subscription state.
MessagingException
public boolean hasNewMessages() throws MessagingException
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.
hasNewMessages
in class Folder
MessagingException
- if there was a problem accessing the storepublic Folder getFolder(String name) throws MessagingException
getFolder
in class Folder
name
- the name of the folder to return
MessagingException
- if there was a problem accessing the storepublic boolean delete(boolean recurse) throws MessagingException
FolderEvent.DELETED
events are sent as appropriate.
If recurse is false, then the behaviour depends on the folder type and store
implementation as followd:
FolderEvent.DELETED
event is sent.FolderEvent.DELETED
event is sent; if the folder is not
empty then the delete fails and this method returns false.FolderEvent.DELETED
event is sent; if the folder does
contain subfolders then the implementation may choose from the following three
behaviors:
FolderEvent.DELETED
event, and then return true to indicate the delete was performed. Note this does
not delete the folder itself and the exists()
operation for this folder
will return true
delete
in class Folder
recurse
- whether subfolders should be recursively deleted as well
MessagingException
- if there was a problem accessing the storepublic boolean renameTo(Folder f) throws MessagingException
FolderEvent.RENAMED
event is sent to
all listeners registered with this folder or with the store.
renameTo
in class Folder
newName
- the new name for this folder
MessagingException
- if there was a problem accessing the storepublic void open(int mode) throws MessagingException
ConnectionEvent.OPENED
event is sent to listeners registered
with this Folder.
Whether the Store allows multiple connections or if it allows multiple
writers is implementation defined.
open
in class Folder
mode
- READ_ONLY or READ_WRITE
MessagingException
- if there was a problem accessing the storeprotected void populateMessageCache()
MessagingException
public void close(boolean expunge) throws MessagingException
close
in class Folder
expunge
- whether to expunge all deleted messages
MessagingException
- if there was a problem accessing the store; the folder is still closedprotected void cleanupFolder(boolean expunge, boolean disconnected) throws MessagingException
expunge
- Indicates whether open messages should be expunged.disconnected
- The disconnected flag. If true, the server has cut
us off, which means our connection can not be returned
to the connection pool.
MessagingException
public boolean isOpen()
isOpen
in class Folder
public Flags getPermanentFlags()
getPermanentFlags
in class Folder
public int getMessageCount() throws MessagingException
getMessageCount
in class Folder
MessagingException
- if there was a problem accessing the storepublic int getNewMessageCount() throws MessagingException
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.
NB: This is an override of the default Folder implementation, which
examines each of the messages in the folder. IMAP has more efficient
mechanisms for grabbing the information.
getNewMessageCount
in class Folder
MessagingException
- if there was a problem accessing the storepublic int getUnreadMessageCount() throws MessagingException
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.
NB: This is an override of the default Folder implementation, which
examines each of the messages in the folder. IMAP has more efficient
mechanisms for grabbing the information.
getUnreadMessageCount
in class Folder
MessagingException
- if there was a problem accessing the storepublic int getDeletedMessageCount() throws MessagingException
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.
getDeletedMessageCount
in class Folder
MessagingException
- if there was a problem accessing the storepublic Message getMessage(int msgNum) throws MessagingException
Message
objects should be used as
references instead.
getMessage
in class Folder
msgNum
- The message sequence number of the target message.
MessagingException
- if there was a problem accessing the storepublic Message[] getMessages(int start, int end) throws MessagingException
getMessages
in class Folder
start
- Index of the first message to fetch, inclusive.end
- Index of the last message to fetch, inclusive.
MessagingException
- if there was a problem accessing the storepublic void appendMessages(Message[] msgs) throws MessagingException
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.
appendMessages
in class Folder
msgs
- The array of messages to append to the folder.
MessagingException
- if there was a problem accessing the storepublic void fetch(Message[] messages, FetchProfile profile) throws MessagingException
fetch
in class Folder
messages
- messages for which information should be fetchedprofile
- the information to fetch
MessagingException
- if there was a problem accessing the storeFetchProfile
public void setFlags(Message[] messages, Flags flags, boolean set) throws MessagingException
Message.setFlags(Flags, boolean)
for each supplied messages.
setFlags
in class Folder
messages
- whose flags should be setflags
- the set of flags to modifyset
- Indicates whether the flags should be set or cleared.
MessagingException
- if there was a problem accessing the storepublic void setFlags(int start, int end, Flags flags, boolean value) throws MessagingException
Message.setFlags(Flags, boolean)
.
setFlags
in class Folder
start
- first message end setend
- last message end setflags
- the set of flags end modifyvalue
- Indicates whether the flags should be set or cleared.
MessagingException
- if there was a problem accessing the storepublic void setFlags(int[] ids, Flags flags, boolean value) throws MessagingException
Message.setFlags(Flags, boolean)
.
setFlags
in class Folder
ids
- the indexes of the messages to setflags
- the set of flags end modifyvalue
- Indicates whether the flags should be set or cleared.
MessagingException
- if there was a problem accessing the storepublic void copyMessages(Message[] messages, Folder folder) throws MessagingException
appendMessages(Message[])
.
copyMessages
in class Folder
messages
- the messages to copyfolder
- the folder to copy to
MessagingException
- if there was a problem accessing the storepublic Message[] expunge() throws MessagingException
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.
expunge
in class Folder
MessagingException
- if there was a problem accessing the storepublic Message[] search(SearchTerm term) throws MessagingException
Message.match(javax.mail.search.SearchTerm)
method returns true;
subclasses may provide a more efficient implementation.
search
in class Folder
term
- the search criteriamessages
- the messages to search
MessagingException
- if there was a problem accessing the storepublic Message[] search(SearchTerm term, Message[] messages) throws MessagingException
Message.match(javax.mail.search.SearchTerm)
method returns true;
subclasses may provide a more efficient implementation.
search
in class Folder
term
- the search criteriamessages
- the messages to search
MessagingException
- if there was a problem accessing the storepublic long getUIDValidity() throws MessagingException
getUIDValidity
in interface UIDFolder
MessagingException
public Message getMessageByUID(long uid) throws MessagingException
getMessageByUID
in interface UIDFolder
uid
- The target UID.
MessagingException
public Message[] getMessagesByUID(long start, long end) throws MessagingException
getMessagesByUID
in interface UIDFolder
start
- The start of the UID range.end
- The end of the UID range. The special value
LASTUID can be used to request all messages up
to the last UID.
MessagingException
public Message[] getMessagesByUID(long[] ids) throws MessagingException
getMessagesByUID
in interface UIDFolder
ids
- An array of UID values to be retrieved.
MessagingException
public long getUID(Message message) throws MessagingException
getUID
in interface UIDFolder
message
- The target message.
MessagingException
protected Message retrieveMessageByUid(Long key, int msgNumber) throws MessagingException
key
- The UID key used for the mapping.msgNumber
- The message sequence number.
MessagingException
protected void addToUidCache(Long key, Message msg)
key
- The UID key.msg
- The message to add.protected void appendMessage(Message msg) throws MessagingException
msg
- The message to append.
MessagingException
protected Folder[] filterFolders(String pattern, boolean subscribed) throws MessagingException
pattern
- The pattern string (in wildmat format) used to match.
MessagingException
protected boolean holdsFolders() throws MessagingException
MessagingException
protected void checkMessageValidity(int messageNumber) throws MessagingException
messageNumber
- The message number we're checking.
MessagingException
protected void checkOpen() throws IllegalStateException
IllegalStateException
protected void checkClosed() throws IllegalStateException
IllegalStateException
protected void checkReadWrite() throws IllegalStateException
IllegalStateException
protected void checkOpenReadWrite() throws IllegalStateException
IllegalStateException
public void notifyMessageChangedListeners(int type, Message m)
notifyMessageChangedListeners
in class Folder
type
- The type of update made to the message.m
- The message that was updated.Folder.notifyMessageChangedListeners(int, javax.mail.Message)
protected IMAPConnection getConnection() throws MessagingException
MessagingException
protected void releaseConnection(IMAPConnection connection) throws MessagingException
connection
- The connection to release.
MessagingException
protected void refreshStatus(boolean force) throws MessagingException
force
- Force a status refresh always.
MessagingException
protected Message expungeMessage(int sequenceNumber) throws MessagingException
sequenceNumber
- The sequence number for the expunged message.
MessagingException
protected Message[] resolveMessages(int[] messageNumbers) throws MessagingException
messageNumbers
- The array of message numbers (can be null).
MessagingException
protected String generateMessageSet(List messages) throws MessagingException
messages
- The List of messages.
MessagingException
protected String generateMessageSet(Message[] messages) throws MessagingException
messages
- The array of messages we generate from.
MessagingException
protected void checkFolderValidity() throws MessagingException
MessagingException
protected void checkMessageFolder(Message msg) throws MessagingException
msg
- The message we're checking.
MessagingException
protected IMAPListResponse findListResponse(List responses, String name)
responses
- The list of responses.name
- The desired mailbox name.
protected String getMailBoxName()
public boolean handleResponse(IMAPUntaggedResponse response)
handleResponse
in interface IMAPUntaggedResponseHandler
response
- The UntaggedResponse to process.
public void removeACL(ACL acl) throws MessagingException
acl
- The ACL element to remove.
MessagingException
public void addACL(ACL acl) throws MessagingException
acl
- The new ACL to add.
MessagingException
public void addRights(ACL acl) throws MessagingException
acl
- The target ACL to update.
MessagingException
public void removeRights(ACL acl) throws MessagingException
acl
- The ACL describing the Rights to remove.
MessagingException
public Rights[] listRights(String name) throws MessagingException
name
- The user name for the Rights.
MessagingException
public Rights myRights() throws MessagingException
MessagingException
public Quota[] getQuota() throws MessagingException
MessagingException
public void setQuota(Quota quota) throws MessagingException
quota
- The new quota information to set.
MessagingException
public String[] getAttributes() throws MessagingException
MessagingException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |