Package com.sun.mail.iap
Class Protocol
java.lang.Object
com.sun.mail.iap.Protocol
- Direct Known Subclasses:
IMAPProtocol
General protocol handling code for IMAP-like protocols.
The Protocol object is multithread safe.
-
Constructor Summary
ConstructorsConstructorDescriptionProtocol(InputStream in, PrintStream out, Properties props, boolean debug) Constructor for debugging.Protocol(String host, int port, Properties props, String prefix, boolean isSSL, MailLogger logger) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a response handler.Response[]Send a command to the server.Return the SocketChannel associated with this connection, if any.Return the address the socket connected to.longReturns the timestamp.voidhandleResult(Response response) Convenience routine to handle OK, NO, BAD and BYE responses.booleanIs another response available in our buffer?booleanisSSL()Is this connection using an SSL socket?voidnotifyResponseHandlers(Response[] responses) Notify response handlersvoidRemoved the specified response handler.voidsimpleCommand(String cmd, Argument args) Convenience routine to handle simple IAP commands that do not have responses specific to that command.voidstartCompression(String cmd) Start compression on the current connection.voidStart TLS on the current connection.booleanDoes the server support UTF-8? This implementation returns false.writeCommand(String command, Argument args)
-
Constructor Details
-
Protocol
public Protocol(String host, int port, Properties props, String prefix, boolean isSSL, MailLogger logger) throws IOException, ProtocolException Constructor.Opens a connection to the given host at given port.
- Parameters:
host- host to connect toport- portnumber to connect toprops- Properties object used by this protocolprefix- Prefix to prepend to property keysisSSL- use SSL?logger- log messages here- Throws:
IOException- for I/O errorsProtocolException- for protocol failures
-
Protocol
public Protocol(InputStream in, PrintStream out, Properties props, boolean debug) throws IOException Constructor for debugging.- Parameters:
in- the InputStream to read fromout- the PrintStream to write toprops- Properties object used by this protocoldebug- true to enable debugging output- Throws:
IOException- for I/O errors
-
-
Method Details
-
getTimestamp
public long getTimestamp()Returns the timestamp.- Returns:
- the timestamp
-
addResponseHandler
Adds a response handler.- Parameters:
h- the response handler
-
removeResponseHandler
Removed the specified response handler.- Parameters:
h- the response handler
-
notifyResponseHandlers
Notify response handlers- Parameters:
responses- the responses
-
readResponse
- Throws:
IOExceptionProtocolException
-
hasResponse
public boolean hasResponse()Is another response available in our buffer?- Returns:
- true if another response is in the buffer
- Since:
- JavaMail 1.5.4
-
writeCommand
- Throws:
IOExceptionProtocolException
-
command
Send a command to the server. Collect all responses until either the corresponding command completion response or a BYE response (indicating server failure). Return all the collected responses.- Parameters:
command- the commandargs- the arguments- Returns:
- array of Response objects returned by the server
-
handleResult
Convenience routine to handle OK, NO, BAD and BYE responses.- Parameters:
response- the response- Throws:
ProtocolException- for protocol failures
-
simpleCommand
Convenience routine to handle simple IAP commands that do not have responses specific to that command.- Parameters:
cmd- the commandargs- the arguments- Throws:
ProtocolException- for protocol failures
-
startTLS
Start TLS on the current connection.cmdis the command to issue to start TLS negotiation. If the command succeeds, we begin TLS negotiation. If the socket is already an SSLSocket this is a nop and the command is not issued.- Parameters:
cmd- the command to issue- Throws:
IOException- for I/O errorsProtocolException- for protocol failures
-
startCompression
Start compression on the current connection.cmdis the command to issue to start compression. If the command succeeds, we begin compression.- Parameters:
cmd- the command to issue- Throws:
IOException- for I/O errorsProtocolException- for protocol failures
-
isSSL
public boolean isSSL()Is this connection using an SSL socket?- Returns:
- true if using SSL
- Since:
- JavaMail 1.4.6
-
getInetAddress
Return the address the socket connected to.- Returns:
- the InetAddress the socket is connected to
- Since:
- JavaMail 1.5.2
-
getChannel
Return the SocketChannel associated with this connection, if any.- Returns:
- the SocketChannel
- Since:
- JavaMail 1.5.2
-
supportsUtf8
public boolean supportsUtf8()Does the server support UTF-8? This implementation returns false. Subclasses should override as appropriate.- Returns:
- true if the server supports UTF-8
- Since:
- JavaMail 1.6.0
-