| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
IMAPFolder f = (IMAPFolder)folder;
Based on 42 examples
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 {@link #getQuota getQuota} and
{@link #setQuota setQuota} methods support the IMAP QUOTA extension.
Refer to RFC 2087
for more information.
The {@link #getACL getACL}, {@link #addACL addACL}, {@link #removeACL removeACL}, {@link #addRights addRights}, {@link #removeRights removeRights}, {@link #listRights listRights}, and {@link #myRights myRights} methods support the IMAP ACL extension. Refer to RFC 2086 for more information.
The {@link #doCommand doCommand} method and {@link IMAPFolder.ProtocolCommand 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.
Nested Class Summary | |
---|---|
static class |
A fetch profile item for fetching headers. |
static interface |
A simple interface for user-defined IMAP protocol commands. |
Field Summary | |
---|---|
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
|
Fields inherited from class javax.mail.Folder |
---|
HOLDS_FOLDERS, HOLDS_MESSAGES, mode, READ_ONLY, READ_WRITE, store |
Constructor Summary | |
---|---|
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. |
Method Summary | |
---|---|
void |
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 |
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 |
Execute a user-supplied IMAP command. |
Object |
|
Object |
|
protected Object |
|
boolean |
exists() Check whether this folder really exists on the server. |
Message[] |
expunge() Expunge all messages marked as DELETED. |
Message[] |
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 |
Close this folder without waiting for the server. |
ACL[] |
getACL() Get the access control list entries for this folder. |
String[] |
Get the attributes that the IMAP server returns with the LIST response. |
int |
Get the deleted message count. |
Folder |
Get the named subfolder. |
String |
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 |
Get the total message count. |
Message[] |
getMessagesByUID(long start, long end) Get the Messages specified by the given range. |
Message[] |
getMessagesByUID(long[] uids) Get the Messages specified by the given array. |
String |
getName() Get the name of this folder. |
int |
Get the new message count. |
Folder |
Get this folder's parent. |
Flags |
Return the permanent flags supported by the server. |
Quota[] |
getQuota() Get the quotas for the quotaroot associated with this folder. |
char |
Get the separator character. |
protected IMAPProtocol |
Get this folder's Store's protocol connection. |
int |
getType() Get the type of this folder. |
long |
Get the UID for the specified message. |
long |
Returns the predicted UID that will be assigned to the next message that is appended to this folder. |
long |
Returns the UIDValidity for this folder. |
int |
Get the unread message count. |
void |
The response handler. |
boolean |
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 |
Check whether this folder is subscribed. |
Folder[] |
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 |
Release the store protocol object. |
void |
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 |
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 |
Set the specified flags for the given array of messages. |
void |
Set the quotas for the quotaroot specified in the quota argument. |
void |
setSubscribed(boolean subscribe) Subscribe/Unsubscribe this folder. |
Field Detail |
---|
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 final char UNKNOWN_SEPARATOR
Constructor Detail |
---|
protected IMAPFolder(ListInfo li, IMAPStore store)
li
store
protected IMAPFolder(String fullName, char separator, IMAPStore store)
fullName
- fullname of this folderseparator
- the default separator character for this
folder's namespacestore
- the Storeprotected IMAPFolder(String fullName, char separator, IMAPStore store, boolean isNamespace)
fullName
- fullname of this folderseparator
- the default separator character for this
folder's namespacestore
- the StoreisNamespace
Method Detail |
---|
public void addACL(ACL acl) throws MessagingException
acl
- the access control list entry to addMessagingException
- if the server doesn't support the
ACL extensionpublic synchronized Message[] addMessages(Message[] msgs) throws MessagingException
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.
msgs
MessagingException
public void addRights(ACL acl) throws MessagingException
acl
- the identifer and rights to addMessagingException
- if the server doesn't support the
ACL extensionpublic synchronized void appendMessages(Message[] msgs) throws MessagingException
appendMessages
in class Folder
msgs
MessagingException
public synchronized AppendUID[] appendUIDMessages(Message[] msgs) throws MessagingException
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.
msgs
MessagingException
public synchronized void close(boolean expunge) throws MessagingException
close
in class Folder
expunge
MessagingException
public synchronized void copyMessages(Message[] msgs, Folder folder) throws MessagingException
copyMessages
in class Folder
msgs
folder
MessagingException
public synchronized boolean create(int type) throws MessagingException
create
in class Folder
type
MessagingException
public synchronized boolean delete(boolean recurse) throws MessagingException
delete
in class Folder
recurse
MessagingException
public 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; } });
cmd
MessagingException
public Object doCommandIgnoreFailure(IMAPFolder.ProtocolCommand cmd) throws MessagingException
cmd
MessagingException
public Object doOptionalCommand(String err, IMAPFolder.ProtocolCommand cmd) throws MessagingException
err
cmd
MessagingException
protected Object doProtocolCommand(IMAPFolder.ProtocolCommand cmd) throws ProtocolException
cmd
ProtocolException
public synchronized boolean exists() throws MessagingException
exists
in class Folder
MessagingException
public synchronized Message[] expunge() throws MessagingException
expunge
in class Folder
MessagingException
public synchronized Message[] expunge(Message[] msgs) throws MessagingException
msgs
MessagingException
public synchronized void fetch(Message[] msgs, FetchProfile fp) throws MessagingException
fetch
in class Folder
msgs
fp
MessagingException
public synchronized void forceClose() throws MessagingException
MessagingException
public ACL[] getACL() throws MessagingException
MessagingException
- if the server doesn't support the
ACL extensionpublic String[] getAttributes() throws MessagingException
MessagingException
public synchronized int getDeletedMessageCount() throws MessagingException
getDeletedMessageCount
in class Folder
MessagingException
public Folder getFolder(String name) throws MessagingException
getFolder
in class Folder
name
MessagingException
public synchronized String getFullName()
getFullName
in class Folder
public synchronized Message getMessage(int msgnum) throws MessagingException
getMessage
in class Folder
msgnum
MessagingException
public synchronized Message getMessageByUID(long uid) throws MessagingException
null
is returned.
uid
MessagingException
public synchronized int getMessageCount() throws MessagingException
getMessageCount
in class Folder
MessagingException
public synchronized 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.
start
end
MessagingException
public synchronized 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.
uids
MessagingException
public synchronized String getName()
getName
in class Folder
public synchronized int getNewMessageCount() throws MessagingException
getNewMessageCount
in class Folder
MessagingException
public synchronized Folder getParent() throws MessagingException
getParent
in class Folder
MessagingException
public synchronized Flags getPermanentFlags()
getPermanentFlags
in class Folder
public Quota[] getQuota() throws MessagingException
MessagingException
- if the server doesn't support the
QUOTA extensionpublic synchronized char getSeparator() throws MessagingException
getSeparator
in class Folder
MessagingException
protected synchronized IMAPProtocol getStoreProtocol() throws ProtocolException
ProtocolException
public synchronized int getType() throws MessagingException
getType
in class Folder
MessagingException
public synchronized long getUID(Message message) throws MessagingException
message
MessagingException
public synchronized long getUIDNext() throws MessagingException
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.
MessagingException
public synchronized long getUIDValidity() throws MessagingException
MessagingException
public synchronized int getUnreadMessageCount() throws MessagingException
getUnreadMessageCount
in class Folder
MessagingException
public void handleResponse(Response r)
r
public synchronized boolean hasNewMessages() throws MessagingException
hasNewMessages
in class Folder
MessagingException
public void idle() throws MessagingException
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 extensionpublic synchronized boolean isOpen()
isOpen
in class Folder
public synchronized boolean isSubscribed()
isSubscribed
in class Folder
public Folder[] list(String pattern) throws MessagingException
list
in class Folder
pattern
MessagingException
public Rights[] listRights(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 Folder[] listSubscribed(String pattern) throws MessagingException
listSubscribed
in class Folder
pattern
MessagingException
public Rights myRights() throws MessagingException
MessagingException
- if the server doesn't support the
ACL extensionpublic synchronized void open(int mode) throws MessagingException
open
in class Folder
mode
MessagingException
protected synchronized void releaseStoreProtocol(IMAPProtocol p)
p
public void removeACL(String name) throws MessagingException
name
- the identifier for which to remove all ACL entriesMessagingException
- 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 synchronized boolean renameTo(Folder f) throws MessagingException
renameTo
in class Folder
f
MessagingException
public synchronized Message[] search(SearchTerm term) throws MessagingException
search
in class Folder
term
MessagingException
public synchronized Message[] search(SearchTerm term, Message[] msgs) throws MessagingException
search
in class Folder
term
msgs
MessagingException
public synchronized void setFlags(Message[] msgs, Flags flag, boolean value) throws MessagingException
setFlags
in class Folder
msgs
flag
value
MessagingException
public 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 synchronized void setSubscribed(boolean subscribe) throws MessagingException
setSubscribed
in class Folder
subscribe
MessagingException
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |