



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A lab exercise for creating a minimal email reader using java programming and the pop protocol. Students will learn how to create a gui interface, connect to the email server, log in, retrieve and display email messages, and handle server responses. The document also covers good programming practices such as commenting, formatting, and using if statements.
Typology: Lab Reports
1 / 6
This page cannot be seen from the preview
Don't miss anything!
Your goal in this lab is to use the knowledge of the POP protocol you gained in last week’s lab together with the introduction to Java programming provided in class to write a very simple email client program. The program you write will actually only provide half of the minimal functionality of an email client. It will enable its user to read mail but not provide the ability to send mail. This handout provides guidance on the steps you will need to complete as you construct this program. You should
you will need for at least the first steps of the lab on paper before your lab period. In this handout, we first describe the interface that your program should provide. We then discuss the major steps you will have to take to complete the program. Next, we review the details of the process of entering your pro- gram’s code, running your program, and electronically submitting your work when you are done. After that, we explain what we will look for when we grade it. Finally, we provide information on a number of details you will need to complete this program including a short review of the POP protocol.
A sample of what the interface for your program might look like while the program is being used is shown below. Across the top of its window, the program displays two text fields in which the user must enter his or her account information. Below these is a field to hold the number of the message the user wants to see. This field is followed by a button labeled “Get Message.’’The remainder of the program’s window is filled with two JTextAreas. The upper text area is used to display the latest message retrieved. The text area that appears near the bottom of the win- dow is used to display the “+OK” and “-ERR” messages the POP server sends in response to the commands it re- ceives from your program. While experimenting with the Apple Mail program, we learned that it fetches all available messages at once. Your program will take a different approach. Each time the “Get Message’’ button is pressed, it will log on to the CS de- partment’s email server using the “USER’’ and “PASS’’ commands, retrieve the specified message using the “RETR’’ command, and then log out using the “QUIT’’ command. As a consequence, the user of the program must fill in all three text fields before pressing the “Get Message’’ button.
It is a good idea to implement a program in small steps, testing the correctness of what you have done in each step as completely as possible before moving on to the next step. Otherwise, it can be very difficult to pinpoint errors when they occur. With this in mind, here is a plan you may wish to follow while working on this assignment:
While you are working on this lab, a disturbing thing may happen. Your program may not do what you expect. For example, instead of seeing nice “+OK” messages in your text area it may be filled with “-ERR” messages. There is a technique that may help you identify the source of your problem. Before running your own program, start TCPCapture and configure it to capture all POP packets. Then run your program and look at all the packets that are sent between your client and the server. You will see the actual contents of the messages your program sends along with the “+OK” and “-ERR” message from the server. This should provide you with a better understanding of what is going wrong and enable you to fix the problem.
Return to the Finder and look in your Netfiles “Private” folder (or the “Documents” or “Desktop” folder if you saved your project there). You should find the folder that BlueJ created for your project. Its name should be the one you picked for your project (something like YellowLab2). Now click on the blue “Users” disk on the Desktop to open a new Finder window. Navigate to b/blawson/ inbox/cmsc150/lab2. Then drag-and-drop from the first Finder window your project folder into the cmsc150/ lab2 folder in my Netfiles inbox. The deadline for submitting your work is 17:00 on Saturday 13 September (the Saturday immediately following the lab). Jepson G22 will be open per the regular computer lab schedule on Saturdays: 11:00-17:00. If you come to the lab on Saturday and it is not open, one of the student assistants in G28 will open it for you upon request. If you submit prior to this deadline and later discover that your submission was flawed, you can submit again pro- vided the deadline has not passed. We will grade the latest submission made before the 17:00 Saturday deadline. Netfiles will not let you submit again unless you change the name of your folder slightly. It does this to prevent an- other student from accidentally overwriting one of your submissions. Just add something to the folder name (like the word “revised”) and the re-submission should work fine.
Grading will typically be done by evaluating your lab submission based on three sets of criteria: how complete your code is, how well it works, and how clearly it is written. Completeness measures whether you have done a reason- able job of writing instructions to provide the desired functionality, even if the instructions you wrote don’t fully work. Correctness measures whether all the desired functionality works as we expect it to. Good style is also an important quality for programs to have; it is essential to make programs readable and understandable. Over the course of the semester we will get pickier about style issues, but it is important for you to get into good habits from the very beginning. Completeness (7 points) / Correctness (3 points)
- GUI layout - Connecting to and disconnecting from the server - Logging in - Retrieving mail messages - Displaying mail messages in top text area - Displaying server responses in bottom text area
In this lab, you should use a form of GUI component called a JPasswordField. This is a text field specially de- signed for inputing passwords. Unlike a normal text field, a JPasswordField doesn’t show the characters a user types into the field. Instead it displays a star for each character typed. The interface to a JPasswordField from within your program is a bit different from that for JTextFields. If you invoke the getText method on a JPasswordField, you will get a message telling you that the method is “depre- cated.’’ This means that the getText method may be removed from the Swing library in the future. The message is annoying enough that we would like to provide an alternate way for you to access the contents of a JPassword- Field. In any context where you would like to use an invocation like somePasswordField.getText() you should instead use an expression of the form new String( somePasswordField.getPassword() ) This will have the same effect as invoking getText, but there will be no message about using a deprecated method.
There is a construct in Java that makes it fairly easy to revise the dataAvailable method in such a way that the “+OK” responses from the server will not appear in the same text area as the contents of email message you retrieve. It is called an if statement. It allows you to tell Java to choose between executing two sets of instructions in a method based on a specified condition. For example, in your mail program you could use an if statement to enable Java to choose whether a line retrieved within your dataAvailable method should be displayed in the top text area or the bottom text area based on whether the line began with the text “+OK”. An if statement takes the form:
} else {
} For your program, the condition that should determine which text area should be used is whether the latest line re- ceived from the server begins with “+OK” or not. If the name lineFromServer refers to the latest line retrieved from the server, you can express this choice in Java by saying if ( lineFromServer.startsWith( “+OK” ) ) {
} else {
} The statement(s) included within the first pair of curly braces should append the contents of the line received to the lower text area. Statements to display the line received in the upper text area should be placed between the second pair of curly braces. In order to use this code, you will have to place lines to declare the variable linesFrom- Server, to get the next line from the server, and to associate this line with the variable linesFromServer before the if statement. We want you to modify your POP program so that the final version of your dataAvailable method includes such an if statement. Of course, this code will be fooled by any email message that contains a line that actually starts with +OK” or if the server sends a “-ERR” response. We will worry about how to deal with that issue next week....