HW3

Document Sample
HW3 Powered By Docstoc
					          COMP 431 — INTERNET SERVICES & PROTOCOLS

                                           Kevin Jeffay
                                           Spring 2011

                                   Homework 3, February 2

                                         Due: February 9
________________________________________________________________________

Even More Baby-steps Towards the Construction of an SMTP Server (The Final Step!)
In this assignment you will extend the program you developed for Homework 2 to perform the “reverse”
mail processing steps. By now you should have a program that receives and processes SMTP commands
from “an SMTP client” (this is what you are simulating when you type in commands from the keyboard)
and generates a “mailbox” file. This is the “server-side” processing that is done in an SMTP server. In
this assignment you will now extend your program to perform the “client-side” processing of the SMTP
server.

Specifically, your program will read a mailbox file (having the format of the file you created in
Homework 2) and generate and write to standard output the SMTP commands necessary to send the
contents of the mail messages in the mailbox file to a destination SMTP server. Your program should
both generate SMTP commands and listen for the SMTP response messages that a real server would emit
in response to your commands.

For example assume the following two email messages are the contents of a file named jeffay@cs.unc.edu
in the directory forward in the current working directory.
   From: <aikat@cs.unc.edu>
   To: <jeffay@cs.unc.edu>
   Hey Kevin, do you really think we should use SMTP as a class
   project in COMP 431 this year? The smart students are going to
   figure out automated ways to send anonymous SPAM to the world!
   From: <student-who-wants-to-get-an-A@cs.unc.edu>
   To: <jeffay@cs.unc.edu>
   Dude, I just wanted to tell you that I think these SMTP
   programming assignments are the coolest thing! I really like
   learning how a real-life protocol for a real-life Internet service
   really works.

   Thanks!

Your program would read the first message from the mailbox file and generate the following SMTP
commands:
   MAIL FROM: <aikat@cs.unc.edu>
   RCPT TO: <jeffay@cs.unc.edu>
                                                         2


      DATA
      Hey Kevin, do you really think we should use SMTP as a class
      project in COMP 431 this year? The smart students are going to
      figure out automated ways to send anonymous SPAM to the world!
      .

After outputting each SMTP command your program should pause and wait to receive an SMTP
response. You should parse the response and continue with the transmission of the mail message only if
you receive a positive acknowledgement (a 250 or 354 message). All of your program’s output should be
directed to standard output and, except for reading the mailbox file, all of of your program’s inputs should
be from standard input.

When parsing SMTP response messages you should only parse for the response number and ignore
whatever text is also sent with the response message. You should echo the SMTP response messages you
receive to standard output. Thus for the above message, if your program works correctly you should see
the following on standard output:1

      MAIL FROM: <aikat@cs.unc.edu>
      250 OK
      RCPT TO: <jeffay@cs.unc.edu>
      250 OK
      DATA
      354 Some random text…
      Hey Kevin, do you really think we should use SMTP as a class
      project in COMP 431 this year? The smart students are going to
      figure out automated ways to send anonymous SPAM to the world!
      .
      250 OK

Keep writing the contents of mail messages found in the mailbox file until end-of-file is reached on the
mailbox file. You can assume that the string “From:” at the beginning of a line indicates the start of a new
mail message. If you receive any error message from the SMTP server you should stop processing email,
emit the SMTP command QUIT and terminate your program.2 Similarly, when you have reached end-of-
file on the mailbox file you should emit the SMTP QUIT command and terminate your program.

Note that since your program will not be communicating with a real SMTP server you will have to
simulate the server by typing in the SMTP response messages after each command is output. That is, in
the example above, all of the 250 and 354 responses will have to be typed in by you.


Homework Requirements
Write a Java program to read the contents of a file that is specified as a command line argument. For now,
you may assume that this file contains well-formed email messages. A well-formed email message has
the form

      From: <reverse-path>
      To: <forward-path>


1To make this example more clear, standard input has been redirected to a file containing the appropriate set of
SMTP server response messages. If you were typing in the response messages from the keyboard the response
messages would appear twice on standard output.

2   The QUIT command has a trivial syntax. It’s just single word QUIT!
                                                           3


    An arbitrary number of lines of text. Text can be arbitrary but cannot consist of a period by itself at the start of
    a line.

(You may assume that each email message has only a single “To:” line in the header.) For each message
in the file:

•   Generate and emit the appropriate SMTP commands to send the message, waiting for the appropriate
    SMTP response message to be emitted after each command before proceeding.

•   After processing the last message, or should any errors be encountered during the processing of any
    message, emit the SMTP QUIT command.

Write all SMTP commands and data transmissions to standard output. Read the SMTP response messages
from standard input and echo to standard output.

As always, your program must not output any user prompts, debugging information, status messages, etc.


Grading
As per the instructions distributed with Homework 1, create a subdirectory named HW3 within the
directory ~/comp431/submissions, and place the final version of your program in this directory before the
due date. Please give your final program the name “SMTP2.java.” When your program is complete, send
mail to the TA (aikat@cs.unc.edu) with the subject line “COMP 431 HW3 ready.” Again, if you send
mail from an account other than your CS account, please indicate your Computer Science Unix account
login (user-id) in the body of the message.

Program(s) should be neatly formatted (i.e., easy to read) and well documented. In general, 75% of your
grade for a program will be for correctness, 25% for “programming style” (appropriate use of language
features, including variable/procedure/class names), and documentation (descriptions of functions,
general comments, use of invariants, pre- and post conditions where appropriate).

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:5
posted:11/25/2011
language:French
pages:3