com.sun.mail.imap
类 IMAPFolder

java.lang.Object
  继承者 javax.mail.Folder
      继承者 com.sun.mail.imap.IMAPFolder
所有已实现的接口:
ResponseHandler, UIDFolder
直接已知子类:
DefaultFolder

public class IMAPFolder
extends Folder
implements UIDFolder, ResponseHandler

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.

版本:
1.84, 07/05/15
作者:
John Mani, Bill Shannon, Jim Glennon

嵌套类摘要
static class IMAPFolder.FetchProfileItem
          A fetch profile item for fetching headers.
static interface IMAPFolder.ProtocolCommand
          A simple interface for user-defined IMAP protocol commands.
 
字段摘要
protected  String[] attributes
           
protected  Flags availableFlags
           
protected  boolean exists
           
protected  String fullName
           
protected  boolean isNamespace
           
protected  Vector messageCache
           
protected  Object messageCacheLock
           
protected  String name
           
protected  Flags permanentFlags
           
protected  IMAPProtocol protocol
           
protected  char separator
           
protected  int type
           
protected  Hashtable uidTable
           
protected static char UNKNOWN_SEPARATOR
           
 
从类 javax.mail.Folder 继承的字段
HOLDS_FOLDERS, HOLDS_MESSAGES, mode, READ_ONLY, READ_WRITE, store
 
从接口 javax.mail.UIDFolder 继承的字段
LASTUID
 
构造方法摘要
protected IMAPFolder(ListInfo li, IMAPStore store)
          Constructor used to create an existing folder.
protected IMAPFolder(String fullName, char separator, IMAPStore store)
          Constructor used to create a possibly non-existent folder.
protected IMAPFolder(String fullName, char separator, IMAPStore store, boolean isNamespace)
          Constructor used to create a possibly non-existent folder.
 
方法摘要
 void addACL(ACL acl)
          Add an access control list entry to the access control list for this folder.
 Message[] addMessages(Message[] msgs)
          Append the given messages into 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.
 AppendUID[] appendUIDMessages(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.
 Object doCommand(IMAPFolder.ProtocolCommand cmd)
          Execute a user-supplied IMAP command.
 Object doCommandIgnoreFailure(IMAPFolder.ProtocolCommand cmd)
           
 Object doOptionalCommand(String err, IMAPFolder.ProtocolCommand cmd)
           
protected  Object doProtocolCommand(IMAPFolder.ProtocolCommand cmd)
           
 boolean exists()
          Check whether this folder really exists on the server.
 Message[] expunge()
          Expunge all messages marked as DELETED.
 Message[] expunge(Message[] msgs)
          Expunge the indicated messages, which must have been marked as DELETED.
 void fetch(Message[] msgs, FetchProfile fp)
          Prefetch attributes, based on the given FetchProfile.
 void forceClose()
          Close this folder without waiting for the server.
 ACL[] getACL()
          Get the access control list entries for this folder.
 String[] getAttributes()
          Get the attributes that the IMAP server returns with the LIST response.
 int getDeletedMessageCount()
          Get the deleted message count.
 Folder getFolder(String name)
          Get the named subfolder.
 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.
 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.
 Quota[] getQuota()
          Get the quotas for the quotaroot associated with this folder.
 char getSeparator()
          Get the separator character.
protected  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 getUIDNext()
          Returns the predicted UID that will be assigned to the next message that is appended to this folder.
 long getUIDValidity()
          Returns the UIDValidity for this folder.
 int getUnreadMessageCount()
          Get the unread message count.
 void handleResponse(Response r)
          The response handler.
 boolean hasNewMessages()
          Check whether this folder has new messages.
 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.
 boolean isOpen()
          Check whether this connection is really open.
 boolean isSubscribed()
          Check whether this folder is subscribed.
 Folder[] list(String pattern)
          List all subfolders matching the specified pattern.
 Rights[] listRights(String name)
          Get all the rights that may be allowed to the given identifier.
 Folder[] listSubscribed(String pattern)
          List all subscribed subfolders matching the specified pattern.
 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(IMAPProtocol p)
          Release the store protocol object.
 void removeACL(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.
 
从类 javax.mail.Folder 继承的方法
addConnectionListener, addFolderListener, addMessageChangedListener, addMessageCountListener, finalize, getMessages, getMessages, getMessages, getMode, getStore, getURLName, list, listSubscribed, notifyConnectionListeners, notifyFolderListeners, notifyFolderRenamedListeners, notifyMessageAddedListeners, notifyMessageChangedListeners, notifyMessageRemovedListeners, removeConnectionListener, removeFolderListener, removeMessageChangedListener, removeMessageCountListener, setFlags, setFlags, toString
 
从类 java.lang.Object 继承的方法
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

字段详细信息

fullName

protected String fullName

name

protected String name

type

protected int type

separator

protected char separator

availableFlags

protected Flags availableFlags

permanentFlags

protected Flags permanentFlags

exists

protected boolean exists

isNamespace

protected boolean isNamespace

attributes

protected String[] attributes

protocol

protected IMAPProtocol protocol

messageCache

protected Vector messageCache

messageCacheLock

protected Object messageCacheLock

uidTable

protected Hashtable uidTable

UNKNOWN_SEPARATOR

protected static final char UNKNOWN_SEPARATOR
另请参见:
常量字段值
构造方法详细信息

IMAPFolder

protected IMAPFolder(String fullName,
                     char separator,
                     IMAPStore store)
Constructor used to create a possibly non-existent folder.

参数:
fullName - fullname of this folder
separator - the default separator character for this folder's namespace
store - the Store

IMAPFolder

protected IMAPFolder(String fullName,
                     char separator,
                     IMAPStore store,
                     boolean isNamespace)
Constructor used to create a possibly non-existent folder.

参数:
fullName - fullname of this folder
separator - the default separator character for this folder's namespace
store - the Store

IMAPFolder

protected IMAPFolder(ListInfo li,
                     IMAPStore store)
Constructor used to create an existing folder.

方法详细信息

getName

public String getName()
Get the name of this folder.

指定者:
Folder 中的 getName
返回:
name of the Folder

getFullName

public String getFullName()
Get the fullname of this folder.

指定者:
Folder 中的 getFullName
返回:
full name of the Folder

getParent

public Folder getParent()
                 throws MessagingException
Get this folder's parent.

指定者:
Folder 中的 getParent
返回:
Parent folder
抛出:
MessagingException

exists

public boolean exists()
               throws MessagingException
Check whether this folder really exists on the server.

指定者:
Folder 中的 exists
返回:
true if the folder exists, otherwise false
抛出:
MessagingException - typically if the connection to the server is lost.
另请参见:
Folder.create(int)

list

public Folder[] list(String pattern)
              throws MessagingException
List all subfolders matching the specified pattern.

指定者:
Folder 中的 list
参数:
pattern - the match pattern
返回:
array of matching Folder objects. An empty array is returned if no matching Folders exist.
抛出:
FolderNotFoundException - if this folder does not exist.
MessagingException
另请参见:
Folder.listSubscribed(java.lang.String)

listSubscribed

public Folder[] listSubscribed(String pattern)
                        throws MessagingException
List all subscribed subfolders matching the specified pattern.

覆盖:
Folder 中的 listSubscribed
参数:
pattern - the match pattern
返回:
array of matching subscribed Folder objects. An empty array is returned if no matching subscribed folders exist.
抛出:
FolderNotFoundException - if this folder does not exist.
MessagingException
另请参见:
Folder.list(java.lang.String)

getSeparator

public char getSeparator()
                  throws MessagingException
Get the separator character.

指定者:
Folder 中的 getSeparator
返回:
Hierarchy separator character
抛出:
FolderNotFoundException - if the implementation requires the folder to exist, but it does not
MessagingException

getType

public int getType()
            throws MessagingException
Get the type of this folder.

指定者:
Folder 中的 getType
返回:
integer with appropriate bits set
抛出:
FolderNotFoundException - if this folder does not exist.
MessagingException
另请参见:
Folder.HOLDS_FOLDERS, Folder.HOLDS_MESSAGES

isSubscribed

public boolean isSubscribed()
Check whether this folder is subscribed.

覆盖:
Folder 中的 isSubscribed
返回:
true if this Folder is subscribed

setSubscribed

public void setSubscribed(boolean subscribe)
                   throws MessagingException
Subscribe/Unsubscribe this folder.

覆盖:
Folder 中的 setSubscribed
参数:
subscribe - true to subscribe, false to unsubscribe
抛出:
FolderNotFoundException - if this folder does not exist.
MethodNotSupportedException - if this store does not support subscription
MessagingException

create

public boolean create(int type)
               throws MessagingException
Create this folder, with the specified type.

指定者:
Folder 中的 create
参数:
type - The type of this folder.
返回:
true if the creation succeeds, else false.
抛出:
MessagingException
另请参见:
Folder.HOLDS_FOLDERS, Folder.HOLDS_MESSAGES, FolderEvent

hasNewMessages

public boolean hasNewMessages()
                       throws MessagingException
Check whether this folder has new messages.

指定者:
Folder 中的 hasNewMessages
返回:
true if the Store has new Messages
抛出:
FolderNotFoundException - if this folder does not exist.
MessagingException

getFolder

public Folder getFolder(String name)
                 throws MessagingException
Get the named subfolder.

指定者:
Folder 中的 getFolder
参数:
name - name of the Folder
返回:
Folder object
抛出:
MessagingException

delete

public boolean delete(boolean recurse)
               throws MessagingException
Delete this folder.

指定者:
Folder 中的 delete
返回:
true if the Folder is deleted successfully
抛出:
FolderNotFoundException - if this folder does not exist
MessagingException
另请参见:
FolderEvent

renameTo

public boolean renameTo(Folder f)
                 throws MessagingException
Rename this folder.

指定者:
Folder 中的 renameTo
参数:
f - a folder representing the new name for this Folder
返回:
true if the Folder is renamed successfully
抛出:
FolderNotFoundException - if this folder does not exist
MessagingException
另请参见:
FolderEvent

open

public void open(int mode)
          throws MessagingException
Open this folder in the given mode.

指定者:
Folder 中的 open
参数:
mode - open the Folder READ_ONLY or READ_WRITE
抛出:
FolderNotFoundException - if this folder does not exist.
MessagingException
另请参见:
Folder.READ_ONLY, Folder.READ_WRITE, Folder.getType(), ConnectionEvent

fetch

public void fetch(Message[] msgs,
                  FetchProfile fp)
           throws MessagingException
Prefetch attributes, based on the given FetchProfile.

覆盖:
Folder 中的 fetch
参数:
msgs - fetch items for these messages
fp - the FetchProfile
抛出:
MessagingException

setFlags

public void setFlags(Message[] msgs,
                     Flags flag,
                     boolean value)
              throws MessagingException
Set the specified flags for the given array of messages.

覆盖:
Folder 中的 setFlags
参数:
msgs - the array of message objects
flag - Flags object containing the flags to be set
value - set the flags to this boolean value
抛出:
MessagingException
另请参见:
Message.setFlags(javax.mail.Flags, boolean), MessageChangedEvent

close

public void close(boolean expunge)
           throws MessagingException
Close this folder.

指定者:
Folder 中的 close
参数:
expunge - expunges all deleted messages if this flag is true
抛出:
MessagingException
另请参见:
ConnectionEvent

forceClose

public void forceClose()
                throws MessagingException
Close this folder without waiting for the server.

抛出:
MessagingException

isOpen

public boolean isOpen()
Check whether this connection is really open.

指定者:
Folder 中的 isOpen
返回:
true if this Folder is in the 'open' state.

getPermanentFlags

public Flags getPermanentFlags()
Return the permanent flags supported by the server.

指定者:
Folder 中的 getPermanentFlags
返回:
permanent flags, or null if not known

getMessageCount

public int getMessageCount()
                    throws MessagingException
Get the total message count.

指定者:
Folder 中的 getMessageCount
返回:
total number of messages. -1 may be returned by certain implementations if this method is invoked on a closed folder.
抛出:
FolderNotFoundException - if this folder does not exist.
MessagingException

getNewMessageCount

public int getNewMessageCount()
                       throws MessagingException
Get the new message count.

覆盖:
Folder 中的 getNewMessageCount
返回:
number of new messages. -1 may be returned by certain implementations if this method is invoked on a closed folder.
抛出:
FolderNotFoundException - if this folder does not exist.
MessagingException

getUnreadMessageCount

public int getUnreadMessageCount()
                          throws MessagingException
Get the unread message count.

覆盖:
Folder 中的 getUnreadMessageCount
返回:
total number of unread messages. -1 may be returned by certain implementations if this method is invoked on a closed folder.
抛出:
FolderNotFoundException - if this folder does not exist.
MessagingException

getDeletedMessageCount

public int getDeletedMessageCount()
                           throws MessagingException
Get the deleted message count.

覆盖:
Folder 中的 getDeletedMessageCount
返回:
number of deleted messages. -1 may be returned by certain implementations if this method is invoked on a closed folder.
抛出:
FolderNotFoundException - if this folder does not exist.
MessagingException

getMessage

public Message getMessage(int msgnum)
                   throws MessagingException
Get the specified message.

指定者:
Folder 中的 getMessage
参数:
msgnum - the message number
返回:
the Message object
抛出:
FolderNotFoundException - if this folder does not exist.
MessagingException
另请参见:
Folder.getMessageCount(), Folder.fetch(javax.mail.Message[], javax.mail.FetchProfile)

appendMessages

public void appendMessages(Message[] msgs)
                    throws MessagingException
Append the given messages into this folder.

指定者:
Folder 中的 appendMessages
参数:
msgs - array of Messages to be appended
抛出:
FolderNotFoundException - if this folder does not exist.
MessagingException - if the append failed.

appendUIDMessages

public AppendUID[] appendUIDMessages(Message[] msgs)
                              throws MessagingException
Append the given messages into this folder. Return array of AppendUID objects containing UIDs of these messages in the destination folder. Each element of the returned array corresponds to an element of the msgs array. A null element means the server didn't return UID information for the appended message.

Depends on the APPENDUID response code defined by the UIDPLUS extension - RFC 2359.

抛出:
MessagingException
从以下版本开始:
JavaMail 1.4

addMessages

public Message[] addMessages(Message[] msgs)
                      throws MessagingException
Append the given messages into this folder. Return array of Message objects representing the messages in the destination folder. Note that the folder must be open. Each element of the returned array corresponds to an element of the msgs array. A null element means the server didn't return UID information for the appended message.

Depends on the APPENDUID response code defined by the UIDPLUS extension - RFC 2359.

抛出:
MessagingException
从以下版本开始:
JavaMail 1.4

copyMessages

public void copyMessages(Message[] msgs,
                         Folder folder)
                  throws MessagingException
Copy the specified messages from this folder, to the specified destination.

覆盖:
Folder 中的 copyMessages
参数:
msgs - the array of message objects
folder - the folder to copy the messages to
抛出:
FolderNotFoundException - if the destination folder does not exist.
MessagingException
另请参见:
Folder.appendMessages(javax.mail.Message[])

expunge

public Message[] expunge()
                  throws MessagingException
Expunge all messages marked as DELETED.

指定者:
Folder 中的 expunge
返回:
array of expunged Message objects
抛出:
FolderNotFoundException - if this folder does not exist
MessagingException
另请参见:
Message.isExpunged(), MessageCountEvent

expunge

public Message[] expunge(Message[] msgs)
                  throws MessagingException
Expunge the indicated messages, which must have been marked as DELETED.

抛出:
MessagingException

search

public Message[] search(SearchTerm term)
                 throws MessagingException
Search whole folder for messages matching the given term.

覆盖:
Folder 中的 search
参数:
term - the search criterion
返回:
array of matching messages
抛出:
SearchException - if the search term is too complex for the implementation to handle.
FolderNotFoundException - if this folder does not exist.
MessagingException
另请参见:
SearchTerm

search

public Message[] search(SearchTerm term,
                        Message[] msgs)
                 throws MessagingException
Search the folder for messages matching the given term. Returns array of matching messages. Returns an empty array if no matching messages are found.

覆盖:
Folder 中的 search
参数:
term - the search criterion
msgs - the messages to be searched
返回:
array of matching messages
抛出:
SearchException - if the search term is too complex for the implementation to handle.
MessagingException
另请参见:
SearchTerm

getUIDValidity

public long getUIDValidity()
                    throws MessagingException
Returns the UIDValidity for this folder.

指定者:
接口 UIDFolder 中的 getUIDValidity
返回:
UIDValidity
抛出:
MessagingException

getUIDNext

public long getUIDNext()
                throws MessagingException
Returns the predicted UID that will be assigned to the next message that is appended to this folder. If the folder is closed, the STATUS command is used to retrieve this value. If the folder is open, the value returned from the SELECT or EXAMINE command is returned. Note that messages may have been appended to the folder while it was open and thus this value may be out of date.

Servers implementing RFC2060 likely won't return this value when a folder is opened. Servers implementing RFC3501 should return this value when a folder is opened.

返回:
the UIDNEXT value, or -1 if unknown
抛出:
MessagingException
从以下版本开始:
JavaMail 1.3.3

getMessageByUID

public Message getMessageByUID(long uid)
                        throws MessagingException
Get the Message corresponding to the given UID. If no such message exists, null is returned.

指定者:
接口 UIDFolder 中的 getMessageByUID
参数:
uid - UID for the desired message
返回:
the Message object. null is returned if no message corresponding to this UID is obtained.
抛出:
MessagingException

getMessagesByUID

public Message[] getMessagesByUID(long start,
                                  long end)
                           throws MessagingException
Get the Messages specified by the given range.

Returns Message objects for all valid messages in this range. Returns an empty array if no messages are found.

指定者:
接口 UIDFolder 中的 getMessagesByUID
参数:
start - start UID
end - end UID
返回:
array of Message objects
抛出:
MessagingException
另请参见:
UIDFolder.LASTUID

getMessagesByUID

public Message[] getMessagesByUID(long[] uids)
                           throws MessagingException
Get the Messages specified by the given array.

uids.length() elements are returned. If any UID in the array is invalid, a null entry is returned for that element.

指定者:
接口 UIDFolder 中的 getMessagesByUID
参数:
uids - array of UIDs
返回:
array of Message objects
抛出:
MessagingException

getUID

public long getUID(Message message)
            throws MessagingException
Get the UID for the specified message.

指定者:
接口 UIDFolder 中的 getUID
参数:
message - Message from this folder
返回:
UID for this message
抛出:
MessagingException

getQuota

public Quota[] getQuota()
                 throws MessagingException
Get the quotas for the quotaroot associated with this folder. Note that many folders may have the same quotaroot. Quotas are controlled on the basis of a quotaroot, not (necessarily) a folder. The relationship between folders and quotaroots depends on the IMAP server. Some servers might implement a single quotaroot for all folders owned by a user. Other servers might implement a separate quotaroot for each folder. A single folder can even have multiple quotaroots, perhaps controlling quotas for different resources.

返回:
array of Quota objects for the quotaroots associated with this folder
抛出:
MessagingException - if the server doesn't support the QUOTA extension

setQuota

public void setQuota(Quota quota)
              throws MessagingException
Set the quotas for the quotaroot specified in the quota argument. Typically this will be one of the quotaroots associated with this folder, as obtained from the getQuota method, but it need not be.

参数:
quota - the quota to set
抛出:
MessagingException - if the server doesn't support the QUOTA extension

getACL

public ACL[] getACL()
             throws MessagingException
Get the access control list entries for this folder.

返回:
array of access control list entries
抛出:
MessagingException - if the server doesn't support the ACL extension

addACL

public void addACL(ACL acl)
            throws MessagingException
Add an access control list entry to the access control list for this folder.

参数:
acl - the access control list entry to add
抛出:
MessagingException - if the server doesn't support the ACL extension

removeACL

public void removeACL(String name)
               throws MessagingException
Remove any access control list entry for the given identifier from the access control list for this folder.

参数:
name - the identifier for which to remove all ACL entries
抛出:
MessagingException - if the server doesn't support the ACL extension

addRights

public void addRights(ACL acl)
               throws MessagingException
Add the rights specified in the ACL to the entry for the identifier specified in the ACL. If an entry for the identifier doesn't already exist, add one.

参数:
acl - the identifer and rights to add
抛出:
MessagingException - if the server doesn't support the ACL extension

removeRights

public void removeRights(ACL acl)
                  throws MessagingException
Remove the rights specified in the ACL from the entry for the identifier specified in the ACL.

参数:
acl - the identifer and rights to remove
抛出:
MessagingException - if the server doesn't support the ACL extension

listRights

public Rights[] listRights(String name)
                    throws MessagingException
Get all the rights that may be allowed to the given identifier. Rights are grouped per RFC 2086 and each group is returned as an element of the array. The first element of the array is the set of rights that are always granted to the identifier. Later elements are rights that may be optionally granted to the identifier.

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 for
返回:
array of Rights objects representing possible rights for the identifier
抛出:
MessagingException - if the server doesn't support the ACL extension

myRights

public Rights myRights()
                throws MessagingException
Get the rights allowed to the currently authenticated user.

返回:
the rights granted to the current user
抛出:
MessagingException - if the server doesn't support the ACL extension

getAttributes

public String[] getAttributes()
                       throws MessagingException
Get the attributes that the IMAP server returns with the LIST response.

抛出:
MessagingException
从以下版本开始:
JavaMail 1.3.3

idle

public void idle()
          throws MessagingException
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. Use an appropriate listener to be notified of new messages or other events. When another thread (e.g., the listener thread) needs to issue an IMAP comand for this folder, the idle mode will be terminated and this method will return. Typically the caller will invoke this method in a loop.

The mail.imap.minidletime property enforces a minimum delay before returning from this method, to ensure that other threads have a chance to issue commands before the caller invokes this method again. The default delay is 10 milliseconds.

抛出:
MessagingException - if the server doesn't support the IDLE extension
IllegalStateException - if the folder isn't open
从以下版本开始:
JavaMail 1.4.1

handleResponse

public void handleResponse(Response r)
The response handler. This is the callback routine that is invoked by the protocol layer.

指定者:
接口 ResponseHandler 中的 handleResponse

getStoreProtocol

protected IMAPProtocol getStoreProtocol()
                                 throws ProtocolException
Get this folder's Store's protocol connection. When acquiring a store protocol object, it is important to use the following steps: IMAPProtocol p = null; try { p = getStoreProtocol(); // perform the command } catch (WhateverException ex) { // handle it } finally { releaseStoreProtocol(p); }

抛出:
ProtocolException

doCommand

public Object doCommand(IMAPFolder.ProtocolCommand cmd)
                 throws MessagingException
Execute a user-supplied IMAP command. The command is executed in the appropriate context with the necessary locks held and using the appropriate 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; } });

抛出:
MessagingException

doOptionalCommand

public Object doOptionalCommand(String err,
                                IMAPFolder.ProtocolCommand cmd)
                         throws MessagingException
抛出:
MessagingException

doCommandIgnoreFailure

public Object doCommandIgnoreFailure(IMAPFolder.ProtocolCommand cmd)
                              throws MessagingException
抛出:
MessagingException

doProtocolCommand

protected Object doProtocolCommand(IMAPFolder.ProtocolCommand cmd)
                            throws ProtocolException
抛出:
ProtocolException

releaseStoreProtocol

protected void releaseStoreProtocol(IMAPProtocol p)
Release the store protocol object. If we borrowed a protocol object from the connection pool, give it back. If we used our own protocol object, nothing to do.



Copyright © 2013. All Rights Reserved.