You are on page 1of 6

!"#$%&! !"#$%&!!"#!!!!"#$%!

"
Steven R. Bagley, Colin Higgins & Stephen Nutbrown

!"#$%&'(#)%"*
For the G52APR coursework, you are to develop a POP3 email server. Details of the POP3 protocol can be found at http://www.apps.ietf.org/rfc/rfc1939.html, and a basic introduction to what is expected was given in lectures. Briefly, your program should open up a listen socket that POP3 clients (e.g. an email program such as Thunderbird) can connect t o in order to access email. To aid with the design of your system the coursework is divided into three components, each of which can be completed (more or less) independently, and then glued together to form the final system. The three components are:

+,*-%../"&*!"#0$1$0#0$*
Converts the POP3 commands coming from the network connection into method calls to the database backend and generates the responses to send back along the network connection.

2,*30#4%$5*
Opens a network connection to listen for incoming connections from the email program. This should support more than one concurrent connection so will need to use threading.

6,*7/#/8/90* :/(50"&*
The emails will be stored in a standard SQL database, in this part of the program you will need to fetch the relevant emails from the database using the Java database APIs in response to the method calls from the Command Interpreter. As with all large pieces of software, one of the most important tasks is to define the interfaces that the different pieces use to interact, and you should take some time to think about how these are going to work (although you will be able to change earlier sections of your program as you develop the later sections, if you so desire). The interface between the network component and command interpreter is relatively simple. Each active network connection will have a command interpreter object that it will call handleInput on to pass it a string containing the next command received from the client. However, the interface between the Command Interpreter and the Database backend will need to be more formal, using a normal Java interface. This is so that you can develop the command interpreter independently of the database backend. Once you have worked out the methods that the interface will need to support, you can create a dummy, minimal implementation of this interface that can be used to test your interpreter. In effect, we are using the strategy pattern here. We could vary how your server stores its email just by creating a new implementation of the interface (which, say, reads the emails from files stored on disk rather than a database). The rest of this document w i l l expand on what is expected for each component of the coursework, including what that components functionality should be, its deliverables and the hand-in date for those deliverables. For now only part 1 is included.

+, *-%../"&*!"#0$1$0#0$*
Due in: 17:00, 8th November 2013. For this section of the coursework you are to write the command interpreter. This will handle the POP3 commands (a list of which POP3 commands that should be supported are given in the appendix) that are sent to the POP3 server over the network connection from the POP3 client. In the final system the network section will already have converted the commands from a sequence of bytes (octets, in network speak) into a Java String. Later, you will write the part of the program that creates the POP3s server network socket and handles incoming connections from the various POP3 clients, but for now, you can test this program by reading a string (containing a valid command) from the keyboard and/or using JUnit tests.

+,+,

;0<')$0.0"#9*

Definition of a Java interface that the Command Interpreter will use to inform the database backend (by calling methods on an object implementing this interface) of commands received by the network channel. A class which can be used to create a Command Interpreter object for each active connection. Internally, this class may use other objects to complete the process but these should not be exposed to the rest of the program. This class must implement the method String handleInput(String input)as the method which receives messages from the network part of your work (part 2). The class should be named CommandInterpreter. This class should also have a constructor with no parameters to enable easy execution during marking. This object should support a method that can be called by the Network component to handle the input from the client and will have one parameter a string containing single command to be interpreted. The ability to return a (possibly multiline) response to the network section. A dummy testing class which temporarily replaces the database class (to be produced in part 3) and simply returns a suitable string for each request (see section 1.4 Output below). POP3 sends commands over the network connection in ASCII with each command on one line, these will have been converted into Strings by the Network section. Your command interpreter will be presented (by calls to its method) with each command as a string. It will need to do several tasks. Firstly, it will need to work out which command has been received (RETR, or USER, for instance). Once this has been done it has to ensure that any parameters required by the command are present, and correct. Then it must convert them into a relevant Java type (for example, RETR takes a message id as a parameter, this is an integer number so should be converted to an int). You should make use of any of the Java text processing APIs to handle this. Once the string has been parsed, you should then call the relevant methods via the interface that links to the backend (which you will need to design in part 3 and which has the testing class in for part 1) to fetch the relevant details from the database. The result of this call should then be packaged up as a correct POP3 response to the client (e.g. if the client tries to use RETR to access a non-existent message then the client should return an error response as defined in the RFC). Your command interpreter should also make sure that it keeps the correct state, i.e. you should not allow the USER and PASS commands to be executed once the client has successfully authenticated itself.

+,2,

!"#0$=/(0* 709)>"*

You will need to work out what are the minimal set of methods you will need your backend to provide to support the POP3 commands. There does not necessarily need to be a one-toone mapping between POP3 commands and a method on the interface. For example, it would be perfectly possible to map the RETR command and the TOP command to the same

method (either that the command interpreter truncates the response from the backend for TOP, or that it passes a special value to ask for all lines of the message to be returned from the backend).

+,6,

?09#)">*

You will want to test your implementation of the command interpreter. The easiest way to do this is to write a small test harness (similar to those you wrote in Introduction to Software Engineering last year). This test harness could work in a variety of ways and we leave it to you to chose the most appropriate and briefly justify the choice in a comment at the top of the class. It could read a line of text from the keyboard and feed it to your command interpreter as you will then be able to test your interpreter by typing the relevant POP3 commands in at the keyboard. The test harness could also have a fixed set of test cases hardcoded into it. You may also wish to consider the use of JUnit tests or something similar, or any other testing method you feel appropriate. You wont have a working implementation of the backend so you should develop a simple implementation of the interface that does just enough to let you test this section (for instance, you may just print out the name of the method called and return a dummy set of values).

+,@,

A'#1'#*

Your command interpreter should maintain the current state (AUTHORIZATION, TRANSACTION , UPDATE). To allow for your own testing, as well as allowing for us to test the functionality of your work, you should create a mock user in your mock database implementation with the credentials User: test Password: password You can now test to ensure your command interpreter is working properly. Including the test User (with Password password) is essential as we will be unable to test your software properly without it. To allow us to mark your work and to check you have called the correct methods in your command interpreter, please make sure that your output meets the following rules: Where the response from the command interpreter is flexible, you must include the request command and any parameters in the response. Where the response from the command interpreter is not flexible, you must make sure you meet the POP3 specification. Your mock implementation of your backend does not contain any mail, so commands such as DELE 1 or LIST 1 should result in a ERR status, but should still call the correct methods to your database interface.

See Note from section 9 of the protocol: "Note that with the exception of the STAT, LIST, and UIDL commands, the reply given by the POP3 server to any command is significant only to "+OK" and "-ERR". Any text occurring after this reply may be ignored by the client." This is where we would like you to make sure to add the command and parameters (See examples).

B%.0*0C/.1D09E*
FD0C)8D0* !"##$%&'#()**+,-# C: USER test

S: +OK anything you want to say, welcome test nice to meet you USER test. !+"#$%&'#()**+,-#./00)0"# C: USER dave S: -ERR Anything you want to say, Dave is not real x y z USER dave. 3%#*FD0C)8D0* !"#12%3#()**+,-# C: LIST S: +OK 0 messages (0 octets) 4"#%353#()**+,-# C: STAT S: +OK 0 0

+,G,

70D)H0$/8D09*

You should deliver the following via Moodle (also see Marking Criteria). A zip file containing the source code to your Command Interpreter and test suite Your Command Interpreter must be named exactly CommandInterpreter.java and must contain the method String handleInput(String input). All source files should be contained within a single directory. A short comment at the start of the class containing your main method explaining how your interpreter works and in particular, the interface you have defined for calling the Java backend.

Due in: 17:00, 22nd November 2013.

2,

30#4%$5*90(#)%"*

In this section of the coursework, you are to implement the network section of your POP3 server. It should open a listen socket on the local machine, on a port specified on the command line that starts your server. When a client connects to your server, you should accept the connection and route the input from the client to the Command Interpreter that you created in the previous section. Any responses generated by your Command Interpreter should be routed back to the client over the network connection.

2,+,

;0<')$0.0"#9*

When completed, the program you write for this stage of the coursework should: Open a network socket that is set to listen for incoming connections on a port. The port number should be passed to your server as a command argument (although port 110 is usually used for mail). Please name your class as Pop3Server.java. The server should take two parameters on the command line when it is started. The first is the port number. The second should be an integer representing a timeout value in seconds. This should default this to 600 seconds as per the pop3 specification. So to run your sever a typical command might be java Pop3Server 110 600 Accept multiple, concurrent, incoming connections from clients. Data from each client should be routed to a separate Command Interpreter object for each client and the responses from this object routed back to the correct client. When the Command Interpreter finishes the session, the network connection should be closed.

The connection should be terminated after a fixed length period of inactivity as given in the Pop3 specification.

2,2,

?09#)">*

You may test your server in anyway you feel appropriate; several methods have been mentioned in lectures. To test your server, you will almost certainly want to connect to it and send commands. There are three ways you can do this. The first, is to simply connect to it using the telnet program, which is available on the school UNIX systems, as well on Mac OS X and Linux. Unfortunately, it seems to have been removed in later versions of MS Windows and so you will need to download a program such as PuTTY to achieve the same thing. From a UNIX command prompt, however, you would want to type:
telnet <ip address> <port>

where <ip address> and <port> should be replaced with the relevant values. You will then be able to interactively type commands and see the responses from the POP3 server. You can simulate multiple connections to your server by running the client several times. The second approach to testing your POP3 server is to write a very simple Java program that connects to your server and issues a series of commands directly and responds to the result. The advantage of this approach is that the program will always issue a repeatable sequence of commands to the server, which may aid in debugging. You may also be able to use test data from part 1 if you do it this way. A third approach would be to use a real mail client such as Outlook or Thunderbird. Of course, JUnit tests, or equivalent, can be used at your discretion to test individual classes if you feel this is appropriate.

2,6,

I%&)=J)">*#K0* -%../"&*!"#0$1$0#0$*

You may find that while developing the network code that you wish to change the implementation of your Command Interpreter. Please feel free to make any changes that you think are necessary to make this fit with your network code. Your mark for the first piece of the coursework wont be altered by these later changes, however credit will be given for the explanation you give in the short report about why it was necessary to make these changes.

2,@,

70D)H0$/8D09*

You should deliver the following via Moodle (also see section 4. Marking Criteria). Source code for your network section, command interpreter and any test programs you have generated. A short comment at the start of the network class containing your main method explaining how your network code works and how it integrates with your Command Interpreter. IF you had to modify your Command Interpreter then you should include details of what you had to change and, in particular, why it was necessary to make those changes.

I/$5)">*($)#0$)/*
The coursework will marks available are split as follows: part 1: 30%, part 2: 35%, part 3: 35%. Marking criteria is based on class structure; correct use of the database interface; method structure; sensible logic; typographic appropriateness; functional correctness (adherence to the POP3 protocol provided); correct use of conventions and evidence of thorough testing.

It is vital that you check to make sure your work compiles on the school machines. Penalties will be given for work not submitted in the correct format and structure. Your source code should be submitted as a .zip file. You should not use packages for this work. The standard university policy for late submission applies for the first 6 days, after which there will be no late submissions.

LMMN37!X
Your program should support the following POP3 commands:
USER LIST RSET PASS RETR TOP QUIT DELE UIDL STAT NOOP

You might also like