2022-12-02 EECS 3214 Programming Assignment 3

加我微信或好久
本人有三年程序代写经验,写过近 800 个项目,所有代码均为 100%原创。以前给中介代写,现在本人自己接单,不是中介。代写语言包括 C++、C、Python、Java、JavaScript、Go、C#、Ruby、Haskell、Ocaml、Scala、Scheme、F#、Racket、Prolog、Clojure、Matlab、MIPS汇编、x86汇编、arm汇编、RISC-V汇编,LC3汇编,Hack汇编等各种语言编程项目。iOS、安卓app、编译器、编译原理、操作系统。英文要求无障碍。经验丰富,保证原创,亲自编写,不是中介。网上很多都是中介,本人曾长期跟他们打交道。
注意:不接毕业设计、毕业论文等。请直接私信我发具体需求及截止时间。主要接英文需求。中介勿扰。扫码加我微信或好友,发送详细需求。

2022-12-02

PA3.1. Implementing an SMTP server

Learning Goals

  • To learn how to read and implement a well-specified protocol;
  • To develop your programming and debugging skills as they relate to the use of sockets in Java;
  • To implement the server side of a protocol;
  • To develop general networking experimental skills;
  • To develop a further understanding of what TCP does, and how to manage TCP connections from the server perspective.

Special Note

Although this assignment’s autograder will test the most common input issues and produce an initial score, this score may be overwritten by a manual review by the course staff. This manual review will ensure your code works not only based on the simple cases listed in the resulting tests, but also for other considerations listed in the RFCs and for additional tests. TAs will also review your code quality in terms of clarity and use of comments.

Assignment Overview

In this assignment you will use the Java socket library to construct two servers typically used in mail exchange: an SMTP server, used for sending emails, and a POP3 server, used to retrieve emails from a mailbox. Both servers will be called directly from a command line, instead of GUI. Both your programs are to take a single argument, the TCP port the respective server is to listen on for client connections.

To start your assignment, download the file MailServer.zip. This file contains the base files required to implement your code.

In order to avoid problems with spam and misbehaved email messages, your servers will implement only internal email messages. Messages will be received by your SMTP server, saved locally, and then retrieved by your POP3 server. Your messages will not be relayed to other servers, and you will not receive messages from other servers. You are not allowed to implement any email forwarding mechanism, as unintended errors when handling this kind of traffic may cause the University’s network to be flagged as an email spammer, and you may be subject to penalties such as account suspension or limited access to the department resources.

Some code is already provided that performs basic functionality, such as checking for the command-line arguments, handling usernames, passwords and email files. Note that the provided code already implements partial functionality to create individual threads, so that each accepted client runs in a separate thread. This means your system will be able to handle multiple clients simultaneously without interfering with each other. However, to avoid problems, you are encouraged to avoid static variables or variables that are somehow shared between threads, other than those already provided in the code.

This assignment is divided into two parts. This page describes the first part, associated to the SMTP server. The following question handles the POP server.

Part 1: The SMTP server

The SMTP protocol, described in RFC 5321, is used by mail clients (such as Thunderbird and Outlook) to send email messages. You will implement the server side of this protocol. More specifically, you will create a server able to support, at the very least, the following commands:

  • HELO and EHLO (client identification)
  • MAIL (message initialization)
  • RCPT (recipient specification)
  • DATA (message contents)
  • RSET (reset transmission)
  • VRFY (check username)
  • NOOP (no operation)
  • QUIT (session termination)

The functionality of the commands above is listed in the RFC, with special consideration to sections 3 (intro), 3.1, 3.2, 3.3, 3.5, and 3.8. Technical details about these commands are found in section 4 (intro), and 4.1 to 4.3. You may skip over parts of these sections that cover commands and functionality not listed above. You must pay special attention to possible error messages, and make sure your code sends the correct error messages for different kinds of invalid input, such as invalid command ordering, missing or extraneous parameters, or invalid recipients.

About the EHLO command: you are not required to implement the multi-line response of an EHLO command. Responding with a single line that contains the response code and the host name is enough.

About the VRFY command: the RFC lists two possible types of parameters for VRFY (end of section 3.5.1): a string containing just the username (without @domain), or a string containing both the username and domain (a regular email address format, e.g. john. doe@example.com). You are not required to implement the former, only the latter. In particular, if a parameter is provided to VRFY, you only need to return success (i.e., 250) if the username exists and error (i.e., 550) if the username does not exist. There is no need to return other results listed on the RFC as MAY implement like partial matches, ambiguous results, mailbox storage limitations, etc… You are still required to check that the command includes the mandatory argument (returning an appropriate error in this case).

You are not required to implement commands not listed above, although a proper implementation must distinguish between commands you do not support (e.g., EXPN or HELP) from other invalid commands; The return code 502 is used for unsupported commands, while 500 is used for invalid commands. You are also not required to implement encryption or authentication.

Although you are to accept messages from any sender, your recipients must be limited to the ones supported by your system. You are to keep in your repository directory a text file called users. txt containing, in each line, a user name (as an email address) and a password, separated by a space. You are to accept only recipients that are users in this file. This file will not be submitted for grading, you may use it for testing only. For example, your users. txt file may contain the following content:

john.doe@example.com password123
mary.smith@example.com mypasswordisstrongerthanyours
edward.snowden@example.com ThisIsA100%SecureAndMemorablePassword

Note that a single message may be delivered to more than one recipient, so while saving the recipients you must keep a list of recipients for the current message. Functionality for checking if a user is in the users. txt file is provided in the initial code of your repository.

Once a transaction for handling a message is finished, your program must save the content of the email message, including headers, in files inside the mail.store directory, with subdirectories for each recipient. Messages sent to more than one recipient will be saved in all recipients’ directories. The provided code already includes functionality to save these files and create these directories. In particular, the class Mailwriter is provided that allows you to save content into the mailbox of multiple recipients, in an interface similar to a regular Filewriter. Note that the content is only saved to the actual mailboxes when the writer is closed, so you should make sure that you properly close the writer once the data is complete (using a try-with-resources block is also a good approach).

Implementation Constraints and Suggestions

The provided code already provides functionality for several features you are expected to perform. You are strongly encouraged to read the comments for the provided classes and methods before starting the implementation, as part of what you are expected to implement can be vastly simplified by using the provided code. You may assume that the functionality of these functions will be available and unmodified in the grading environment.

Don’t try to implement this assignment all at once. Instead incrementally build and simultaneously test the solution. A suggested strategy is to:

  • Start by reading the RFCs for both protocols, and listing a “normal” scenario, where a client will send one message to one recipient, or the client has one message which is listed and and retrieved. Make note of the proper sequence of commands and replies to be used for each of these scenarios.
  • Have your program send the initial welcome message and immediately return.
  • Get your server to start reading and parsing commands and arguments. Make sure your code considers case-insensitive comparisons of strings (e.g., HELO, helo and HeLo are all equivalent). At this point just respond with a message indicating that the command was not recognized.
  • Implement simple commands like QUIT and NOOP.
  • Implement a straightforward sequence of commands as listed in your first item. Start simple, then move on to more complex tasks.
  • Finally, identify potentially incorrect sequences of commands or arguments, and handle them accordingly. Examples may include sending a message to no recipient, specifying a password without a username, obtaining the list of messages without logging in first, etc.

Running Java code with arguments

Note that both applications require you to pass the listening port as an argument in the command line. The way to produce this result depends on how you are running your applications. If you are running your code in a terminal, you may use:

java ca.yorku.eecs3214.mail.net.MySMTPServer 55555

replacing 55555 with the port number of your choice.

If you are running your code in an IDE, instructions vary according to the IDE, but they are typically related to Run Configurations or equivalent setting, and you will set Program arguments. Here are some common IDEs with their settings:

  • Eclipse
  • Intellis
  • VSCode

PA3.2. Implementing a POP server

Learning Goals

  • To learn how to read and implement a well-specified protocol;
  • To develop your programming and debugging skills as they relate to the use of sockets in Java;
  • To implement the server side of a protocol;
  • To develop general networking experimental skills;
  • To develop a further understanding of what TCP does, and how to manage TCP connections from the server perspective.

This part of the assignment uses the same codebase as the previous part, for SMTP, but it can be developed independently. As described in the previous assignment, you will use the Java socket library to construct a server typically used in mail exchange: a POP3 server, used to retrieve emails from a mailbox. The server will be called directly from a command line, instead of GUI. It takes a single argument, the TCP port the server is to listen on for client connections. Please review the introduction to the previous part for more information.

Part 2: The POP3 server

The POP3 protocol, described in RFC 1939, is used by mail clients to retrieve email messages from the mailbox of a specific email user. You will implement the server side of this protocol. More specifically, you are required to support, at the very least, the following commands:

  • USER and PASS (plain authentication)
  • STAT (message count information)
  • LIST (message listing) - with and without arguments
  • RETR (message content retrieval)
  • DELE (delete message)
  • RSET (undelete messages)
  • NOOP (no operation)
  • QUIT (session termination)

The functionality of the commands above is listed in the RFC. Since this is a short RFC you are encouraged to read the entire document, but the most important sections are 1-6 and 9- 11. You must also pay special attention to possible error case, and make sure your code sends a valid error message for different kinds of invalid input, such as invalid command ordering, missing or extraneous parameters, or invalid recipients. You are not required to implement other commands. You are also not required to implement encryption.

You only need to implement plain user authentication, with no password encryption or digest. User and password checks can be performed using provided functions, based on the information in file users.txt described in part 1.

A user’s messages will be retrieved from a subdirectory of mail.store, with the subdirectory name corresponding to the user name. This is the same structure as the one used to store messages in the SMTP server; this allows you to use your SMTP server to add messages to a user’s mailbox, and POP3 to retrieve these messages. Your program is to read those messages and return them to the user as requested. Most of the functionality to read the list of files, obtain their size and maintain information need to retrieve its content is already implemented in functions provided in the provided code.

Note that, although typical clients send messages in a straightforward order, you must allow the user to provide commands in an order that is different than a regular client, as long as allowed by the RFC. In particular, note that the DELE command, which deletes a message, does not actually delete it right away, but only marks it as deleted. Your code must be able to, for example, list all remaining messages after a deletion by ignoring the deleted message while still listing other messages with the same numeric order as they had before the deletion. The email file will, then, be deleted once the session terminates.

Implementation Constraints and Suggestions

As mentioned in part 1, the provided code already provides functionality for several features you are expected to perform. You are strongly encouraged to read the comments for the provided classes and methods before starting the implementation, as part of what you are expected to implement can be vastly simplified by using the provided code. You may assume that the functionality of these functions will be available and unmodified in the grading environment.

The constraints and suggestions listed in part 1 of this assignment also apply to this part. Note that strategies to test your code are listed there, including instructions on how to setup an email client to use your code.

You may discuss this assignment with your classmates, but you must do your work only with your partner. You are not allowed to show your code, even for discussion or explanatory purposes to other classmates.

You may add, at the top of the provided files, a comment block that contains any information you would like to convey to the TAs about your assignment. For example maybe you didn’t get some part of the assignment working, or it works in some circumstances but not others. Note that the purpose of this comment is to guide the code review of a TA so that they may be able to more easily find specific issues, and is not guaranteed to affect your grade.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值