jSyncManager Simple Java Server

org.jSyncManager.SJS.Adapters.SMTPServer
Class AbstractSMTPServer

java.lang.Object
  extended by java.lang.Thread
      extended by org.jSyncManager.SJS.API.AbstractAdapter
          extended by org.jSyncManager.SJS.API.AbstractRequestResponseAdapter
              extended by org.jSyncManager.SJS.Adapters.SMTPServer.AbstractSMTPServer
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
SMTPServer, TestSMTPServer

public abstract class AbstractSMTPServer
extends AbstractRequestResponseAdapter

This is an abstract adapter to be used for handling smtp requests. This class will take case of parsing received command and ensuring that any state requirements for the entered commands are met before forwarding the command for action to the subclass implementation.

Version:
1.0
Author:
Jeff CROWE <jcrowe@uvic.ca>, Michael Walts <mwalts@uvic.ca>

Nested Class Summary
 class AbstractSMTPServer.CommandData
          Handles the DATA command
 class AbstractSMTPServer.CommandEhlo
          Handles the EHLO command
 class AbstractSMTPServer.CommandExpn
          Handles the EXPN command
 class AbstractSMTPServer.CommandHelo
          Handles the HELO command
 class AbstractSMTPServer.CommandHelp
          Handles the HELP command
 class AbstractSMTPServer.CommandMail
          Handles the MAIL command
 class AbstractSMTPServer.CommandNoop
          Handles the NOOP command
 class AbstractSMTPServer.CommandQuit
          Handles the QUIT command
 class AbstractSMTPServer.CommandRcpt
          Handles the RCPT command
 class AbstractSMTPServer.CommandRset
          Handles the RSET command
 class AbstractSMTPServer.CommandVrfy
          Handles the VRFY command
 class AbstractSMTPServer.SmtpCommand
          Handles the response of the system to a single command
static class AbstractSMTPServer.State
          Stores a mutable long for the masks which represent the state information
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected static java.lang.String atDomainRegex
          A string to provide the basic regex for a valid domain name preceeded by an '@'.
protected  java.util.HashMap<java.lang.String,AbstractSMTPServer.SmtpCommand> commands
          stores all the command strings mapped to the handlers for those string
protected  long currentMask
          bit used in construction of SmtpCommands, currently supports maximum 64 commands
protected static java.lang.String domainRegex
          A string to provide the basic regex for a valid domain name.
protected static java.lang.String INVALID_ADDR_SYNTAX
          String returned for invalid e-mail address syntax
protected static java.lang.String INVALID_SEQUENCE
          String returned for a command run out of sequence
protected static java.lang.String INVALID_SYNTAX
          String returned for invalid syntax
protected static java.util.regex.Pattern mailAddrExpr
          A pattern object for easily matching data within MAIL FROM: statements.
protected static java.lang.String PARAM_NOT_IMPLEMENTED
          String returned when a parameter is not implemented
protected static java.util.regex.Pattern rcptAddrExpr
          A pattern object for easily matching data within RCPT TO: statements.
protected static java.util.regex.Pattern relayPattern
          A pattern object for easily matching relays.
protected  AbstractSMTPServer.State state
          A bit mask field to store the current state of the connection being handled by this instance
protected static java.lang.String validEmailChars
          A string to provide a regex denoting the basic valid e-mail characters.
 
Fields inherited from class org.jSyncManager.SJS.API.AbstractAdapter
props
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AbstractSMTPServer()
          AbstractSMTPServer constructor, initializes the commands
 
Method Summary
 java.util.HashMap<java.lang.String,AbstractSMTPServer.SmtpCommand> getCommands()
           
protected  java.lang.String getConnectionHeaderString()
          General summary
 long getCurrentMask()
           
static java.util.regex.Pattern getMailAddrExpr()
           
static java.util.regex.Pattern getRcptAddrExpr()
           
 long getStateLong()
           
protected  void initCommands()
          Registers all of the available commands into the given map.
protected abstract  java.lang.String processData()
          Processes a syntactically correct DATA command
protected abstract  java.lang.String processEhlo(java.lang.String args)
          Processes a syntactically correct EHLO command
protected abstract  java.lang.String processExpn(java.lang.String args)
          Processes a syntactically correct EXPN command
protected abstract  java.lang.String processHelo(java.lang.String args)
          Processes a syntactically correct HELO command
protected abstract  java.lang.String processHelp(java.lang.String args)
          Processes a syntactically correct HELP command
protected abstract  java.lang.String processMail(java.lang.String args)
          Processes a syntactically correct MAIL command
protected abstract  java.lang.String processMessageFinished()
          run at the end of a message, after "." appears on a line by itself
protected abstract  void processMessagePart(java.lang.String args)
          Processes a string received while in the DATA state
protected abstract  java.lang.String processNoop()
          Processes NOOP command
protected abstract  java.lang.String processQuit()
          Processes a syntactically correct QUIT command
protected abstract  java.lang.String processRcpt(java.util.List<java.lang.String> relays, java.lang.String addr)
          Processes a syntactically correct RCPT command.
protected  java.lang.String processRequest(java.lang.String request)
          Implementation of the processRequest method from AbstractResponseAdapter.
protected abstract  java.lang.String processRset()
          Processes a syntactically correct RSET command
protected abstract  java.lang.String processVrfy(java.lang.String args)
          Processes a syntactically correct VRFY command
 
Methods inherited from class org.jSyncManager.SJS.API.AbstractRequestResponseAdapter
disconnect, getTimeoutMessage, processConnection
 
Methods inherited from class org.jSyncManager.SJS.API.AbstractAdapter
connectionPermitted, getConnectionManagerInterface, getInetAddress, getLogManager, getProperty, processConnection, run, setLogManager, setThreadGroup
 
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
 

Field Detail

INVALID_SYNTAX

protected static final java.lang.String INVALID_SYNTAX
String returned for invalid syntax

See Also:
Constant Field Values

INVALID_ADDR_SYNTAX

protected static final java.lang.String INVALID_ADDR_SYNTAX
String returned for invalid e-mail address syntax

See Also:
Constant Field Values

INVALID_SEQUENCE

protected static final java.lang.String INVALID_SEQUENCE
String returned for a command run out of sequence

See Also:
Constant Field Values

PARAM_NOT_IMPLEMENTED

protected static final java.lang.String PARAM_NOT_IMPLEMENTED
String returned when a parameter is not implemented

See Also:
Constant Field Values

validEmailChars

protected static final java.lang.String validEmailChars
A string to provide a regex denoting the basic valid e-mail characters.

See Also:
Constant Field Values

domainRegex

protected static final java.lang.String domainRegex
A string to provide the basic regex for a valid domain name.

See Also:
Constant Field Values

atDomainRegex

protected static final java.lang.String atDomainRegex
A string to provide the basic regex for a valid domain name preceeded by an '@'.

See Also:
Constant Field Values

rcptAddrExpr

protected static final java.util.regex.Pattern rcptAddrExpr
A pattern object for easily matching data within RCPT TO: statements.


mailAddrExpr

protected static final java.util.regex.Pattern mailAddrExpr
A pattern object for easily matching data within MAIL FROM: statements.


relayPattern

protected static final java.util.regex.Pattern relayPattern
A pattern object for easily matching relays.


commands

protected java.util.HashMap<java.lang.String,AbstractSMTPServer.SmtpCommand> commands
stores all the command strings mapped to the handlers for those string


state

protected AbstractSMTPServer.State state
A bit mask field to store the current state of the connection being handled by this instance


currentMask

protected long currentMask
bit used in construction of SmtpCommands, currently supports maximum 64 commands

Constructor Detail

AbstractSMTPServer

public AbstractSMTPServer()
AbstractSMTPServer constructor, initializes the commands

Method Detail

initCommands

protected void initCommands()
Registers all of the available commands into the given map. through the SmtpCommand constructor


processRequest

protected java.lang.String processRequest(java.lang.String request)
                                   throws java.lang.Exception
Implementation of the processRequest method from AbstractResponseAdapter. This method will get which command handler should be used from the commands map (filled by registerCommands), and delegates the processing of the command to that handler.

Specified by:
processRequest in class AbstractRequestResponseAdapter
Parameters:
request - parameter value
Returns:
returned
Throws:
java.lang.Exception - exception

processHelo

protected abstract java.lang.String processHelo(java.lang.String args)
                                         throws java.lang.Exception
Processes a syntactically correct HELO command

Parameters:
args - parameter value
Returns:
the appropriate response to this command
Throws:
java.lang.Exception - exception

processEhlo

protected abstract java.lang.String processEhlo(java.lang.String args)
                                         throws java.lang.Exception
Processes a syntactically correct EHLO command

Parameters:
args - parameter value
Returns:
the appropriate response to this command
Throws:
java.lang.Exception - exception

processMail

protected abstract java.lang.String processMail(java.lang.String args)
Processes a syntactically correct MAIL command

Parameters:
args - The parameters passed to this command
Returns:
the appropriate response to this command

processRcpt

protected abstract java.lang.String processRcpt(java.util.List<java.lang.String> relays,
                                                java.lang.String addr)
Processes a syntactically correct RCPT command.

Parameters:
relays - a list of relays.
addr - The parameters passed to this command.
Returns:
the appropriate response to this command.

processData

protected abstract java.lang.String processData()
Processes a syntactically correct DATA command

Returns:
the appropriate response to this command

processMessagePart

protected abstract void processMessagePart(java.lang.String args)
Processes a string received while in the DATA state

Parameters:
args - The current part of the e-mail message

processMessageFinished

protected abstract java.lang.String processMessageFinished()
run at the end of a message, after "." appears on a line by itself

Returns:
the appropriate response to this command

processRset

protected abstract java.lang.String processRset()
Processes a syntactically correct RSET command

Returns:
the appropriate response to this command

processVrfy

protected abstract java.lang.String processVrfy(java.lang.String args)
Processes a syntactically correct VRFY command

Parameters:
args - The parameters passed to this command
Returns:
the appropriate response to this command

processExpn

protected abstract java.lang.String processExpn(java.lang.String args)
Processes a syntactically correct EXPN command

Parameters:
args - The parameters passed to this command
Returns:
the appropriate response to this command

processHelp

protected abstract java.lang.String processHelp(java.lang.String args)
Processes a syntactically correct HELP command

Parameters:
args - The parameters passed to this command
Returns:
the appropriate response to this command

processQuit

protected abstract java.lang.String processQuit()
                                         throws java.lang.Exception
Processes a syntactically correct QUIT command

Returns:
the appropriate response to this command
Throws:
java.lang.Exception - exception

processNoop

protected abstract java.lang.String processNoop()
Processes NOOP command

Returns:
the appropriate response to this command

getConnectionHeaderString

protected java.lang.String getConnectionHeaderString()
General summary

Overrides:
getConnectionHeaderString in class AbstractRequestResponseAdapter
Returns:
returned

getRcptAddrExpr

public static java.util.regex.Pattern getRcptAddrExpr()

getMailAddrExpr

public static java.util.regex.Pattern getMailAddrExpr()

getCommands

public java.util.HashMap<java.lang.String,AbstractSMTPServer.SmtpCommand> getCommands()

getStateLong

public long getStateLong()

getCurrentMask

public long getCurrentMask()

jSyncManager Simple Java Server

Copyright (c) 2004 Brad BARCLAY. All Rights Reserved.