Designing MIME coding class with design pattern--concurrently talking about template method and strategy

Source: Internet
Author: User
Tags base64 mail

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.