|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.mail.Folder | +--com.sun.mail.imap.IMAPFolder
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 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.
Inner Class Summary | |
static class |
IMAPFolder.FetchProfileItem
A fetch profile item for fetching headers. |
static interface |
IMAPFolder.ProtocolCommand
A simple interface for user-defined IMAP protocol commands. |
Inner classes inherited from class javax.mail.UIDFolder |
UIDFolder.FetchProfileItem |
Field Summary | |
protected Flags |
availableFlags
|
protected boolean |
exists
|
protected java.lang.String |
fullName
|
protected java.util.Vector |
messageCache
|
protected java.lang.Object |
messageCacheLock
|
protected java.lang.String |
name
|
protected Flags |
permanentFlags
|
protected com.sun.mail.imap.protocol.IMAPProtocol |
protocol
|
protected char |
separator
|
protected int |
type
|
protected java.util.Hashtable |
uidTable
|
protected static char |
UNKNOWN_SEPARATOR
|
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(com.sun.mail.imap.protocol.ListInfo li,
IMAPStore store)
Constructor used to create an existing folder. |
protected |
IMAPFolder(java.lang.String fullName,
char separator,
IMAPStore store)
Constructor used to create a possibly non-existent folder. |
Method Summary | |
void |
addACL(ACL acl)
Add an access control list entry to the access control list for this folder. |
void |
addRights(ACL acl)
Add the rights specified in the ACL to the entry for the identifier specified in the ACL. |
void |
appendMessages(Message[] msgs)
Append the given messages into this folder. |
void |
close(boolean expunge)
Close this folder. |
void |
copyMessages(Message[] msgs,
Folder folder)
Copy the specified messages from this folder, to the specified destination. |
boolean |
create(int type)
Create this folder, with the specified type. |
boolean |
delete(boolean recurse)
Delete this folder. |
java.lang.Object |
doCommand(IMAPFolder.ProtocolCommand cmd)
Execute a user-supplied IMAP command. |
boolean |
exists()
Check whether this folder really exists on the server. |
Message[] |
expunge()
Expunge. |
void |
fetch(Message[] msgs,
FetchProfile fp)
Prefetch attributes, based on the given FetchProfile. |
ACL[] |
getACL()
Get the access control list entries for this folder. |
int |
getDeletedMessageCount()
Get the deleted message count. |
Folder |
getFolder(java.lang.String name)
Get the named subfolder. |
java.lang.String |
getFullName()
Get the fullname of this folder. |
Message |
getMessage(int msgnum)
Get the specified message. |
Message |
getMessageByUID(long uid)
Get the Message corresponding to the given UID. |
int |
getMessageCount()
Get the total message count. |
Message[] |
getMessagesByUID(long[] uids)
Get the Messages specified by the given array. |
Message[] |
getMessagesByUID(long start,
long end)
Get the Messages specified by the given range. |
java.lang.String |
getName()
Get the name of this folder. |
int |
getNewMessageCount()
Get the new message count. |
Folder |
getParent()
Get this folder's parent. |
Flags |
getPermanentFlags()
Return the permanent flags supported by the server. |
com.sun.mail.imap.protocol.IMAPProtocol |
getProtocol()
Return the IMAPProtocol object for this folder. |
Quota[] |
getQuota()
Get the quotas for the quotaroot associated with this folder. |
char |
getSeparator()
Get the separator character. |
protected com.sun.mail.imap.protocol.IMAPProtocol |
getStoreProtocol()
Get this folder's Store's protocol connection. |
int |
getType()
Get the type of this folder. |
long |
getUID(Message message)
Get the UID for the specified message. |
long |
getUIDValidity()
Returns the UIDValidity for this folder |
int |
getUnreadMessageCount()
Get the unread message count. |
void |
handleResponse(com.sun.mail.iap.Response r)
The response handler. |
boolean |
hasNewMessages()
Check whether this folder has new messages. |
boolean |
isOpen()
Check whether this connection is really open. |
boolean |
isSubscribed()
Check whether this folder is subscribed. |
Folder[] |
list(java.lang.String pattern)
List all subfolders matching the specified pattern. |
Rights[] |
listRights(java.lang.String name)
Get all the rights that may be allowed to the given identifier. |
Folder[] |
listSubscribed(java.lang.String pattern)
List all subscribed subfolders matching the specified pattern. |
protected java.lang.Object |
lockFor(com.sun.mail.imap.protocol.IMAPProtocol p)
Return a lock for the protocol object. |
Rights |
myRights()
Get the rights allowed to the currently authenticated user. |
void |
open(int mode)
Open this folder in the given mode. |
protected void |
releaseStoreProtocol(com.sun.mail.imap.protocol.IMAPProtocol p)
Release the store protocol object. |
void |
removeACL(java.lang.String name)
Remove any access control list entry for the given identifier from the access control list for this folder. |
void |
removeRights(ACL acl)
Remove the rights specified in the ACL from the entry for the identifier specified in the ACL. |
boolean |
renameTo(Folder f)
Rename this folder. |
Message[] |
search(SearchTerm term)
Search whole folder for messages matching the given term. |
Message[] |
search(SearchTerm term,
Message[] msgs)
Search the folder for messages matching the given term. |
void |
setFlags(Message[] msgs,
Flags flag,
boolean value)
Set the specified flags for the given array of messages. |
void |
setQuota(Quota quota)
Set the quotas for the quotaroot specified in the quota argument. |
void |
setSubscribed(boolean subscribe)
Subscribe/Unsubscribe this folder. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected java.lang.String fullName
protected java.lang.String name
protected int type
protected char separator
protected Flags availableFlags
protected Flags permanentFlags
protected boolean exists
protected com.sun.mail.imap.protocol.IMAPProtocol protocol
protected java.util.Vector messageCache
protected java.lang.Object messageCacheLock
protected java.util.Hashtable uidTable
protected static final char UNKNOWN_SEPARATOR
Constructor Detail |
protected IMAPFolder(java.lang.String fullName, char separator, IMAPStore store)
fullName
- fullname of this folderseparator
- the default separator character for this
folder's namespacestore
- the Storeprotected IMAPFolder(com.sun.mail.imap.protocol.ListInfo li, IMAPStore store)
Method Detail |
public java.lang.String getName()
getName
in class Folder
javax.mail.Folder
public java.lang.String getFullName()
getFullName
in class Folder
javax.mail.Folder
public Folder getParent() throws MessagingException
getParent
in class Folder
javax.mail.Folder
public boolean exists() throws MessagingException
exists
in class Folder
javax.mail.Folder
MessagingException
- typically if the connection
to the server is lost.Folder.create(int)
public Folder[] list(java.lang.String pattern) throws MessagingException
list
in class Folder
javax.mail.Folder
pattern
- the match patternFolderNotFoundException
- if this folder does
not exist.MessagingException
- Folder.listSubscribed(java.lang.String)
public Folder[] listSubscribed(java.lang.String pattern) throws MessagingException
listSubscribed
in class Folder
javax.mail.Folder
pattern
- the match patternFolderNotFoundException
- if this folder does
not exist.MessagingException
- Folder.list(java.lang.String)
public char getSeparator() throws MessagingException
getSeparator
in class Folder
javax.mail.Folder
FolderNotFoundException
- if this folder does
not existpublic int getType() throws MessagingException
getType
in class Folder
javax.mail.Folder
FolderNotFoundException
- if this folder does
not exist.Folder.HOLDS_FOLDERS
,
Folder.HOLDS_MESSAGES
public boolean isSubscribed()
isSubscribed
in class Folder
javax.mail.Folder
public void setSubscribed(boolean subscribe) throws MessagingException
setSubscribed
in class Folder
javax.mail.Folder
subscribe
- true to subscribe, false to unsubscribeFolderNotFoundException
- if this folder does
not exist.MethodNotSupportedException
- if this store
does not support subscriptionMessagingException
- public boolean create(int type) throws MessagingException
create
in class Folder
javax.mail.Folder
type
- The type of this folder.MessagingException
- Folder.HOLDS_FOLDERS
,
Folder.HOLDS_MESSAGES
,
FolderEvent
public boolean hasNewMessages() throws MessagingException
hasNewMessages
in class Folder
javax.mail.Folder
FolderNotFoundException
- if this folder does
not exist.MessagingException
- public Folder getFolder(java.lang.String name) throws MessagingException
getFolder
in class Folder
javax.mail.Folder
name
- name of the FolderMessagingException
- public boolean delete(boolean recurse) throws MessagingException
delete
in class Folder
javax.mail.Folder
FolderNotFoundException
- if this folder does
not existIllegalStateException
- if this folder is not in
the closed state.MessagingException
- FolderEvent
public boolean renameTo(Folder f) throws MessagingException
renameTo
in class Folder
javax.mail.Folder
f
- a folder representing the new name for this FolderFolderNotFoundException
- if this folder does
not existIllegalStateException
- if this folder is not in
the closed state.MessagingException
- FolderEvent
public void open(int mode) throws MessagingException
open
in class Folder
javax.mail.Folder
mode
- open the Folder READ_ONLY or READ_WRITEFolderNotFoundException
- if this folder does
not exist.IllegalStateException
- if this folder is not in
the closed state.MessagingException
- Folder.READ_ONLY
,
Folder.READ_WRITE
,
Folder.getType()
,
ConnectionEvent
public void fetch(Message[] msgs, FetchProfile fp) throws MessagingException
fetch
in class Folder
javax.mail.Folder
msgs
- fetch items for these messagesfp
- the FetchProfileIllegalStateException
- if this folder is not openedMessagingException.
- public void setFlags(Message[] msgs, Flags flag, boolean value) throws MessagingException
setFlags
in class Folder
javax.mail.Folder
msgnums
- the array of message objectsflag
- Flags object containing the flags to be setvalue
- set the flags to this boolean valueIllegalStateException
- if this folder is not opened
or if it has been opened READ_ONLY.MessagingException
- Message.setFlags(javax.mail.Flags, boolean)
,
MessageChangedEvent
public void close(boolean expunge) throws MessagingException
close
in class Folder
javax.mail.Folder
expunge
- expunges all deleted messages if this flag is trueIllegalStateException
- if this folder is not openedMessagingException
- ConnectionEvent
public boolean isOpen()
isOpen
in class Folder
javax.mail.Folder
public Flags getPermanentFlags()
getPermanentFlags
in class Folder
javax.mail.Folder
public int getMessageCount() throws MessagingException
getMessageCount
in class Folder
javax.mail.Folder
FolderNotFoundException
- if this folder does
not exist.MessagingException
- public int getNewMessageCount() throws MessagingException
getNewMessageCount
in class Folder
javax.mail.Folder
FolderNotFoundException
- if this folder does
not exist.MessagingException
- public int getUnreadMessageCount() throws MessagingException
getUnreadMessageCount
in class Folder
javax.mail.Folder
FolderNotFoundException
- if this folder does
not exist.MessagingException
- public int getDeletedMessageCount() throws MessagingException
getDeletedMessageCount
in class Folder
javax.mail.Folder
FolderNotFoundException
- if this folder does
not exist.MessagingException
- public Message getMessage(int msgnum) throws MessagingException
getMessage
in class Folder
javax.mail.Folder
msgnum
- the message numberFolderNotFoundException
- if this folder does
not exist.IllegalStateException
- if this folder is not openedIndexOutOfBoundsException
- if the message number
is out of range.MessagingException
- Folder.getMessageCount()
,
Folder.fetch(javax.mail.Message[], javax.mail.FetchProfile)
public void appendMessages(Message[] msgs) throws MessagingException
appendMessages
in class Folder
javax.mail.Folder
msgs
- array of Messages to be appendedFolderNotFoundException
- if this folder does
not exist.MessagingException
- if the append failed.public void copyMessages(Message[] msgs, Folder folder) throws MessagingException
copyMessages
in class Folder
javax.mail.Folder
msgnums
- the array of message objectsfolder
- the folder to copy the messages toFolderNotFoundException
- if the destination
folder does not exist.IllegalStateException
- if this folder is not opened.MessagingException
- Folder.appendMessages(javax.mail.Message[])
public Message[] expunge() throws MessagingException
expunge
in class Folder
javax.mail.Folder
FolderNotFoundException
- if this folder does not
existIllegalStateException
- if this folder is not opened.MessagingException
- Message.isExpunged()
,
MessageCountEvent
public Message[] search(SearchTerm term) throws MessagingException
search
in class Folder
javax.mail.Folder
term
- the search criterionSearchException
- if the search
term is too complex for the implementation to handle.FolderNotFoundException
- if this folder does
not exist.IllegalStateException
- if this folder is not opened.MessagingException
- SearchTerm
public Message[] search(SearchTerm term, Message[] msgs) throws MessagingException
search
in class Folder
javax.mail.Folder
term
- the search criterionmsgs
- the messages to be searchedSearchException
- if the search
term is too complex for the implementation to handle.IllegalStateException
- if this folder is not openedMessagingException
- SearchTerm
public long getUIDValidity() throws MessagingException
getUIDValidity
in interface UIDFolder
javax.mail.UIDFolder
public Message getMessageByUID(long uid) throws MessagingException
null
is returned.getMessageByUID
in interface UIDFolder
javax.mail.UIDFolder
uid
- UID for the desired messagenull
is returned
if no message corresponding to this UID is obtained.MessagingException
- public Message[] getMessagesByUID(long start, long end) throws MessagingException
Returns Message objects for all valid messages in this range. Returns an empty array if no messages are found.
getMessagesByUID
in interface UIDFolder
javax.mail.UIDFolder
start
- start UIDend
- end UIDMessagingException
- UIDFolder.LASTUID
public Message[] getMessagesByUID(long[] uids) throws MessagingException
uids.length()
elements are returned.
If any UID in the array is invalid, a null
entry
is returned for that element.
getMessagesByUID
in interface UIDFolder
javax.mail.UIDFolder
uids
- array of UIDsMessagingException
- public long getUID(Message message) throws MessagingException
getUID
in interface UIDFolder
javax.mail.UIDFolder
message
- Message from this folderjava.util.NoSuchElementException
- if the given Message
is not in this Folder.public Quota[] getQuota() throws MessagingException
MessagingException
- if the server doesn't support the
QUOTA extensionpublic void setQuota(Quota quota) throws MessagingException
getQuota
method, but it
need not be.quota
- the quota to setMessagingException
- if the server doesn't support the
QUOTA extensionpublic ACL[] getACL() throws MessagingException
MessagingException
- if the server doesn't support the
ACL extensionpublic void addACL(ACL acl) throws MessagingException
acl
- the access control list entry to addMessagingException
- if the server doesn't support the
ACL extensionpublic void removeACL(java.lang.String name) throws MessagingException
name
- the identifier for which to remove all ACL entriesMessagingException
- if the server doesn't support the
ACL extensionpublic void addRights(ACL acl) throws MessagingException
acl
- the identifer and rights to addMessagingException
- if the server doesn't support the
ACL extensionpublic void removeRights(ACL acl) throws MessagingException
acl
- the identifer and rights to removeMessagingException
- if the server doesn't support the
ACL extensionpublic Rights[] listRights(java.lang.String name) throws MessagingException
Note that this method lists the rights that it is possible to
assign to the given identifier, not the rights that are
actually granted to the given identifier. For the latter, see
the getACL
method.
name
- the identifier to list rights forMessagingException
- if the server doesn't support the
ACL extensionpublic Rights myRights() throws MessagingException
MessagingException
- if the server doesn't support the
ACL extensionpublic void handleResponse(com.sun.mail.iap.Response r)
handleResponse
in interface com.sun.mail.iap.ResponseHandler
protected com.sun.mail.imap.protocol.IMAPProtocol getStoreProtocol() throws com.sun.mail.iap.ProtocolException
public com.sun.mail.imap.protocol.IMAPProtocol getProtocol()
NOTE: This method was intended to allow experimentation with simple extension commands that can use the low level Protocol object APIs to send commands and process responses.
NOTE: Using this protocol object is completely
UNSAFE because there's no way to aquire
the required locks. See the doCommand
method
for a safe alternative.
doCommand(com.sun.mail.imap.IMAPFolder.ProtocolCommand)
public java.lang.Object doCommand(IMAPFolder.ProtocolCommand cmd) throws MessagingException
IMAPProtocol
object.
This method returns whatever the ProtocolCommand
object's doCommand
method returns. If the
doCommand
method throws a ConnectionException
it is translated into a StoreClosedException
or
FolderClosedException
as appropriate. If the
doCommand
method throws a ProtocolException
it is translated into a MessagingException
.
The following example shows how to execute the IMAP NOOP command.
Executing more complex IMAP commands requires intimate knowledge
of the com.sun.mail.iap
and
com.sun.mail.imap.protocol
packages, best acquired by
reading the source code.
import com.sun.mail.iap.*; import com.sun.mail.imap.*; import com.sun.mail.imap.protocol.*; ... IMAPFolder f = (IMAPFolder)folder; Object val = f.doCommand(new IMAPFolder.ProtocolCommand() { public Object doCommand(IMAPProtocol p) throws ProtocolException { p.simpleCommand("NOOP", null); return null; } });
Here's a more complex example showing how to use the proposed IMAP SORT extension:
import com.sun.mail.iap.*; import com.sun.mail.imap.*; import com.sun.mail.imap.protocol.*; ... IMAPFolder f = (IMAPFolder)folder; Object val = f.doCommand(new IMAPFolder.ProtocolCommand() { public Object doCommand(IMAPProtocol p) throws ProtocolException { // Issue command Argument args = new Argument(); Argument list = new Argument(); list.writeString("SUBJECT"); args.writeArgument(list); args.writeString("UTF-8"); args.writeString("ALL"); Response[] r = p.command("SORT", args); Response response = r[r.length-1]; // Grab response Vector v = new Vector(); if (response.isOK()) { // command succesful for (int i = 0, len = r.length; i < len; i++) { if (!(r[i] instanceof IMAPResponse)) continue; IMAPResponse ir = (IMAPResponse)r[i]; if (ir.keyEquals("SORT")) { String num; while ((num = ir.readAtomString()) != null) System.out.println(num); r[i] = null; } } } // dispatch remaining untagged responses p.notifyResponseHandlers(r); p.handleResult(response); return null; } });
protected java.lang.Object lockFor(com.sun.mail.imap.protocol.IMAPProtocol p)
When using this folder's protocol object, we have to lock the messageCacheLock, as described at the top. When using a borrowed store protocol we don't have to lock anything so we take advantage of the fact that locking a brand new object is effectively a no-op. This allows the code that conditionally chooses different protocol objects to do conditional locking in a simple way.
protected void releaseStoreProtocol(com.sun.mail.imap.protocol.IMAPProtocol p)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |