Package davmail

Class AbstractConnection

java.lang.Object
java.lang.Thread
davmail.AbstractConnection
All Implemented Interfaces:
Closeable, AutoCloseable, Runnable
Direct Known Subclasses:
CaldavConnection, ImapConnection, LdapConnection, PopConnection, SmtpConnection

public abstract class AbstractConnection extends Thread implements Closeable
Generic connection common to pop3 and smtp implementations
  • Field Details

  • Constructor Details

    • AbstractConnection

      public AbstractConnection(String name, Socket clientSocket)
      Only set the thread name and socket
      Parameters:
      name - thread type name
      clientSocket - client socket
    • AbstractConnection

      public AbstractConnection(String name, Socket clientSocket, String encoding)
      Initialize the streams and set a thread name.
      Parameters:
      name - thread type name
      clientSocket - client socket
      encoding - socket stream encoding
  • Method Details

    • logConnection

      public void logConnection(String action, String userName)
    • sendClient

      public void sendClient(String message) throws IOException
      Send the provided message to the client followed by CRLF.
      Parameters:
      message - message
      Throws:
      IOException - on error
    • sendClient

      public void sendClient(String prefix, String message) throws IOException
      Send prefix and message to the client followed by CRLF.
      Parameters:
      prefix - prefix
      message - message
      Throws:
      IOException - on error
    • sendClient

      public void sendClient(byte[] messageBytes) throws IOException
      Send all bytes to the client.
      Parameters:
      messageBytes - content
      Throws:
      IOException - on error
    • sendClient

      public void sendClient(byte[] messageBytes, int offset, int length) throws IOException
      Send only bytes to the client.
      Parameters:
      messageBytes - content
      offset - the start offset in the data.
      length - the number of bytes to write.
      Throws:
      IOException - on error
    • readClient

      public String readClient() throws IOException
      Read a line from the client connection. Log message to logger
      Returns:
      command line or null
      Throws:
      IOException - when unable to read the next line
    • close

      public void close()
      Close client connection, streams, and Exchange session.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable