Multi-purpose Internet Mail Extension mime

Source: Internet
Author: User
Tags rfc

 

Multi-purpose Internet Mail Extension (MIME,Multipurpose Internet Mail Extensions)

Before mime is introduced, RFC 822 can only send basic ASCII code text information. It is very difficult to implement the content of an email, such as binary files, sounds, and animations. Mime provides a method that can append multiple encoding files to an email to make up for the shortcomings of the original information format. In fact, mime is not only a part of the HTTP protocol standard.

In the earliest HTTP protocol, there was no additional data type information. All transmitted data was interpreted by the client program as HTML documents in the hypertext markup language. to support multimedia data types, the MIME data type information appended to the document is used to identify the data type in the HTTP protocol. When the output result is sent to the browser, the browser starts an appropriate application to process the output document through the MIME type in the document. In HTTP, the MIME type is defined in the Content-Type header.

Generally, a mime Message consists of a message header and a message body. Now we are concerned with mime mail, so in the following discussion, we should refer to "message" as "mail ".

 

1. MIME headers

The mime-format header contains important information such as the sender, recipient, subject, time, MIME Version, and mail content type. Each piece of information is called a domain, which is composed of ":" and information content after the domain name. It can be a row, long or occupying multiple rows. The first line of the domain must be written with a "Header", that is, there must be no blank characters (spaces and tabs) on the left side. To continue a line, you must start with a blank character, the first blank character is not inherent in the information. It must be filtered out during decoding.

1) common domains include:

Domain Name Description Added
Received transmission path: email servers at all levels
Return-path reply address target email server
Delivered-to destination email server
Reply-to reply Address Email creator
From sender address: email creator
To recipient Address Email creator
CC Address Email creator
The creator of the BCC dark mail.
Date and Time email creator
Subject subject email creator
Message-ID: the creator of the message.
Mime-version: the creator of the mime-version message.
The creator of the Content-Type email.
Content-transfer-encoding: the sender of the Transfer Encoding Method email

 

2) Content-Type. This header field is used to specify the message type. Generally. Content-Type: [type]/[subtype]; Parameter

Type has the following format.

  • Text: indicates the standardized representation of text information. Text messages can be in multiple character sets or formats;
  • Multipart: connects multiple parts of the message body to form a message. These parts can be different types of data;
  • Application: used to transmit application data or binary data;
  • Message: Used to package an e-mail message;
  • Image: used to transmit static image data;
  • Audio: used to transmit audio or audio data;
  • Video: used to transmit dynamic image data. It can be a video data format edited together with audio.

Subtype is used to specify the type details. The set of Content-Type/subtype pairs and related parameters will increase over time. To ensure that these values are developed in an orderly and open state, mime uses Internet Assigned Numbers Authority (IANA) as the central registration mechanism to manage these values. Common subtype values are as follows:

  • Text/plain (plain text)
  • Text/html (HTML document)
  • Application/XHTML + XML (XHTML document)
  • Image/GIF (GIF image)
  • Image/JPEG (JPEG image) [image/pjpeg in PHP]
  • Image/PNG (PNG Image) [image/X-PNG in PHP]
  • Video/MPEG (mPEG animation)
  • Application/octet-stream (any binary data)
  • Application/pdf (PDF)
  • Application/MSWord (Microsoft Word file)
  • Message/rfc822 (RFC 822 format)
  • Multipart/alternative (HTML form and plain text form of HTML mail, the same content is expressed in different forms)
  • Application/X-WWW-form-urlencoded (Form submitted using the http post method)
  • Multipart/form-data (same as above, but mainly used when the form is submitted along with file upload)

In addition, subtypes that are not accepted as formal data types can be independent names starting with X-(for example, application/X-gzip ). The inherent name of VND-start can also be used (for example, application/vnd. MS-Excel ).

Parameter can be used to specify additional information. In more cases, it is used to specify the charset parameter for text encoding methods such as text/plain and text/htm. Mime defines the default subtype Based on the type. When the client cannot determine the subtype of the message, the message is treated as the default subtype for processing. Text is text/plain by default, application is application/octet-stream by default, and multipart is considered multipart/mixed by default.

 

3) content Transfer Encoding (content-transfer-encoding), which makes it possible to specify a character encoding method other than ASCII. The format is as follows:

Content-transfer-encoding: [mechanic]

The value of the mechanism can be "7bit", "8bit", "binary", "quoted-printable", or "base64 ".

 

7bit refers to the 7-bit ASCII encoding method.

8-bit ASCII code.

Binary, quoted-printable, because some European text and some characters in the ASCII character set are partially the same. If mail messages are in these languages, the characters that overlap ASCII can be used as is, and the characters that do not exist in the ASCII character set are in the form of "= ??" . Here "?" You must specify the hexadecimal number after encoding. The length of a message encoded with quoted-printable is not too long, and most of the messages are ASCII characters. Even if the message is not decoded, the content of the message can be roughly understood.

Base64 is an encoding method that converts binary 01 sequences into ASCII characters. The encoded text or binary message can be transmitted using SMTP and other protocols that only support ASCII characters. Base64 is generally considered to increase the message length by an average of 33%. Moreover, encoded messages are not readable to humans.

The value x-encodingname is a reserved extension.

 

Binary mime body

1) Common Simple Mail types include text/plain (plain text) and text/html (hypertext ).

2) When the MIME type of an email is multipart,

The body is divided into multiple segments, each of which contains two parts: the header and the body. These two parts are also separated by blank lines. There are three common multipart types: multipart/mixed, multipart/related, and multipart/alternative. From their names, it is not difficult to deduce the meaning and usefulness of these types. The hierarchical relationships between them can be summarized as follows:

+ Complete multipart/mixed parts + | + ----------------- multipart/related ------------------ + | + ----- multipart/alternative ------ ++ ---------- + | + ------ + | | embedded resources | attachment | + ------------ ++ ------------ + | + ---------- + | + ------ + | plain text | hypertext body | + ------------ + | + ---------- + | + ------ + | embedded resources | attachment | + ---------------------------------- + + ---------- + | + ------ + | + -------------------------------------------------------- + | + accept +

We can see that if you want to add attachments to an email, you must define the multipart/mixed segment. If there are embedded resources, you must at least define the multipart/related segment. If the plain text and hypertext coexist, define at least multipart/alternative segments. What is "at least "? For example, if only plain text and hypertext text are available, the type in the mail header is extended and defined as multipart/related or even multipart/mixed.

The common feature of multipart types is to specify the "boundary" parameter string in the field header, and each sub-segment in the segment body is bounded by this string. All child segments start with the "--" + boundary row, and the parent segment ends with the "--" + boundary + "--" Row. Segments and segments are also separated by blank lines. When the mail body is multipart, the start part of the mail body (before the first "--" + boundary line) can have some additional text lines, which are equivalent to comments, ignore when decoding.

 

Refer:

Http://dev.csdn.net/htmls/18/18448.html

Http://zh.wikipedia.org/zh/MIME

Http://www.w3schools.com/media/media_mimeref.asp

 

Complete!

Related Article

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.