com.cometway.net
Class ESMTPReceiver

java.lang.Object
  extended by java.lang.Thread
      extended by com.cometway.net.ESMTPReceiver
All Implemented Interfaces:
ICommandParser, java.lang.Runnable
Direct Known Subclasses:
ReceiveEmailHandler

public class ESMTPReceiver
extends java.lang.Thread
implements ICommandParser

This class implements the ESMTP protocol for the server side. It will listen to a socket and await connections that talk the ESMTP/SMTP protocol.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  java.util.Hashtable commandHash
           
protected  java.lang.String data
           
protected  boolean debug
           
protected  java.util.Vector extendedCommands
           
protected  java.util.Vector forwardPaths
           
protected  java.lang.String greeting
           
protected  boolean honestPeer
           
protected  java.io.BufferedReader in
           
static java.lang.String[] kBasicCommands
           
static java.lang.String kCommandUnrecognized
           
static java.lang.String kCRLF
           
static java.lang.String kDefaultGreeting
           
protected static int kMail
           
protected static int kRcpt
           
protected static int kRset
           
static java.lang.String kSyntaxError
           
protected static java.net.InetAddress localHost
           
protected static java.lang.String localHostName
           
protected  java.io.PrintWriter out
           
protected  java.lang.String reversePath
           
protected  boolean seenHelo
           
protected  boolean seenMail
           
protected  boolean seenRcpt
           
protected  java.net.InetAddress sendingHost
           
protected  java.net.Socket socket
           
protected  int state
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ESMTPReceiver()
          this constructor is for using an instance of this class only as an ICommandParser.
ESMTPReceiver(java.net.Socket socket)
           
 
Method Summary
 void addCommandParser(java.lang.String command, ICommandParser parser)
          addCommandParser adds an ICommandParser to extend the commands that it can parse by adding ICommandParsers for new commands.
 void addCommandParser(java.lang.String command, ICommandParser parser, boolean addExtended)
           
static boolean checkPath(java.lang.String path)
           
protected  void close()
           
protected  void debugPrint(java.lang.String line)
           
protected  void deliverMessage()
          deliverMessage(): method is gauranteed to be executed before state is cleared after a data command had been successfully accepted (but not necessarily responded to)
 void disconnect()
           
protected  void errorPrint(java.lang.String line)
           
protected static java.lang.String fixForwardPath(java.lang.String path)
          fixForwardPath: given a String representing a path, function attempts to prepare it for message delivery.
protected static java.lang.String fixReversePath(java.lang.String path)
           
protected  void initCommands()
           
 boolean isHeader(java.lang.String line)
           
static void main(java.lang.String[] argv)
           
 java.lang.String parseCommand(java.lang.String command)
          parse: method parses a command represented as a String of tokens, returning a String response.
protected  java.lang.String parseData(java.util.Enumeration command)
           
protected  java.lang.String parseEhlo(java.util.Enumeration command)
           
protected  java.lang.String parseHelo(java.util.Enumeration command)
           
protected  java.lang.String parseMail(java.lang.String commandString)
           
protected  java.lang.String parseNonRFCMail(java.util.Enumeration command)
           
protected  java.lang.String parseNonRFCRcpt(java.util.Enumeration command)
           
protected  java.lang.String parseNoop(java.util.Enumeration command)
           
protected  java.lang.String parseQuit(java.util.Enumeration command)
           
protected  java.lang.String parseRcpt(java.lang.String commandString)
           
protected  java.lang.String parseRset(java.util.Enumeration command)
           
protected  java.lang.String parseVrfy(java.util.Enumeration command)
           
protected  void prepareMessage()
          prepareMessage() should occur before routeMessage() and deliverMessage()
protected  java.lang.String read()
           
protected  void resetState()
           
protected  void routeMessage()
           
 void run()
           
 void setDebug(boolean debug)
           
 void setGreeting(java.lang.String greeting)
           
 void setSocket(java.net.Socket socket)
           
static java.lang.String stripBrackets(java.lang.String path)
          stripBrackets: given a path (possibly enclosed by angle brackets), method attempts to strip all enclosing brackets.
protected  void write(java.lang.String string)
           
 
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

kCRLF

public static final java.lang.String kCRLF
See Also:
Constant Field Values

kDefaultGreeting

public static final java.lang.String kDefaultGreeting
See Also:
Constant Field Values

kCommandUnrecognized

public static final java.lang.String kCommandUnrecognized
See Also:
Constant Field Values

kSyntaxError

public static final java.lang.String kSyntaxError
See Also:
Constant Field Values

kBasicCommands

public static final java.lang.String[] kBasicCommands

kMail

protected static final int kMail
See Also:
Constant Field Values

kRcpt

protected static final int kRcpt
See Also:
Constant Field Values

kRset

protected static final int kRset
See Also:
Constant Field Values

socket

protected java.net.Socket socket

in

protected java.io.BufferedReader in

out

protected java.io.PrintWriter out

commandHash

protected java.util.Hashtable commandHash

extendedCommands

protected java.util.Vector extendedCommands

greeting

protected java.lang.String greeting

seenHelo

protected boolean seenHelo

seenMail

protected boolean seenMail

seenRcpt

protected boolean seenRcpt

honestPeer

protected boolean honestPeer

state

protected int state

localHostName

protected static java.lang.String localHostName

localHost

protected static java.net.InetAddress localHost

sendingHost

protected java.net.InetAddress sendingHost

reversePath

protected java.lang.String reversePath

data

protected java.lang.String data

forwardPaths

protected java.util.Vector forwardPaths

debug

protected boolean debug
Constructor Detail

ESMTPReceiver

public ESMTPReceiver()
this constructor is for using an instance of this class only as an ICommandParser. the problem is that the parseData() method actually needs to use that in and out channels. but using this class as an ICommandParser no I/O streams need exist; so we build 'cheater' readers and writers that just do nothing


ESMTPReceiver

public ESMTPReceiver(java.net.Socket socket)
Method Detail

initCommands

protected void initCommands()

setSocket

public void setSocket(java.net.Socket socket)

setGreeting

public void setGreeting(java.lang.String greeting)

setDebug

public void setDebug(boolean debug)

addCommandParser

public void addCommandParser(java.lang.String command,
                             ICommandParser parser,
                             boolean addExtended)

addCommandParser

public void addCommandParser(java.lang.String command,
                             ICommandParser parser)
Description copied from interface: ICommandParser
addCommandParser adds an ICommandParser to extend the commands that it can parse by adding ICommandParsers for new commands. the String represents the new command to be parsed by the given ICommandParser

Specified by:
addCommandParser in interface ICommandParser

parseCommand

public java.lang.String parseCommand(java.lang.String command)
Description copied from interface: ICommandParser
parse: method parses a command represented as a String of tokens, returning a String response. the response might be used to indicate success or failure of different sorts, or state as a result of command

Specified by:
parseCommand in interface ICommandParser

resetState

protected void resetState()

parseData

protected java.lang.String parseData(java.util.Enumeration command)

parseEhlo

protected java.lang.String parseEhlo(java.util.Enumeration command)

parseHelo

protected java.lang.String parseHelo(java.util.Enumeration command)

parseNonRFCMail

protected java.lang.String parseNonRFCMail(java.util.Enumeration command)

parseMail

protected java.lang.String parseMail(java.lang.String commandString)

fixReversePath

protected static java.lang.String fixReversePath(java.lang.String path)

parseNoop

protected java.lang.String parseNoop(java.util.Enumeration command)

parseQuit

protected java.lang.String parseQuit(java.util.Enumeration command)

parseNonRFCRcpt

protected java.lang.String parseNonRFCRcpt(java.util.Enumeration command)

parseRcpt

protected java.lang.String parseRcpt(java.lang.String commandString)

fixForwardPath

protected static java.lang.String fixForwardPath(java.lang.String path)
fixForwardPath: given a String representing a path, function attempts to prepare it for message delivery.


checkPath

public static boolean checkPath(java.lang.String path)

stripBrackets

public static java.lang.String stripBrackets(java.lang.String path)
stripBrackets: given a path (possibly enclosed by angle brackets), method attempts to strip all enclosing brackets. this is bad since when we recreate the paths later, we will only add a single level of enclosing angle brackets


deliverMessage

protected void deliverMessage()
deliverMessage(): method is gauranteed to be executed before state is cleared after a data command had been successfully accepted (but not necessarily responded to)


routeMessage

protected void routeMessage()

prepareMessage

protected void prepareMessage()
prepareMessage() should occur before routeMessage() and deliverMessage()


isHeader

public boolean isHeader(java.lang.String line)

parseRset

protected java.lang.String parseRset(java.util.Enumeration command)

parseVrfy

protected java.lang.String parseVrfy(java.util.Enumeration command)

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

disconnect

public void disconnect()

read

protected java.lang.String read()

write

protected void write(java.lang.String string)

close

protected void close()

errorPrint

protected void errorPrint(java.lang.String line)

debugPrint

protected void debugPrint(java.lang.String line)

main

public static void main(java.lang.String[] argv)