com.sun.mail.iap
Class Protocol

java.lang.Object
  extended by com.sun.mail.iap.Protocol
Direct Known Subclasses:
IMAPProtocol

public class Protocol
extends java.lang.Object

General protocol handling code for IMAP-like protocols.

The Protocol object is multithread safe.

Version:
1.39, 07/06/01
Author:
John Mani, Max Spivak, Bill Shannon

Field Summary
protected  boolean debug
           
protected  java.lang.String host
           
protected  java.io.PrintStream out
           
protected  java.lang.String prefix
           
protected  java.util.Properties props
           
protected  boolean quote
           
 
Constructor Summary
Protocol(java.io.InputStream in, java.io.OutputStream out, boolean debug)
          Constructor for debugging.
Protocol(java.lang.String host, int port, boolean debug, java.io.PrintStream out, java.util.Properties props, java.lang.String prefix, boolean isSSL)
          Constructor.
 
Method Summary
 void addResponseHandler(ResponseHandler h)
          Adds a response handler.
 Response[] command(java.lang.String command, Argument args)
          Send a command to the server.
protected  void disconnect()
          Disconnect.
protected  void finalize()
          Finalizer.
protected  ResponseInputStream getInputStream()
          Return the Protocol's InputStream.
protected  java.io.OutputStream getOutputStream()
          Return the Protocol's OutputStream
protected  ByteArray getResponseBuffer()
          Return a buffer to be used to read a response.
 long getTimestamp()
          Returns the timestamp.
 void handleResult(Response response)
          Convenience routine to handle OK, NO, BAD and BYE responses.
 void notifyResponseHandlers(Response[] responses)
          Notify response handlers
protected  void processGreeting(Response r)
           
 Response readResponse()
           
 void removeResponseHandler(ResponseHandler h)
          Removed the specified response handler.
 void simpleCommand(java.lang.String cmd, Argument args)
          Convenience routine to handle simple IAP commands that do not have responses specific to that command.
 void startTLS(java.lang.String cmd)
          Start TLS on the current connection.
protected  boolean supportsNonSyncLiterals()
          Returns whether this Protocol supports non-synchronizing literals Default is false.
 java.lang.String writeCommand(java.lang.String command, Argument args)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

host

protected java.lang.String host

debug

protected boolean debug

quote

protected boolean quote

out

protected java.io.PrintStream out

props

protected java.util.Properties props

prefix

protected java.lang.String prefix
Constructor Detail

Protocol

public Protocol(java.lang.String host,
                int port,
                boolean debug,
                java.io.PrintStream out,
                java.util.Properties props,
                java.lang.String prefix,
                boolean isSSL)
         throws java.io.IOException,
                ProtocolException
Constructor.

Opens a connection to the given host at given port.

Parameters:
host - host to connect to
port - portnumber to connect to
debug - debug mode
out - debug output stream
props - Properties object used by this protocol
prefix - Prefix to prepend to property keys
Throws:
java.io.IOException
ProtocolException

Protocol

public Protocol(java.io.InputStream in,
                java.io.OutputStream out,
                boolean debug)
         throws java.io.IOException
Constructor for debugging.

Throws:
java.io.IOException
Method Detail

getTimestamp

public long getTimestamp()
Returns the timestamp.


addResponseHandler

public void addResponseHandler(ResponseHandler h)
Adds a response handler.


removeResponseHandler

public void removeResponseHandler(ResponseHandler h)
Removed the specified response handler.


notifyResponseHandlers

public void notifyResponseHandlers(Response[] responses)
Notify response handlers


processGreeting

protected void processGreeting(Response r)
                        throws ProtocolException
Throws:
ProtocolException

getInputStream

protected ResponseInputStream getInputStream()
Return the Protocol's InputStream.


getOutputStream

protected java.io.OutputStream getOutputStream()
Return the Protocol's OutputStream


supportsNonSyncLiterals

protected boolean supportsNonSyncLiterals()
Returns whether this Protocol supports non-synchronizing literals Default is false. Subclasses should override this if required


readResponse

public Response readResponse()
                      throws java.io.IOException,
                             ProtocolException
Throws:
java.io.IOException
ProtocolException

getResponseBuffer

protected ByteArray getResponseBuffer()
Return a buffer to be used to read a response. The default implementation returns null, which causes a new buffer to be allocated for every response.

Since:
JavaMail 1.4.1

writeCommand

public java.lang.String writeCommand(java.lang.String command,
                                     Argument args)
                              throws java.io.IOException,
                                     ProtocolException
Throws:
java.io.IOException
ProtocolException

command

public Response[] command(java.lang.String command,
                          Argument args)
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 command
args - the arguments
Returns:
array of Response objects returned by the server

handleResult

public void handleResult(Response response)
                  throws ProtocolException
Convenience routine to handle OK, NO, BAD and BYE responses.

Throws:
ProtocolException

simpleCommand

public void simpleCommand(java.lang.String cmd,
                          Argument args)
                   throws ProtocolException
Convenience routine to handle simple IAP commands that do not have responses specific to that command.

Throws:
ProtocolException

startTLS

public void startTLS(java.lang.String cmd)
              throws java.io.IOException,
                     ProtocolException
Start TLS on the current connection. cmd is the command to issue to start TLS negotiation. If the command succeeds, we begin TLS negotiation.

Throws:
java.io.IOException
ProtocolException

disconnect

protected void disconnect()
Disconnect.


finalize

protected void finalize()
                 throws java.lang.Throwable
Finalizer.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable


Copyright © 2011. All Rights Reserved.