Package org.apache.commons.net.imap
Class IMAPSClient
java.lang.Object
org.apache.commons.net.SocketClient
org.apache.commons.net.imap.IMAP
org.apache.commons.net.imap.IMAPClient
org.apache.commons.net.imap.IMAPSClient
- Direct Known Subclasses:
AuthenticatingIMAPClient
The IMAPSClient class provides SSL/TLS connection encryption to IMAPClient. Copied from
FTPSClient and modified to suit
IMAP. If implicit mode is selected (NOT the default), SSL/TLS negotiation starts right after the connection has been established. In explicit mode (the
default), SSL/TLS negotiation starts when the user calls execTLS() and the server accepts the command.
//Implicit usage:
IMAPSClient c = new IMAPSClient(true);
c.connect("127.0.0.1", 993);
//Explicit usage:
IMAPSClient c = new IMAPSClient();
c.connect("127.0.0.1", 143);
if (c.execTLS()) { /rest of the commands here/ }
Warning: the hostname is not verified against the certificate by default, use setHostnameVerifier(HostnameVerifier)
or
setEndpointCheckingEnabled(boolean)
(on Java 1.7+) to enable verification.-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.commons.net.imap.IMAPClient
IMAPClient.FETCH_ITEM_NAMES, IMAPClient.SEARCH_CRITERIA, IMAPClient.STATUS_DATA_ITEMS
Nested classes/interfaces inherited from class org.apache.commons.net.imap.IMAP
IMAP.IMAPChunkListener, IMAP.IMAPState
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The default IMAP over SSL port.static final String
Default secure socket protocol name.Fields inherited from class org.apache.commons.net.imap.IMAP
__DEFAULT_ENCODING, __writer, _reader, DEFAULT_PORT, TRUE_CHUNK_LISTENER
Fields inherited from class org.apache.commons.net.SocketClient
_defaultPort_, _hostname_, _input_, _output_, _serverSocketFactory_, _socket_, _socketFactory_, _timeout_, connectTimeout, NETASCII_EOL, remoteInetSocketAddress
-
Constructor Summary
ConstructorDescriptionConstructor for IMAPSClient.IMAPSClient
(boolean implicit) Constructor for IMAPSClient.IMAPSClient
(boolean implicit, SSLContext ctx) Constructor for IMAPSClient.IMAPSClient
(String proto) Constructor for IMAPSClient.IMAPSClient
(String proto, boolean implicit) Constructor for IMAPSClient.IMAPSClient
(String proto, boolean implicit, SSLContext ctx) Constructor for IMAPSClient.IMAPSClient
(SSLContext context) Constructor for IMAPSClient. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Because there are so many connect() methods, the _connectAction_() method is provided as a means of performing some action immediately after establishing a connection, rather than reimplementing all the connect() methods.boolean
execTLS()
The TLS command execution.String[]
Returns the names of the cipher suites which could be enabled for use on this connection.String[]
Returns the names of the protocol versions which are currently enabled for use on this connection.Gets the currently configuredHostnameVerifier
.Gets the currently configuredTrustManager
.boolean
Return whether or not endpoint identification using the HTTPS algorithm on Java 1.7+ is enabled.void
setEnabledCipherSuites
(String[] cipherSuites) Controls which particular cipher suites are enabled for use on this connection.void
setEnabledProtocols
(String[] protocolVersions) Controls which particular protocol versions are enabled for use on this connection.void
setEndpointCheckingEnabled
(boolean enable) Automatic endpoint identification checking using the HTTPS algorithm is supported on Java 1.7+.void
setHostnameVerifier
(HostnameVerifier newHostnameVerifier) Override the defaultHostnameVerifier
to use.void
setKeyManager
(KeyManager newKeyManager) Sets aKeyManager
to use.void
setTrustManager
(TrustManager newTrustManager) Override the defaultTrustManager
to use.Methods inherited from class org.apache.commons.net.imap.IMAPClient
append, append, append, capability, check, close, copy, create, delete, examine, expunge, fetch, list, login, logout, lsub, noop, rename, search, search, select, status, store, subscribe, uid, unsubscribe
Methods inherited from class org.apache.commons.net.imap.IMAP
disconnect, doCommand, doCommand, fireReplyReceived, generateCommandID, getReplyString, getReplyStrings, getState, sendCommand, sendCommand, sendCommand, sendCommand, sendData, setChunkListener, setState
Methods inherited from class org.apache.commons.net.SocketClient
addProtocolCommandListener, applySocketAttributes, checkOpenOutputStream, connect, connect, connect, connect, connect, connect, createCommandSupport, fireCommandSent, getCharset, getCharsetName, getCommandSupport, getConnectTimeout, getDefaultPort, getDefaultTimeout, getKeepAlive, getLocalAddress, getLocalPort, getProxy, getReceiveBufferSize, getRemoteAddress, getRemoteInetSocketAddress, getRemotePort, getSendBufferSize, getServerSocketFactory, getSoLinger, getSoTimeout, getTcpNoDelay, isAvailable, isConnected, removeProtocolCommandListener, setCharset, setConnectTimeout, setDefaultPort, setDefaultTimeout, setKeepAlive, setProxy, setReceiveBufferSize, setSendBufferSize, setServerSocketFactory, setSocketFactory, setSoLinger, setSoTimeout, setTcpNoDelay, verifyRemote
-
Field Details
-
DEFAULT_IMAPS_PORT
The default IMAP over SSL port.- See Also:
-
DEFAULT_PROTOCOL
Default secure socket protocol name.- See Also:
-
-
Constructor Details
-
IMAPSClient
public IMAPSClient()Constructor for IMAPSClient. Sets security mode to explicit (isImplicit = false). -
IMAPSClient
Constructor for IMAPSClient.- Parameters:
implicit
- The security mode (Implicit/Explicit).
-
IMAPSClient
Constructor for IMAPSClient.- Parameters:
implicit
- The security mode(Implicit/Explicit).ctx
- A pre-configured SSL Context.
-
IMAPSClient
Constructor for IMAPSClient.- Parameters:
context
- A pre-configured SSL Context.
-
IMAPSClient
Constructor for IMAPSClient.- Parameters:
proto
- the protocol.
-
IMAPSClient
Constructor for IMAPSClient.- Parameters:
proto
- the protocol.implicit
- The security mode(Implicit/Explicit).
-
IMAPSClient
Constructor for IMAPSClient.- Parameters:
proto
- the protocol.implicit
- The security mode(Implicit/Explicit).ctx
- the SSL context
-
-
Method Details
-
_connectAction_
Because there are so many connect() methods, the _connectAction_() method is provided as a means of performing some action immediately after establishing a connection, rather than reimplementing all the connect() methods.- Overrides:
_connectAction_
in classIMAP
- Throws:
IOException
- If it is thrown by _connectAction_().- See Also:
-
execTLS
The TLS command execution.- Returns:
- TRUE if the command and negotiation succeeded.
- Throws:
SSLException
- If the server reply code is not positive.IOException
- If an I/O error occurs while sending the command or performing the negotiation.
-
getEnabledCipherSuites
Returns the names of the cipher suites which could be enabled for use on this connection. When the underlyingSocket
is not anSSLSocket
instance, returns null.- Returns:
- An array of cipher suite names, or
null
.
-
getEnabledProtocols
Returns the names of the protocol versions which are currently enabled for use on this connection. When the underlyingSocket
is not anSSLSocket
instance, returns null.- Returns:
- An array of protocols, or
null
.
-
getHostnameVerifier
Gets the currently configuredHostnameVerifier
.- Returns:
- A HostnameVerifier instance.
- Since:
- 3.4
-
getTrustManager
Gets the currently configuredTrustManager
.- Returns:
- A TrustManager instance.
-
isEndpointCheckingEnabled
Return whether or not endpoint identification using the HTTPS algorithm on Java 1.7+ is enabled. The default behavior is for this to be disabled.- Returns:
- True if enabled, false if not.
- Since:
- 3.4
-
setEnabledCipherSuites
Controls which particular cipher suites are enabled for use on this connection. Called before server negotiation.- Parameters:
cipherSuites
- The cipher suites.
-
setEnabledProtocols
Controls which particular protocol versions are enabled for use on this connection. I perform setting before a server negotiation.- Parameters:
protocolVersions
- The protocol versions.
-
setEndpointCheckingEnabled
Automatic endpoint identification checking using the HTTPS algorithm is supported on Java 1.7+. The default behavior is for this to be disabled.- Parameters:
enable
- Enable automatic endpoint identification checking using the HTTPS algorithm on Java 1.7+.- Since:
- 3.4
-
setHostnameVerifier
Override the defaultHostnameVerifier
to use.- Parameters:
newHostnameVerifier
- The HostnameVerifier implementation to set ornull
to disable.- Since:
- 3.4
-
setKeyManager
Sets aKeyManager
to use.- Parameters:
newKeyManager
- The KeyManager implementation to set.- See Also:
-
setTrustManager
Override the defaultTrustManager
to use.- Parameters:
newTrustManager
- The TrustManager implementation to set.- See Also:
-