Zhang Xiaolong talks about how to write E-mail software
Author: Evaluation: the station Date: 2001-08-31 Description: Source:
The editor of "New Trend Electron" is about me, and I have always been too lazy to write articles, but the editor is written about how to write mail software because many readers are interested in developing mail. I think this is better than other content, because of the development of Foxmail, after all, I have accumulated some ideas. But because it is an article toward the public, technology can't be too strong, so mainly from the concept of talking about my own opinion. The first thing to be determined is the application object and range of the mail software you want to develop. Divided into three categories, the first category, your goal is a general E-mail software, just like Foxmail, Outlook. The second class is some branches of e-mail, such as the Mail Monitor (POP3 Monitor, whether there is an email on the server), batch mail transmitter (Bulk emailer). Third categories, use e-mail to some software projects, for example, you may need to transfer data with E-mail in a MIS project, or provide a function of sending mail on the Web (such as a greeting card). About three types, their implementation methods and difficulty are different. In order to explain convenience, we will call the above three types, Class B and Class C. Among them, the A class is the most widely covered by the user, and the factors must be considered, the stability and adaptability requirements of the program are also the largest, and the B-class. The following content is mainly concentrated in mail related knowledge. I want to emphasize that a mail software, more is the processing of non-network. Because the mail software is different from other network applications, the mail software should be closer to the user, actually a daily office application. In fact, in Foxmail, the processing of network parts may only use 10% of energy. First, understand the TCP / IP network programming method for Class A and part B applications, require your own programming to implement TCP-based mail communication. Therefore, the understanding of TCP / IP programming is necessary. And once you have the programming method of TCP / IP, you can complete more network programs, such as FTP, HTTP, etc. I can't discuss it here, because this is a book or a few books. Therefore, I can only recommend myself I think I'm thinking about the book: 1. Internet's classic textbook: Title: Internetworking with TCP / IP. Author: Douglas E. Comer. Publishing: Prentice Hall. Chinese translation: "Internet interconnection with TCP / IP". Publishing: Electronic Industry Press. This book has three volumes. Tsinghua University Press has issued an English version in China because the price is cheap than foreign countries. Not long ago, I also bought a friend who sent it to the American book (still expensive). 2. A good book name for Winsock programming: "Internet Programming", Electronic Industry Press, 1996. This is a translated book that explained in detail the concept and method of TCP / IP programming. The difference between UNIX Socket and Windows Socket programming, as well as the synchronous and asynchronous, messaging, messages, and multi-threaded synchronization, message and multi-threading. In 1996, I was because I saw this book, germination wrote the idea of writing foxmail. Second, understand the standards related to email to Class A and Class B applications, it is necessary to be very familiar with the network protocol, especially the RFC protocol associated with E-mail. RFC is a referusion of Request for Comments. Most of the Internet provides updates through RFC, such as our common HTTP protocol, is defined by RFC 2068.
There are many protocols associated with E-mail (communication, mail format, attachment), etc., the following is the RFC: RFC 821 (SMTP, Simple Mail Transfer Protocol, Defining Mechanism) RFC 822 (Mail Format) Definition) RFC 1725 (POP3, Post Office Protocol version 3 defines the mechanism of collecting mail from POP3 server) RFC 1521 (MIME standard) RFC 1522 (MIME standard 2) here, because of the space relationship, there is no way to explain in depth, so it can only Check these documents by the reader yourself. These documents can be found on the Internet, such as http://www.cis.ohio-state.edu/htbin/rfc/index.rfc.html lists all RFC documents. For Class C applications (and some B applications), you may not care about these protocols, because you can use some ready-made controls to complete the functionality of the message, the packaged control can completely block the detail of these implementations. Third, non-network factors As mentioned earlier, you must invest more energy into other non-network parts of the non-network, because as an application, you have to deal with each detail. But it is not a stack of detail of each characteristic. For example, for C class applications, you have to do a reasonable system design, then find a good implementation method for each large module in the design. For example, email storage, I call it a mailbox file system, in fact, an index-based beam record system. Such as inbox, composed of two files, in. Ind is an index file, records the summary information of each message (sender, theme, date, etc.), more importantly, each message is in the data file Location; Data file is in. Box, simply record the original content of each message. The principle of the mailbox file system is not difficult to understand, it is difficult to ensure its very high stability, because the design error of the mailbox file will directly lead to the loss of the message. Like the development of browsers, the browser's HTTP network protocol handles are not complex, but HTML's display is much more complicated. Email is the same. But in Class B and Class C applications, the problem is relatively simple because it is a specific functional implementation. Fourth, Winsock's message and multithreading understanding of the asynchronous mechanism of Winsock is very important, and it is also important for multithreading. Many people think that multithreading can solve any problems, I don't want to be like this. Socket programming under Windows is a big difference in UNIX, you can closely link the Socket's event with Windows message mechanism, write high-efficiency Winsock programs, which depends on Windows and Winsock understanding. If you need to use multithreading, you must carefully consider the thread synchronization problem, which is not just the understanding of threads, but it is possible to consider thread synchronization problems when planning. For example, you have a thread to send an email from the outbox, a thread is receiving mail, and a thread (main thread) is displayed or deleted, these threads may operate on the same mailbox file, if not synchronized The consequences will be destroyed by the mailbox file. Messaging-based asynchronous mechanism based on Winsock is a good choice, so only when there is a network message coming, Winsock is sent to send a message to the program, and the program will not pause in the waiting or loop. With an asynchronous mechanism, you must construct a "state machine", you have to let the program clearly know what phase is currently processed. When the network (server) requires data, the program can know what the next step is to send.