E-mail Project: Listing the Headers

Assigned Wednesday, 1/23/02.
Due Monday 1/28/02, by 9:00PM.

Overview

For this assignment, you will write a program to scan through your email Inbox and display summary information about your messages.

Where your e-mail lives

Your email is contained in your "Inbox", which is located on Carleton College's mail servers. While you can't access this Inbox directly, I have written a method that will copy your Carleton Inbox to a text file that you can access. If you use Notepad to look at this file, you will see that every message in your Inbox is preceded by a big mess of information about who sent the e-mail, when it arrived, which computers handled it along the way, etc. All this information is called the e-mail's "header." The header for a message always begins with a line that starts with the word "From" followed by a space character. Your e-mail program (Mulberry, Outlook Express, etc.) recognizes when one message ends and the next message begins by looking for lines that begin with "From " (with a space after the "m"). Following that first line is a whole lot of header information, including three lines containing "From:" (with more detailed info on who the message is from), "To:", and "Subject:".

The assignment

For this assignment, you will write a method that searches through the Inbox file and prints:

(Note: An old version of the sample code that I provided had comments that contradicted the above four goals. I have since fixed the comments. If you downloaded the old version of the code, feel free to continue using it - but you should complete the assignment as stated here on the web page.)

To get started, create a BlueJ project called ListHeaders. Inside this project, create classes called BasicInbox and BasicInboxMain. As a starting point for these two classes, click on these links for BasicInbox and BasicInboxMain and copy and paste in the code. This code should run on its own, and count the number of lines in your inbox. Your goal is to fill in the method summarizeInbox to achieve the goals mentioned above.

Random Useful Tips

1. The String class has a method called startsWith that you may find useful. For example:

String s= "hello";
if (s.startsWith("he"))
// etc.

2. You shouldn't keep downloading your inbox every time you run your program - you'll get tired of typing in your username and password, as well as waiting for the information to transfer to your computer. After you've gotten your Inbox once, comment out the "getInbox" line in BasicInboxMain. But make sure to uncomment it again before you submit your code!

Extra work for those who want to push themselves further

Some email messages can have two lines in them that start with "From:". For example, the first one might legitimately be the header information. The second one might be a forwarded email message contained inside. Modify your program so that if more than one "From:", "To:", or "Subject:" line appears, only the first is displayed.

Working from home

As with the previous assignments, you have to install some extra stuff on your home system if you want the project to work. Remember to do this early, since I no one has tested this out for me yet! These directions assume that you have successfully gotten all previous assignments to work on your home computer. If that is the case, here is what you need to add:

1. Download PasswordBox.class and this updated InputBox.class, and drop these files in your javabook folder. (If you followed directions previously, this folder should be inside C:\bluej).

2. Download basicio.jar, and place it in your c:\bluej folder.

3. Start up BlueJ. Click "Tools", then "Preferences", then click on the "Libraries" tab. Click on the "Add" button, then type in the complete location where your basicio.jar file is located. For example, on my machine at home, I've added the following line:

c:\bluej\basicio.jar

Shut down BlueJ, and start it up again. Go to the libraries tab again to make sure your changes stuck (occasionally they don't stick, and you have to do it again.)

We will discuss this assignment in class on 1/23/02. Have fun, start early, and keep in touch.



Dave Musicant, Department of Mathematics and Computer Science, Carleton College, Northfield, MN 55057, dmusican@carleton.edu