“This is the 20th day of my participation in the First Challenge 2022. For details: First Challenge 2022.”

Introduction to the

No standards, no network communication. It was on the basis of various network protocols and standards that we built the Internet as it is today. MIME is a web standard format called Multipurpose Internet Mail Extensions.

It is an extension protocol for mail, so what does it have to do with the Internet we use?

No hurry. Let’s take our time.

MIME,

In a long time ago, a popular application of computer is to send mail, in the beginning, only ASCII encoding is a computer world, but as time goes on, and a variety of application of the surge in demand, ASCII format already can’t meet our requirements, format of multi-type also became the difficulty of communication between each other, The result was a unified standard for message formatting, MIME.

MIME enables mail to support not only ASCII but other encodings as well. It also supports pictures, audio, video and applications and other attachments.

Message bodies can also support collections of multiple parts, and when such messages are encoded in MIME format, they can be sent using standard mail protocols such as SMTP, POP, IMAP, and so on.

Because MIME is a standard, any message that meets this standard can be parsed successfully.

MIME soon became widely used in the mail world, but the Internet evolved to use the popular HTTP protocol to access the World Wide Web, and the various content types defined in MIME naturally became the Content standard used in other protocols.

These content Types are defined in the MIME header. When an application receives a Content Type, it uses the corresponding application to parse the message content based on the message type specified in the type.

MIME header

MIME headers are important, and are the primary basis that applications use to determine the format of messages. MIME headers can contain the following fields.

MIME-Version

If the header exists, the message is in MIME format. It usually has a value of 1.0.

MIME - Version: 1.0Copy the code

If there is 1.0, is there 1.1 or 2.0?

I’m sorry, the answer is no. According to Nathaniel Borenstein, MIME’s co-founder, MIME version numbers were introduced in order to modify and upgrade MIME in the future. But because the MIME specification is not well designed for future upgrades to MIME versions, different people may react differently to an upgraded MIME version. As a result, it is difficult to upgrade MIME specifications today when MIME is widely used.

So, go with 1.0.

Content-Type

This header represents the type of the message body, including the type and subtype, for example:

Content-Type: text/plain
Copy the code

The MIME type we often refer to is this tag.

Here are common MIME types:

instructions The suffix type
Hypertext Markup Language text .html text/html
The XML document .xml text/xml
XHTML document .xhtml application/xhtml+xml
Plain text .txt text/plain
RTF text .rtf application/rtf
PDF document .pdf application/pdf
Microsoft Word file .word application/msword
PNG image .png image/png
gifs .gif image/gif
JPEG graphics .jpeg,.jpg image/jpeg
Au Sound file .au audio/basic
MIDI music files mid,.midi audio/midi,audio/x-midi
RealAudio music files .ra, .ram audio/x-pn-realaudio
The MPEG file .mpg,.mpeg video/mpeg
AVI files .avi video/x-msvideo
GZIP file .gz application/x-gzip
TAR file .tar application/x-tar
Arbitrary binary data application/octet-stream

Content-Disposition

Content-disposition is a field added to RFC 2183 that represents the presentation style of the message. Because the previous message only defined its message format, it did not consider how the message was presented, especially for mail.

For example, if an image is inserted into an email, what if the image is displayed inline as we read the message? Or is it in the form of an attachment that the user must download to see?

If in HTTP, the response header field Content-Disposition: Attachment is often used to prompt the client to render the response body as a downloadable file. Typically, when such a response is received, the Web browser prompts the user to save its content as a file, rather than displaying it as a page in the browser window.

Content-Transfer-Encoding

What does this field do?

As we know, with more and more data formats, traditional ASCII can no longer support large content representations, so content representations beyond ASCII such as Unicode have emerged.

However, for THE SMTP server, the encoding that can be transmitted or recognized is limited. If you want to transmit binary content, you need to use certain transfer Encodings to convert binary content. That’s what content-transfer-encoding means.

According to the definition of RFC and IANA, there are the following transfer encodings methods:

Name Reference
7bit [RFC2045]
8bit [RFC2045]
binary [RFC2045]
quoted-printable [RFC2045]
base64 [RFC2045]

For the specific meaning of transfer Encodings, please refer to my subsequent articles, which will only be briefly introduced here.

For the ordinary SMTP server, it can support 7bit, quoted-Printable and Base64 encoding modes.

The SMTP server with 8BITMIME SMTP Extension also supports 8bit encoding.

Binary encoding is also supported for SMTP servers that support BINARYMIME SMTP Extension.

Encoded-Word

According to RFC 2822, field names and values in acknowledgement messages must use ASCII characters. If the message contains non-ASCII characters, it needs to be encoded. The encoding is called encoded-word.

The encoding format is as follows:

"=? charset? encoding? encoded text? = ".Copy the code

Charset represents the encoding of the original message, encoding represents the encoding used, and encoded text is the encoded message.

Multipart messages

Finally, Multipart messages, we know that a message has a corresponding message Type: Content-Type.

If it is a complex message, it may contain more than one message type. This is where Multipart messages is used, where messages are divided into multiple parts, each with a Content-Type.

This type is more common in emails. The following is an example of Multipart messages where a message division marker boundary is specified in the Content-Type.

MIME - Version: 1.0 the content-type: multipart/mixed; boundary=frontier This is a message with multiple parts in MIME format. --frontier Content-Type: text/plain This is the body of the message. --frontier Content-Type: application/octet-stream Content-Transfer-Encoding: base64 PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg== --frontier--Copy the code

conclusion

This is a basic introduction to MIME, in which we have mentioned several transfer encodings methods. Stay tuned for future articles.

This article is available at www.flydean.com/12-mime/

The most popular interpretation, the most profound dry goods, the most concise tutorial, many tips you didn’t know waiting for you to discover!

Welcome to pay attention to my public number: “procedures those things”, understand technology, more understand you!