com.cometway.email
Class ReceivePOP3EmailAgent

java.lang.Object
  extended by com.cometway.props.Props
      extended by com.cometway.ak.Agent
          extended by com.cometway.ak.ScheduledAgent
              extended by com.cometway.email.ReceivePOP3EmailAgent
All Implemented Interfaces:
AgentInterface, HasStateMachineModel, ISchedulable

public class ReceivePOP3EmailAgent
extends ScheduledAgent

This agent periodically checks for new POP3 messages, passing routing the message to the registered RequestAgent matching the message recipient's email address.


Field Summary
 
Fields inherited from class com.cometway.ak.ScheduledAgent
schedule
 
Fields inherited from class com.cometway.ak.Agent
agent_id, agentController, CREATING_STATE, debugReporter, DESTROYED_STATE, DESTROYING_STATE, errorReporter, FAILED_STATE, printlnReporter, props, RUNNING_STATE, STARTING_STATE, STOPPED_STATE, STOPPING_STATE, warningReporter
 
Constructor Summary
ReceivePOP3EmailAgent()
           
 
Method Summary
protected  void closeConnection()
          Closes the connection to the POP3 server.
protected  boolean deleteMessage(int msg_num)
          Deletes the specified message from the POP3 server.
 void deliverMessage(IMessage m)
          This method creates an AgentRequest from the specified IMessage, and delivers it to the RequestAgent that is registered as the message recipient.
protected  java.util.Vector getAllMessages()
          Return a vector holding (Integer {msg_num},(String {msg_header},String {msg_body})).
protected  java.lang.String getLine()
          Reads a line of input from the POP3 server.
protected  IMessage getMessage(int msg_num)
          Downloads the specified message from the POP3 server and returns it as an IMessage.
protected  java.util.Vector getRange(int start, int stop)
          Return a vector holding (Integer {msg_num},(String {msg_header},String {msg_body})).
 void initProps()
          Initializes the default Props for this agent: "schedule" is specifies the schedule this agent uses to check the POP3 server (default: every 60 seconds), "pop3_host" is the POP3 server's host name (default: localhost), "pop3_port" is the POP3 server's port (default: 110), "username" is the POP3 account username, "password" is the POP3 account password, "max_trys" is the number of connection attempt to the POP3 server before giving up, "delete_messages" is set to true if the messages are to be deleted after downloading (default: true).
protected  int last()
          Returns the number of the highest message accesed.
protected  IntegerPair listMessage(int msg_num)
          This method lists a message on the POP3 server by its message number.
protected  java.util.Vector listMessages()
          Returns a vector of pairs.
protected  boolean logon(java.lang.String username, java.lang.String password)
          Sends the logon command to the POP3 server using the specified username and password.
protected  void noop()
          Sends a NOOP command to the POP3 server.
protected  boolean okResponse()
          Returns true if the server returned '+OK'.
protected  boolean okResponse(java.lang.String s)
          Return true if input String starts with '+OK'.
protected  void openConnection()
          Opens a connection to the POP3 server for the agent to use.
protected  java.util.Vector parseAllMessages(java.util.Vector v)
          Parses a Vector containing Pairs referencing message headers and bodies into a Vector of Hashtables containing message attributes including the message body.
protected  java.util.Hashtable parseMessage(Pair p)
          Parses the message header and body in the specified Pair into a Hashtable containing attributes, with the "body" attribute set to the specified body.
protected  java.util.Hashtable parseMessage(java.lang.String header, java.lang.String body)
          Parses the message header and body into a Hastable containing attributes, with the "body" attribute set to the specified body.
protected  void quit()
          End connection to server.
protected  void reset()
          Reset maildrop to previous state.
protected  int send(java.lang.String pop_msg)
          If connected, send a line to the server.
protected  IntegerPair splitInt(java.lang.String s)
           
protected  IntegerPair stat()
          Get the status of the current user.
 void wakeup()
          On wakeup, this agent connects to the POP3 server and downloads any new messages it finds.
 
Methods inherited from class com.cometway.ak.ScheduledAgent
addScheduleChangeListener, getSchedule, removeScheduleChangeListener, schedule, start, stop, unschedule
 
Methods inherited from class com.cometway.ak.Agent
currentStateEquals, debug, destroy, error, error, getAgentController, getDateTimeStr, getProps, getServiceImpl, getStateMachineModel, println, register, registerService, setAgentController, setProps, toString, unregister, unregisterService, warning, warning
 
Methods inherited from class com.cometway.props.Props
addListener, append, copy, copyFrom, copyTo, decrementInteger, dump, enableListeners, enumerateKeys, format, getBoolean, getByteArray, getCharacter, getDate, getDate, getDateString, getDouble, getFloat, getHexString, getInteger, getKeys, getLong, getNextKey, getProperty, getProperty, getPropsContainer, getSize, getString, getString, getTokens, getTokens, getTrimmedString, getVector, hasProperty, incrementInteger, insertProps, loadProps, notifyPropsChanged, notifyPropsChangedIgnore, notifyPropsChangedIgnore, parse, propertyMatchesRegEx, readFromFile, regExPropertyMatches, removeAll, removeListener, removeProperty, resumeNotify, saveProps, set, setBoolean, setCharacter, setDefault, setDouble, setFloat, setInteger, setLong, setProperty, setProperty, setProperty, setPropsContainer, suspendNotify, writeToFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ReceivePOP3EmailAgent

public ReceivePOP3EmailAgent()
Method Detail

initProps

public void initProps()
Initializes the default Props for this agent: "schedule" is specifies the schedule this agent uses to check the POP3 server (default: every 60 seconds), "pop3_host" is the POP3 server's host name (default: localhost), "pop3_port" is the POP3 server's port (default: 110), "username" is the POP3 account username, "password" is the POP3 account password, "max_trys" is the number of connection attempt to the POP3 server before giving up, "delete_messages" is set to true if the messages are to be deleted after downloading (default: true).

Specified by:
initProps in interface AgentInterface
Overrides:
initProps in class ScheduledAgent

wakeup

public void wakeup()
On wakeup, this agent connects to the POP3 server and downloads any new messages it finds. New messsages are delivered to RequestAgents using the deliverMessage method of this class.

Specified by:
wakeup in interface ISchedulable
Overrides:
wakeup in class ScheduledAgent

deliverMessage

public void deliverMessage(IMessage m)
This method creates an AgentRequest from the specified IMessage, and delivers it to the RequestAgent that is registered as the message recipient.


openConnection

protected void openConnection()
Opens a connection to the POP3 server for the agent to use.


deleteMessage

protected boolean deleteMessage(int msg_num)
Deletes the specified message from the POP3 server.


closeConnection

protected void closeConnection()
Closes the connection to the POP3 server.


getLine

protected java.lang.String getLine()
Reads a line of input from the POP3 server.


last

protected int last()
Returns the number of the highest message accesed.


listMessages

protected java.util.Vector listMessages()
Returns a vector of pairs. Each pair contains (int {msg_num} ,int {msg_size})


listMessage

protected IntegerPair listMessage(int msg_num)
This method lists a message on the POP3 server by its message number. Returns the pair (int {msg_num} ,int {msg_size})

Parameters:
msg_num - The message number to list.
Returns:
Returns an IntegerPair, first is the message number, second is the message size.

logon

protected boolean logon(java.lang.String username,
                        java.lang.String password)
Sends the logon command to the POP3 server using the specified username and password.


noop

protected void noop()
Sends a NOOP command to the POP3 server.


okResponse

protected boolean okResponse(java.lang.String s)
Return true if input String starts with '+OK'.


okResponse

protected boolean okResponse()
Returns true if the server returned '+OK'.


getAllMessages

protected java.util.Vector getAllMessages()
Return a vector holding (Integer {msg_num},(String {msg_header},String {msg_body})). This vector contains all the messages.


getRange

protected java.util.Vector getRange(int start,
                                    int stop)
Return a vector holding (Integer {msg_num},(String {msg_header},String {msg_body})). start - first message to get stop - last message to get


getMessage

protected IMessage getMessage(int msg_num)
Downloads the specified message from the POP3 server and returns it as an IMessage.


parseAllMessages

protected java.util.Vector parseAllMessages(java.util.Vector v)
Parses a Vector containing Pairs referencing message headers and bodies into a Vector of Hashtables containing message attributes including the message body.


parseMessage

protected java.util.Hashtable parseMessage(Pair p)
Parses the message header and body in the specified Pair into a Hashtable containing attributes, with the "body" attribute set to the specified body.


parseMessage

protected java.util.Hashtable parseMessage(java.lang.String header,
                                           java.lang.String body)
Parses the message header and body into a Hastable containing attributes, with the "body" attribute set to the specified body.


quit

protected void quit()
End connection to server.


reset

protected void reset()
Reset maildrop to previous state.


send

protected int send(java.lang.String pop_msg)
If connected, send a line to the server. pop_msg - the message to send to the server


splitInt

protected IntegerPair splitInt(java.lang.String s)

stat

protected IntegerPair stat()
Get the status of the current user. Returns a (,) int pair