Class IMAPStore
- java.lang.Object
-
- javax.mail.Service
-
- javax.mail.Store
-
- com.sun.mail.imap.IMAPStore
-
- All Implemented Interfaces:
ResponseHandler,java.lang.AutoCloseable,QuotaAwareStore
- Direct Known Subclasses:
IMAPSSLStore
public class IMAPStore extends Store implements QuotaAwareStore, ResponseHandler
This class provides access to an IMAP message store.Applications that need to make use of IMAP-specific features may cast a
Storeobject to anIMAPStoreobject and use the methods on this class. ThegetQuotaandsetQuotamethods support the IMAP QUOTA extension. Refer to RFC 2087 for more information.The
idmethod supports the IMAP ID extension; see RFC 2971. The fields ID_NAME, ID_VERSION, etc. represent the suggested field names in RFC 2971 section 3.3 and may be used as keys in the Map containing client values or server values.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.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringID_ADDRESSstatic java.lang.StringID_ARGUMENTSstatic java.lang.StringID_COMMANDstatic java.lang.StringID_DATEstatic java.lang.StringID_ENVIRONMENTstatic java.lang.StringID_NAMEstatic java.lang.StringID_OSstatic java.lang.StringID_OS_VERSIONstatic java.lang.StringID_SUPPORT_URLstatic java.lang.StringID_VENDORstatic java.lang.StringID_VERSIONstatic intRESPONSEA special event type for a StoreEvent to indicate an IMAP response, if the mail.imap.enableimapevents property is set.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close this Store.FoldergetDefaultFolder()Get the default folder, representing the root of this user's namespace.FoldergetFolder(java.lang.String name)Get named folder.FoldergetFolder(URLName url)Get named folder.Folder[]getPersonalNamespaces()Using the IMAP NAMESPACE command (RFC 2342), return a set of folders representing the Personal namespaces.java.lang.StringgetProxyAuthUser()Get the user name to be used with the PROXYAUTH command.Quota[]getQuota(java.lang.String root)Get the quotas for the named quota root.Folder[]getSharedNamespaces()Using the IMAP NAMESPACE command (RFC 2342), return a set of folders representing the Shared namespaces.Folder[]getUserNamespaces(java.lang.String user)Using the IMAP NAMESPACE command (RFC 2342), return a set of folders representing the User's namespaces.voidhandleResponse(Response r)Response handler method.booleanhasCapability(java.lang.String capability)Return true if the specified capability string is in the list of capabilities the server announced.java.util.Map<java.lang.String,java.lang.String>id(java.util.Map<java.lang.String,java.lang.String> clientParams)Send the IMAP ID command (if supported by the server) and return the result from the server.voididle()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 without the need for the client to constantly poll the server.booleanisConnected()Check whether this store is connected.booleanisSSL()Does this IMAPStore use SSL when connecting to the server?voidsetPassword(java.lang.String password)Set the password that will be used for subsequent connections after this Store is first connected (for example, when creating a connection to open a Folder).voidsetProxyAuthUser(java.lang.String user)Set the user name to be used with the PROXYAUTH command.voidsetQuota(Quota quota)Set the quotas for the quota root specified in the quota argument.voidsetUsername(java.lang.String user)Set the user name that will be used for subsequent connections after this Store is first connected (for example, when creating a connection to open a Folder).-
Methods inherited from class javax.mail.Store
addFolderListener, addStoreListener, removeFolderListener, removeStoreListener
-
Methods inherited from class javax.mail.Service
addConnectionListener, connect, connect, connect, connect, getURLName, removeConnectionListener, toString
-
-
-
-
Field Detail
-
RESPONSE
public static final int RESPONSE
A special event type for a StoreEvent to indicate an IMAP response, if the mail.imap.enableimapevents property is set.- See Also:
- Constant Field Values
-
ID_NAME
public static final java.lang.String ID_NAME
- See Also:
- Constant Field Values
-
ID_VERSION
public static final java.lang.String ID_VERSION
- See Also:
- Constant Field Values
-
ID_OS
public static final java.lang.String ID_OS
- See Also:
- Constant Field Values
-
ID_OS_VERSION
public static final java.lang.String ID_OS_VERSION
- See Also:
- Constant Field Values
-
ID_VENDOR
public static final java.lang.String ID_VENDOR
- See Also:
- Constant Field Values
-
ID_SUPPORT_URL
public static final java.lang.String ID_SUPPORT_URL
- See Also:
- Constant Field Values
-
ID_ADDRESS
public static final java.lang.String ID_ADDRESS
- See Also:
- Constant Field Values
-
ID_DATE
public static final java.lang.String ID_DATE
- See Also:
- Constant Field Values
-
ID_COMMAND
public static final java.lang.String ID_COMMAND
- See Also:
- Constant Field Values
-
ID_ARGUMENTS
public static final java.lang.String ID_ARGUMENTS
- See Also:
- Constant Field Values
-
ID_ENVIRONMENT
public static final java.lang.String ID_ENVIRONMENT
- See Also:
- Constant Field Values
-
-
Method Detail
-
isSSL
public boolean isSSL()
Does this IMAPStore use SSL when connecting to the server?- Returns:
- true if using SSL
- Since:
- JavaMail 1.4.6
-
setUsername
public void setUsername(java.lang.String user)
Set the user name that will be used for subsequent connections after this Store is first connected (for example, when creating a connection to open a Folder). This value is overridden by any call to the Store's connect method.Some IMAP servers may provide an authentication ID that can be used for more efficient authentication for future connections. This authentication ID is provided in a server-specific manner not described here.
Most applications will never need to use this method.
- Parameters:
user- the user name for the store- Since:
- JavaMail 1.3.3
-
setPassword
public void setPassword(java.lang.String password)
Set the password that will be used for subsequent connections after this Store is first connected (for example, when creating a connection to open a Folder). This value is overridden by any call to the Store's connect method.Most applications will never need to use this method.
- Parameters:
password- the password for the store- Since:
- JavaMail 1.3.3
-
hasCapability
public boolean hasCapability(java.lang.String capability) throws MessagingExceptionReturn true if the specified capability string is in the list of capabilities the server announced.- Parameters:
capability- the capability string- Returns:
- true if the server supports this capability
- Throws:
MessagingException- for failures- Since:
- JavaMail 1.3.3
-
setProxyAuthUser
public void setProxyAuthUser(java.lang.String user)
Set the user name to be used with the PROXYAUTH command. The PROXYAUTH user name can also be set using themail.imap.proxyauth.userproperty when this Store is created.- Parameters:
user- the user name to set- Since:
- JavaMail 1.5.1
-
getProxyAuthUser
public java.lang.String getProxyAuthUser()
Get the user name to be used with the PROXYAUTH command.- Returns:
- the user name
- Since:
- JavaMail 1.5.1
-
isConnected
public boolean isConnected()
Check whether this store is connected. Override superclass method, to actually ping our server connection.- Overrides:
isConnectedin classService- Returns:
- true if the service is connected, false if it is not connected
-
close
public void close() throws MessagingExceptionClose this Store.- Specified by:
closein interfacejava.lang.AutoCloseable- Overrides:
closein classService- Throws:
MessagingException- for errors while closing- See Also:
ConnectionEvent
-
getDefaultFolder
public Folder getDefaultFolder() throws MessagingException
Get the default folder, representing the root of this user's namespace. Returns a closed DefaultFolder object.- Specified by:
getDefaultFolderin classStore- Returns:
- the root Folder
- Throws:
MessagingException- for other failures
-
getFolder
public Folder getFolder(java.lang.String name) throws MessagingException
Get named folder. Returns a new, closed IMAPFolder.- Specified by:
getFolderin classStore- Parameters:
name- The name of the Folder. In some Stores, name can be an absolute path if it starts with the hierarchy delimiter. Else it is interpreted relative to the 'root' of this namespace.- Returns:
- Folder object
- Throws:
MessagingException- for other failures- See Also:
Folder.exists(),Folder.create(int)
-
getFolder
public Folder getFolder(URLName url) throws MessagingException
Get named folder. Returns a new, closed IMAPFolder.- Specified by:
getFolderin classStore- Parameters:
url- URLName that denotes a folder- Returns:
- Folder object
- Throws:
MessagingException- for other failures- See Also:
URLName
-
getPersonalNamespaces
public Folder[] getPersonalNamespaces() throws MessagingException
Using the IMAP NAMESPACE command (RFC 2342), return a set of folders representing the Personal namespaces.- Overrides:
getPersonalNamespacesin classStore- Returns:
- array of Folder objects
- Throws:
MessagingException- for other failures
-
getUserNamespaces
public Folder[] getUserNamespaces(java.lang.String user) throws MessagingException
Using the IMAP NAMESPACE command (RFC 2342), return a set of folders representing the User's namespaces.- Overrides:
getUserNamespacesin classStore- Parameters:
user- the user name- Returns:
- array of Folder objects
- Throws:
MessagingException- for other failures
-
getSharedNamespaces
public Folder[] getSharedNamespaces() throws MessagingException
Using the IMAP NAMESPACE command (RFC 2342), return a set of folders representing the Shared namespaces.- Overrides:
getSharedNamespacesin classStore- Returns:
- array of Folder objects
- Throws:
MessagingException- for other failures
-
getQuota
public Quota[] getQuota(java.lang.String root) throws MessagingException
Get the quotas for the named quota root. Quotas are controlled on the basis of a quota root, not (necessarily) a folder. The relationship between folders and quota roots depends on the IMAP server. Some servers might implement a single quota root for all folders owned by a user. Other servers might implement a separate quota root for each folder. A single folder can even have multiple quota roots, perhaps controlling quotas for different resources.- Specified by:
getQuotain interfaceQuotaAwareStore- Parameters:
root- the name of the quota root- Returns:
- array of Quota objects
- Throws:
MessagingException- if the server doesn't support the QUOTA extension
-
setQuota
public void setQuota(Quota quota) throws MessagingException
Set the quotas for the quota root specified in the quota argument. Typically this will be one of the quota roots obtained from thegetQuotamethod, but it need not be.- Specified by:
setQuotain interfaceQuotaAwareStore- Parameters:
quota- the quota to set- Throws:
MessagingException- if the server doesn't support the QUOTA extension
-
handleResponse
public void handleResponse(Response r)
Response handler method.- Specified by:
handleResponsein interfaceResponseHandler
-
idle
public void idle() throws MessagingExceptionUse the IMAP IDLE command (see RFC 2177), if supported by the server, to enter idle mode so that the server can send unsolicited notifications without the need for the client to constantly poll the server. Use aConnectionListenerto be notified of events. When another thread (e.g., the listener thread) needs to issue an IMAP comand for this Store, the idle mode will be terminated and this method will return. Typically the caller will invoke this method in a loop.If the mail.imap.enableimapevents property is set, notifications received while the IDLE command is active will be delivered to
ConnectionListeners as events with a type ofIMAPStore.RESPONSE. The event's message will be the raw IMAP response string. Note that most IMAP servers will not deliver any events when using the IDLE command on a connection with no mailbox selected (i.e., this method). In most cases you'll want to use theidlemethod onIMAPFolder.NOTE: This capability is highly experimental and likely will change in future releases.
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.
- Throws:
MessagingException- if the server doesn't support the IDLE extensionjava.lang.IllegalStateException- if the store isn't connected- Since:
- JavaMail 1.4.1
-
id
public java.util.Map<java.lang.String,java.lang.String> id(java.util.Map<java.lang.String,java.lang.String> clientParams) throws MessagingExceptionSend the IMAP ID command (if supported by the server) and return the result from the server. The ID command identfies the client to the server and returns information about the server to the client. See RFC 2971. The returned Map is unmodifiable.- Parameters:
clientParams- a Map of keys and values identifying the client- Returns:
- a Map of keys and values identifying the server
- Throws:
MessagingException- if the server doesn't support the ID extension- Since:
- JavaMail 1.5.1
-
-