Class MailServerSimulator

java.lang.Object
  extended by MailServerSimulator

public class MailServerSimulator
extends java.lang.Object

This class simulates the message sending and delivery actions of an email server. A limited number of received message are simulated (about 15). After they are delivered, the server will not deliver additional messages. (You are encouraged to simulate previously received/composed messages. These messages will simulate past use of the program.)

Some messages are SPAM, some are not sent to the user specifically (i.e., sent via a mailing list), and some belong to a common thread of discussion; handle these as you see fit.

This class also simulates incorrect logins, connection problems, and slow connections. Your GUI program should gracefully accomodate such issues.


Nested Class Summary
static class MailServerSimulator.IncorrectLoginException
          This exception is thrown to simulate a login attempt with incorrect credentials.
static class MailServerSimulator.Message
          This class encapsulates a mail message from the simulated mail server.
static class MailServerSimulator.UnableToConnectException
          This exception is thrown to simulate a problem connecting to the server.
 
Constructor Summary
MailServerSimulator(java.lang.String username)
          Initializes the simulator.
 
Method Summary
 MailServerSimulator.Message[] getNewMessages(java.lang.String password)
          Returns an array of (new) messages from the server.
 java.lang.String getPassword()
          Returns the current password.
 boolean sendMessage(java.lang.String from, java.lang.String to, java.lang.String cc, java.lang.String bcc, java.util.Date date, java.lang.String subject, java.lang.String body)
          Simulates sending of an email message.
 boolean setPassword(java.lang.String newPassword)
          Sets the password for the mail account.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MailServerSimulator

public MailServerSimulator(java.lang.String username)
Initializes the simulator. The passed username will appear in the recipient field of messages.

Parameters:
username - the recipient's username
Method Detail

getPassword

public java.lang.String getPassword()
Returns the current password.


setPassword

public boolean setPassword(java.lang.String newPassword)
Sets the password for the mail account.

Parameters:
newPassword - the new password
Returns:
true iff successful

sendMessage

public boolean sendMessage(java.lang.String from,
                           java.lang.String to,
                           java.lang.String cc,
                           java.lang.String bcc,
                           java.util.Date date,
                           java.lang.String subject,
                           java.lang.String body)
                    throws MailServerSimulator.UnableToConnectException
Simulates sending of an email message.

Parameters:
from - the sender information
to - the recipient information
cc - the carbon-copy information
bcc - the blind carbon-copy information
date - the timestamp information
subject - the subject information
body - the message body
Returns:
true iff successfil
Throws:
MailServerSimulator.UnableToConnectException

getNewMessages

public MailServerSimulator.Message[] getNewMessages(java.lang.String password)
                                             throws MailServerSimulator.IncorrectLoginException,
                                                    MailServerSimulator.UnableToConnectException
Returns an array of (new) messages from the server. See the aforementioned issues that are simulated.

Parameters:
password - the password for the account
Returns:
an array of new messages received by the mail server for the recipient.
Throws:
MailServerSimulator.IncorrectLoginException
MailServerSimulator.UnableToConnectException