org.subethamail.smtp.server
Class Session

java.lang.Object
  extended by java.lang.Thread
      extended by org.subethamail.smtp.server.Session
All Implemented Interfaces:
java.lang.Runnable, MessageContext

public class Session
extends java.lang.Thread
implements MessageContext

The thread that handles a connection. This class passes most of it's responsibilities off to the CommandHandler.

Author:
Jon Stevens, Jeff Schnitzer

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Session(SMTPServer server, java.net.Socket socket)
          Creates (but does not start) the thread object.
 
Method Summary
 void addRecipient()
           
 void closeSocket()
          Close the client socket if it is open
 AuthenticationHandler getAuthenticationHandler()
           
 boolean getHasMailFrom()
          Simple state
 MessageHandler getMessageHandler()
           
 java.io.InputStream getRawInput()
           
 CRLFTerminatedReader getReader()
           
 int getRecipientCount()
           
 java.net.SocketAddress getRemoteAddress()
           
 SMTPServer getServer()
           
 SMTPServer getSMTPServer()
           
 java.net.Socket getSocket()
          This method is only used by the start tls command
 boolean isAuthenticated()
           
 void quit()
          Triggers the shutdown of the thread and the closing of the connection.
 void resetMessageState()
          Some state is associated with each particular message (senders, recipients, the message handler).
 void run()
          The thread for each session runs on this and shuts down when the shutdown member goes true.
 void sendResponse(java.lang.String response)
          Sends the response to the client
 void setAuthenticationHandler(AuthenticationHandler handler)
          This is called by the AuthCommand when a session is successfully authenticated.
 void setHasMailFrom(boolean value)
           
 void setSocket(java.net.Socket socket)
          Initializes our reader, writer, and the i/o filter chains based on the specified socket.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Session

public Session(SMTPServer server,
               java.net.Socket socket)
        throws java.io.IOException
Creates (but does not start) the thread object.

Parameters:
server - a link to our parent
socket - is the socket to the client
Throws:
java.io.IOException
Method Detail

getServer

public SMTPServer getServer()
Returns:
a reference to the master server object

run

public void run()
The thread for each session runs on this and shuts down when the shutdown member goes true.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

setSocket

public void setSocket(java.net.Socket socket)
               throws java.io.IOException
Initializes our reader, writer, and the i/o filter chains based on the specified socket. This is called internally when we startup and when (if) SSL is started.

Throws:
java.io.IOException

getSocket

public java.net.Socket getSocket()
This method is only used by the start tls command

Returns:
the current socket to the client

closeSocket

public void closeSocket()
                 throws java.io.IOException
Close the client socket if it is open

Throws:
java.io.IOException

getRawInput

public java.io.InputStream getRawInput()
Returns:
the raw input stream from the client

getReader

public CRLFTerminatedReader getReader()
Returns:
the cooked CRLF-terminated reader from the client

sendResponse

public void sendResponse(java.lang.String response)
                  throws java.io.IOException
Sends the response to the client

Throws:
java.io.IOException

getRemoteAddress

public java.net.SocketAddress getRemoteAddress()
Specified by:
getRemoteAddress in interface MessageContext
Returns:
the IP address of the remote server.

getSMTPServer

public SMTPServer getSMTPServer()
Specified by:
getSMTPServer in interface MessageContext
Returns:
the SMTPServer object.

getMessageHandler

public MessageHandler getMessageHandler()
Returns:
the current message handler

getHasMailFrom

public boolean getHasMailFrom()
Simple state


setHasMailFrom

public void setHasMailFrom(boolean value)

addRecipient

public void addRecipient()

getRecipientCount

public int getRecipientCount()

isAuthenticated

public boolean isAuthenticated()

getAuthenticationHandler

public AuthenticationHandler getAuthenticationHandler()
Specified by:
getAuthenticationHandler in interface MessageContext
Returns:
the handler that was used to authenticate. You will probably want to upcast this object to the actual implementation to pull out information like user identity.

setAuthenticationHandler

public void setAuthenticationHandler(AuthenticationHandler handler)
This is called by the AuthCommand when a session is successfully authenticated. The handler will be an object created by the AuthenticationHandlerFactory.


resetMessageState

public void resetMessageState()
Some state is associated with each particular message (senders, recipients, the message handler). Some state is not; seeing hello, TLS, authentication.


quit

public void quit()
Triggers the shutdown of the thread and the closing of the connection.



Copyright © 2009 SubEthaSMTP. All Rights Reserved. Build version: UNVERSIONED