Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What rules apply to MIME boundary?

When you are writing MIME, you separate different chunks of your message with a certain boundary. I failed for some reason to find any documentation explaining this boundary, but here's what I gathered from examples:

  1. Boundary can be any string of letters and numbers, i. e. "d29a0c638b540b23e9a29a3a9aebc900aeeb6a82".

  2. There are no rules for generating the boundary, you can just md5sum the name of your beloved, and here you go, you've got your boundary.

  3. If you are sending MIME over HTTP, you must add a header "Content-Type" specifying that you do, and your boundary, contents of a header may look like this:

    multipart/form-data; boundary=d29a0c638b540b23e9a29a3a9aebc900aeeb6a82

  4. In the body of your message, the boundary should be preceded with "--", like:

    --d29a0c638b540b23e9a29a3a9aebc900aeeb6a82

But following these rules (and this helpful answer) I failed to generate POST query that server would accept. Am I missing something? Did I get something wrong?

like image 817
Septagram Avatar asked Jan 11 '11 09:01

Septagram


People also ask

What are MIME boundaries?

MIME boundaries are strings of 7-bit US-ASCII text that define the boundaries between message parts in a MIME message. MIME boundaries are declared in a Content-Type message header for any message that encapsulates more than one message part and in part headers for those parts that encapsulate nested parts.

What is boundary in multipart form data?

The boundary is included to separate name/value pair in the multipart/form-data . The boundary parameter acts like a marker for each pair of name and value in the multipart/form-data. The boundary parameter is automatically added to the Content-Type in the http (Hyper Text Transfer Protocol) request header.

Which is an example of a multipart MIME?

multipart. Data that consists of multiple components which may individually have different MIME types. Examples include multipart/form-data (for data produced using the FormData API) and multipart/byteranges (defined in RFC 7233, section 5.4.

What is MIME multipart content?

Multipurpose Internet Mail Extensions (MIME) is an Internet standard that is used to support the transfer of single or multiple text and non-text attachments. Non-text attachments can include graphics, audio, and video files.


1 Answers

The syntax of a boundary is:

 boundary := 0*69<bchars> bcharsnospace  bchars := bcharsnospace / " "  bcharsnospace := DIGIT / ALPHA / "'" / "(" / ")" /                   "+" / "_" / "," / "-" / "." /                   "/" / ":" / "=" / "?" 

And the body of a multipart entity has the syntax (only the important parts):

 multipart-body := [preamble CRLF]                    dash-boundary transport-padding CRLF                    body-part *encapsulation                    close-delimiter transport-padding                    [CRLF epilogue]  dash-boundary := "--" boundary  encapsulation := delimiter transport-padding                   CRLF body-part  delimiter := CRLF dash-boundary  close-delimiter := delimiter "--" 

The preceeding -- is mandatory for every boundary used in the message and the trailing -- is mandatory for the closing boundary (close-delimiter). So a multipart body with three body-parts with boundary as boundary can look like this:

--boundary 1. body-part --boundary 2. body-part --boundary 3. body-part --boundary-- 
like image 128
Gumbo Avatar answered Oct 08 '22 23:10

Gumbo