This paper describes the design idea of reusable and extensible MIME coding class, and compares the difference between template method and strategy mode by the way.
I. Background knowledge
MIME is an Internet protocol, all called "Multipurpose Internet Mail Extensions", and the Chinese name is "Multipurpose Internet Mail Extension." In fact, its application is not limited to sending and receiving Internet mail-it has become one of the basic protocols for transmitting multimedia information over the Internet. This article is concerned only with MIME coding algorithms.
The principle of MIME coding is to convert 8 bit content into 7 bit form to transmit correctly, and then revert it to 8 bit content after receiving. The first reason for encoding a message is that many gateways on the Internet do not correctly transmit characters in 8 bit encodings, such as Chinese characters. MIME encoding has a total of Base64, quoted-printable, 7bit, 8bit and binary.
The BASE64 algorithm encodes the input string or section of data into only {' A '-' Z ', ' ' A '-' ' Z ', ' 0 '-' 9 ', ' ' + ', '/' ' The string of these 64 characters, ' = ' for padding. The encoding method is to take the input data stream 6 bit at a time, use this 6 bit value (0-63) as the index to check the table, output the corresponding characters. In this way, each 3 byte is encoded to 4 characters (3x8→4x6), and the "=" is populated with a "=" of less than 4 characters.
The quoted-printable algorithm encodes according to the input string or byte range, if the characters are not encoded, direct output, and if encoding is required, the first output is "=" followed by a hexadecimal byte value of 2 characters.
Second, design objectives
We plan to develop a set of mime coding and decoding classes that can be applied to a variety of applications:
· Email client program
· Garbled View procedure
· Images and other binary objects into an XML file
The design objectives are as follows:
· Reusable
· Easy to use
· Easy to expand