org.abstracthorizon.mercury.smtp
Class SMTPSession

java.lang.Object
  extended by org.abstracthorizon.danube.connection.ConnectionWrapper
      extended by org.abstracthorizon.mercury.smtp.SMTPSession
All Implemented Interfaces:
org.abstracthorizon.danube.adapter.Adaptable, org.abstracthorizon.danube.connection.Connection

public class SMTPSession
extends org.abstracthorizon.danube.connection.ConnectionWrapper

SMTP connection which represents SMTP session.

Author:
Daniel Sendula

Field Summary
protected  long created
          When session is created
protected  MailSessionData data
          Session data
protected  SMTPCommandFactory factory
          Cached reference to command factory
protected  InputStream inputStream
          Cached input stream
protected  long lastAccessed
          When session is accessed
static org.slf4j.Logger logger
          Logger
protected  TempStorage mail
          Temporary storage for receiving mail
protected  SMTPConnectionHandler parent
          Connection handler that created this connection
protected  SMTPScanner scanner
          Scanner object to be used
protected  int state
          State of the session.
static int STATE_CONNECTED
          Session is connected - no command is received yet
static int STATE_MAIL
          Receiving RCPT TO and DATA commands
static int STATE_READY
          EHLO is received - waiting for MAIL FROM
static int STATE_UNKNOWN
          State is not defined - UNKNOWN state
static SimpleDateFormat USER_READABLE_FORMAT
          Human readable format
 
Fields inherited from class org.abstracthorizon.danube.connection.ConnectionWrapper
connection
 
Constructor Summary
SMTPSession(org.abstracthorizon.danube.connection.Connection connection, SMTPConnectionHandler parent)
          Constructor
 
Method Summary
 void close()
          Closes the session (connection)
 SMTPCommandFactory getCommandFactory()
          Returns command factory that is used
 SMTPConnectionHandler getConnectionHandler()
          Returns refernece to handler that created this session
 OutputStream getDebugStream()
          Returns debug output stream or null
 InputStream getInputStream()
          Returns cached input stream
 MailSessionData getMailSessionData()
          Returns mail session data object
 SMTPScanner getScanner()
          Returns scanner object
 long getSessionAccessed()
          Returns time when the session is last accessed
 String getSessionAccessedString()
          Returns time when the session is last accessed in the human readable format
 long getSessionCreated()
          Returns time when the session is created
 String getSessionCreatedString()
          Returns time when the session is created in human readable format
 int getState()
          Returns session's state
 boolean isKeepLog()
          Returns shell logs be kept after session is finished
 boolean isStreamDebug()
          Returns if logging is enabled
 void resetLastAccessed()
          Resets last accessed time
 void sendResponse(SMTPResponse response)
          Sets SMTP response back
 void setCommandFactory(SMTPCommandFactory factory)
          Sets command factory to be used
 void setKeepLog(boolean keepLog)
          Should we keep log after the session is finished
 void setState(int state)
          Sets session's state
 void setStreamDebug(boolean debug)
          Sets debug stream's logging attribute (LoggingConnection.setLogging(boolean) if any.
 void writeLogMessage(String msg)
          Helper function to write messaage to the log stream
 
Methods inherited from class org.abstracthorizon.danube.connection.ConnectionWrapper
adapt, isClosed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USER_READABLE_FORMAT

public static final SimpleDateFormat USER_READABLE_FORMAT
Human readable format


logger

public static org.slf4j.Logger logger
Logger


STATE_UNKNOWN

public static final int STATE_UNKNOWN
State is not defined - UNKNOWN state

See Also:
Constant Field Values

STATE_CONNECTED

public static final int STATE_CONNECTED
Session is connected - no command is received yet

See Also:
Constant Field Values

STATE_READY

public static final int STATE_READY
EHLO is received - waiting for MAIL FROM

See Also:
Constant Field Values

STATE_MAIL

public static final int STATE_MAIL
Receiving RCPT TO and DATA commands

See Also:
Constant Field Values

mail

protected TempStorage mail
Temporary storage for receiving mail


scanner

protected SMTPScanner scanner
Scanner object to be used


state

protected int state
State of the session. Defaults to STATE_UNKNOWN


data

protected MailSessionData data
Session data


parent

protected SMTPConnectionHandler parent
Connection handler that created this connection


inputStream

protected InputStream inputStream
Cached input stream


factory

protected SMTPCommandFactory factory
Cached reference to command factory


created

protected long created
When session is created


lastAccessed

protected long lastAccessed
When session is accessed

Constructor Detail

SMTPSession

public SMTPSession(org.abstracthorizon.danube.connection.Connection connection,
                   SMTPConnectionHandler parent)
            throws org.abstracthorizon.danube.connection.ConnectionException
Constructor

Parameters:
connection - underlay connection
parent - handler that created this session
Throws:
org.abstracthorizon.danube.connection.ConnectionException
Method Detail

setKeepLog

public void setKeepLog(boolean keepLog)
Should we keep log after the session is finished

Parameters:
keepLog - keep log

isKeepLog

public boolean isKeepLog()
Returns shell logs be kept after session is finished

Returns:
keep log

writeLogMessage

public void writeLogMessage(String msg)
Helper function to write messaage to the log stream

Parameters:
msg - message to be writen to log stream

setStreamDebug

public void setStreamDebug(boolean debug)
Sets debug stream's logging attribute (LoggingConnection.setLogging(boolean) if any.

Parameters:
debug - logging should start (true) or stop (false)

isStreamDebug

public boolean isStreamDebug()
Returns if logging is enabled

Returns:
is logging enabled

getDebugStream

public OutputStream getDebugStream()
Returns debug output stream or null

Returns:
debug output stream or null

getInputStream

public InputStream getInputStream()
Returns cached input stream

Returns:
cached input stream

setState

public void setState(int state)
Sets session's state

Parameters:
state - new session's state

getState

public int getState()
Returns session's state

Returns:
session's state

getScanner

public SMTPScanner getScanner()
Returns scanner object

Returns:
scanner object

getMailSessionData

public MailSessionData getMailSessionData()
Returns mail session data object

Returns:
mail session data object

getConnectionHandler

public SMTPConnectionHandler getConnectionHandler()
Returns refernece to handler that created this session

Returns:
refernece to handler that created this session

close

public void close()
Closes the session (connection)

Specified by:
close in interface org.abstracthorizon.danube.connection.Connection
Overrides:
close in class org.abstracthorizon.danube.connection.ConnectionWrapper

sendResponse

public void sendResponse(SMTPResponse response)
                  throws IOException
Sets SMTP response back

Parameters:
response - response
Throws:
IOException

setCommandFactory

public void setCommandFactory(SMTPCommandFactory factory)
Sets command factory to be used

Parameters:
factory - command factory to be used

getCommandFactory

public SMTPCommandFactory getCommandFactory()
Returns command factory that is used

Returns:
command factory that is used

getSessionCreated

public long getSessionCreated()
Returns time when the session is created

Returns:
time when the session is created

getSessionCreatedString

public String getSessionCreatedString()
Returns time when the session is created in human readable format

Returns:
time when the session is created in human readable format

getSessionAccessed

public long getSessionAccessed()
Returns time when the session is last accessed

Returns:
time when the session is last accessed

getSessionAccessedString

public String getSessionAccessedString()
Returns time when the session is last accessed in the human readable format

Returns:
time when the session is last accessed

resetLastAccessed

public void resetLastAccessed()
Resets last accessed time



Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.