1. Background
My company decided to use Open Office instead of Ms Office several months ago. Because there is no mail sofware in Open Office, I decided to develop a mail program myself. Finally, my company decided to use Lotus Notes for receiving mails and forbade the port for pop3. Thus, my program doesn't make much sense. Indeed, it needs much work to develop a mail client with high performance. Since I am not so free, I quited after I implemented the basic functions, such as, send a mail and receive mails. I upload my code at http://download.csdn.net/source/1203159.
Here, I describe my design briefly. There are two modules, one for sending and receiving mails----SimpleMail, one for caching the mails received---FileStore.
2. Reference
Obviously, you need to be familiar with the related mail protocols, such as Smtp and Pop3. The RFC documents present the basic knowledge. The RFC 821, 822, 1939 may be the first three that you should read.
3. SimpleMail
The module, SimpleMail, is reponsible for sending and receiving mails. I adopt a layered architecture, though it is so simple. Of course, the layer on the top is for user interface, while the layer at the bottom is responsible for handling the network protocols. The layer in the middle is to hide the detail of the network protocol, and provides the upper layer with fixed interface. As shown in the project, I devided the files into three filters. The filter named view contains files for user interface. Besides, the other two filters are for Smtp and Pop3 respectively, and they are the principal protocols. The file --MailManager--that is outside the filter comprises the middle layer, which acts as an intermediary between the user interface and the network protocol. Here, I list the interface in the MailManager below which characterizes the main functions of the mail program :
3.1 the View part
However, I think the implementation intended for user interface doesn't need much description. They are mostly commonplace. But there is an edit box in the send mail dialog. You can drag files into it and select the files in it to delete them. Well, that costed me much time to accomplish those functions. It's worth for you to read it.
3.2 the Mail part
Well, the files in connection with the network protocols may refer to some background knowledge. In fact, those implementation just follow the protocols. Here, I only explain the purpose of several files.
PopReceiveManager.h---implement pop3 protocol for receiving mails
SmtpSendManager.h---implement smtp protocol for sending mails
MIMECode.h, Base64.h---encode and decode the mail content, mainly use the base64 algorithm
AppOctetStream.h, MIMEContentAgent.h, Textplain.h---follow the mail format--MIME
4. FileStore
Well, it's necessary to cache the mails received for further use. So I develop this module for that purpose. The design is similiar to the way that the operating system constructs the files system. The basic unit is a block that stores a mail. And a certain number of blocks comprise a heap while a certain number of heaps comprise a cluster. All of these in this hierachical has an according sturcture to store some related information. The block index indicates the position of the mail. And the header at the head of the file stores the start position to store the mails. The following is the key structures.