Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Verify that the original project is unable to send emails between servers. Open this project in BlueJ, create two mail servers and also create two

  • Verify that the original project is unable to send emails between servers. Open this project in BlueJ, create two mail servers and also create two users on server 1, and a third user on server 2. Send two messages from user 1 to user 2 (on server 1) and user 3 (on server 2), respectively. Check whether user 2 and user 3 can receive the message. Youll find user 2 can receive the message, but user 3 cant. Read through the source code and find out why. Write your explanation.

CODE:

/** * A class to model a simple email client. The client is run by a * particular user, and sends and retrieves mail via a particular server. * * @author David J. Barnes and Michael Klling * @version 2016.02.29 */ public class MailClient { // The server used for sending and receiving. private MailServer server; // The user running this client. private String user;

/** * Create a mail client run by user and attached to the given server. */ public MailClient(MailServer server, String user) { this.server = server; this.user = user; }

/** * Return the next mail item (if any) for this user. */ public MailItem getNextMailItem() { return server.getNextMailItem(user); }

/** * Print the next mail item (if any) for this user to the text * terminal. */ public void printNextMailItem() { MailItem item = server.getNextMailItem(user); if(item == null) { System.out.println("No new mail."); } else { item.print(); } }

/** * Send the given message to the given recipient via * the attached mail server. * @param to The intended recipient. * @param message The text of the message to be sent. */ public void sendMailItem(String to, String message) { MailItem item = new MailItem(user, to, message); server.post(item); } }

import java.util.ArrayList; import java.util.List; import java.util.Iterator;

/** * A simple model of a mail server. The server is able to receive * mail items for storage, and deliver them to clients on demand. * * @author David J. Barnes and Michael Klling * @version 2016.02.29 */ public class MailServer { // Storage for the arbitrary number of mail items to be stored // on the server. private List items;

/** * Construct a mail server. */ public MailServer() { items = new ArrayList<>(); }

/** * Return how many mail items are waiting for a user. * @param who The user to check for. * @return How many items are waiting. */ public int howManyMailItems(String who) { int count = 0; for(MailItem item : items) { if(item.getTo().equals(who)) { count++; } } return count; }

/** * Return the next mail item for a user or null if there * are none. * @param who The user requesting their next item. * @return The user's next item. */ public MailItem getNextMailItem(String who) { Iterator it = items.iterator(); while(it.hasNext()) { MailItem item = it.next(); if(item.getTo().equals(who)) { it.remove(); return item; } } return null; }

/** * Add the given mail item to the message list. * @param item The mail item to be stored on the server. */ public void post(MailItem item) { items.add(item); } }

/** * A class to model a simple mail item. The item has sender and recipient * addresses and a message string. * * @author David J. Barnes and Michael Klling * @version 2016.02.29 */ public class MailItem { // The sender of the item. private String from; // The intended recipient. private String to; // The text of the message. private String message;

/** * Create a mail item from sender to the given recipient, * containing the given message. * @param from The sender of this item. * @param to The intended recipient of this item. * @param message The text of the message to be sent. */ public MailItem(String from, String to, String message) { this.from = from; this.to = to; this.message = message; }

/** * @return The sender of this message. */ public String getFrom() { return from; }

/** * @return The intended recipient of this message. */ public String getTo() { return to; }

/** * @return The text of the message. */ public String getMessage() { return message; }

/** * Print this mail message to the text terminal. */ public void print() { System.out.println("From: " + from); System.out.println("To: " + to); System.out.println("Message: " + message); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 3 Lnai 6323

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

3642159389, 978-3642159381

More Books

Students also viewed these Databases questions

Question

Graph the equation, using the x- and y-intercepts. x + y = 1

Answered: 1 week ago