Reading message contents


C: FETCH 1 CONTENTS=BODY
S: {.7160} FETCH 1 CONTENTS
S:
S: Hello,
S:
S: There will be a meeting tomorrow.
S:
S:...
S:
S: .
S: * FETCH 1 FLAGS=
S: +OK Ok

There are additional FETCH keywords that instruct the server to retrieve the actual message contents. These keywords, described in the following sections, may be requested at the same time as the attribute keywords specified in the previous section. The server will respond with both single-line replies that contain the attributes, and multi-line replies that contain the requested message content. As always, the server may send the individual replies in any order.

The CONTENTS=part keyword results in a multiple line reply from the server, returning the requested content, specified by part. The server may use either multiple line format (dot-stuffed, or binary) at its discretion. The server may use either the LF or the CRLF sequence to terminate lines. The server automatically sets the SEEN flag on this message, which SHOULD generate an additional single line * FETCH reply from the server.

Using CONTENTS.PEEK instead of CONTENTS does not set the SEEN flag. The following documentation refers only to CONTENTS, but either one may be used; they are identical to each other in all ways except for the SEEN flag.

part should be a keyword chosen from the following list:

HEADERS(list)

Returns only the header portion of the message. list is a comma-separated list of case-insensitive header names. The list may be empty, in which case all the headers are returned; otherwise only the specified headers are returned, if they are present. list may also contain the following keywords which are a shorthand representation for frequently requested headers:

:ENVELOPE

This is the same as DATE,SUBJECT,FROM,SENDER,REPLY-TO,TO,CC,BCC,IN-REPLY-TO,MESSAGE-ID,REFERENCES.

:MIME

This is the same as :ENVELOPE, plus MIME-VERSION and all headers that start with CONTENT-.

In all cases, folded header lines are automatically unfolded by the server. All folding newline characters, and the leading whitespace on the continuation lines, are replaced by a single space character. Example:


C: FETCH 1 CONTENTS.PEEK=HEADERS(FROM,MIME-VERSION,CONTENT-TYPE)
S: {.300} FETCH 1 HEADERS
S: Mime-Version: 1.0
S: Content-Type: text/plain; charset=iso-8859-1
S: From: Tom Jones <tjones@example.com>
S: .
S: +OK Ok

Another example:


C: FETCH 1 CONTENTS.PEEK=HEADERS(:ENVELOPE)
S: {.300} FETCH 1 HEADERS
S: From: Tom Jones <tjones@example.com>
S: To: Bob Smith <bsmith@example.com>
S: Subject: Meeting
S: Message-ID: <802374jekdj90@example.com>
S: Date: Mon, 21 Apr 2002 16:56:11 -0400
S: .
S: +OK Ok

MIME(list)

Returns the header portion of all MIME sections in the message. list is a comma-separated list of case-insensitive header names, as in the HEADER keyword. Example:


C: FETCH 1 CONTENTS.PEEK=MIME(MIME-VERSION,CONTENT-TYPE,CONTENT-TRANSFER-ENCODING)
S: {.80} FETCH 1 LINES=207 SIZE=3120 MIME.ID=
S: Mime-Version: 1.0
S: Content-Type: multipart/mixed; boundary="0123456789ABCDEF"
S: .
S: {.40} FETCH 1 LINES=185 SIZE=1012 MIME.ID=1 MIME.PARENT=
S: Content-Type: multipart/alternative; boundary="ABCDEF0123456789"
S: .
S: {.80} FETCH 1 LINES=81 SIZE=208 "MIME.ID=1 1" MIME.PARENT=1
S: Content-Type: text/plain; charset=iso-8859-1
S: Content-Transfer-Encoding: quoted-printable
S: .
S: {.80} FETCH 1 LINES=42 SIZE=783 "MIME.ID=1 2" MIME.PARENT=1
S: Content-Type: text/html; charset=iso-8859-1
S: Content-Transfer-Encoding: quoted-printable
S: .
S: {.80} FETCH 1 LINES=50 SIZE=1257 MIME.ID=2 MIME.PARENT=
S: Content-Type: image/gif
S: Content-Transfer-Encoding: base64
S: .
S: {.80} FETCH 1 LINES=45 SIZE=907 MIME.ID=3 MIME.PARENT=
S: Content-Type: message/rfc822
S: .
S: {.120} FETCH 1 LINES=27 SIZE=452 "MIME.ID=3 1" MIME.PARENT=3
S: Mime-Version: 1.0
S: Content-Type: text/plain; charset=iso-8859-1
S: Content-Transfer-Encoding: 8bit
S: .
S: +OK Ok

RFC 2045, and related documents, specifies the format of MIME messages. A MIME message contains one or more individual or multipart MIME sections; a multipart MIME section itself contains inferior individual or multipart sections, forming a distinct hierarchy. Consult RFCs 2045 through 2049 for additional information.

MIME(list) parses the MIME structure of a message, and recursively returns the requested headers from each MIME section in the message. The server returns a series of multi-line replies, each reply carries headers from a single MIME section. The multi-line replies may be sent in any order, except that the headers for the topmost MIME section must always be sent first, and the headers from the other MIME sections may only be sent after the headers from their parent MIME section, and the headers from all of their preceding sibling MIME section (which is just a fancy way of saying that the server uses either the prefix or the infix traversal order).

The server assigns a unique MIME section ID to each MIME section. The method the server uses to generate a MIME section ID is entirely up to the server, with one exception: the MIME section ID for the entire message must be an empty string. SMAP clients should treat MIME section ID as opaque text strings, and must not interpret them in any way (except for the blank mime ID referring to the entire message).

MIME.ID=id specifies the MIME section ID of the following headers. MIME.PARENT=id specifies the MIME section ID of the parent MIME section (this attribute is not specified for the topmost MIME section, which has no parent). MIME.PARENT=id is not returned for the first, topmost MIME section, and since its MIME section ID is always an empty string, its inferior MIME section will have MIME.PARENT=, the empty id referring to the topmost MIME section.

The SMAP client uses this information to reconstruct the structure of the MIME message.

The above example shows a MIME multipart/mixed message with three sections. The first section is a MIME multipart/alternative with two subsections: text/plain and text/html. The second section is an image/gif, and the third section is a message/rfc822.

message/rfc822 MIME sections are parsed as multipart sections, with exactly one component section: the attached message. The above example shows that the attached message consists of a single text/plain section.

Note

The MIME.ID, MIME.PARENT, SIZE and LINES values may occur in any order. SIZE gives an estimated size of the content portion of the MIME section, and LINES gives the approximate number of text lines in the content portion of the MIME section. These numbers are not to be taken as exact counts, but as ballpark estimates.

HEADERS[id](list)

This is the same as HEADERS(list), except that the server returns headers from the MIME section specified by id. Example:


C: FETCH 1 "CONTENTS.PEEK=HEADERS[1 2](CONTENT-TYPE,CONTENT-TRANSFER-ENCODING)"
S: {.80} FETCH 1 HEADERS
S: Content-Type: text/html; charset=iso-8859-1
S: Content-Transfer-Encoding: quoted-printable
S: .
S: +OK Ok

BODY

Returns the only the body portion of the message. Example:


C: FETCH 1 CONTENTS=BODY
S: {.80} FETCH 1 BODY
S: Mary had a little lamb, its fleece was white as snow,
S: and everywhere Mary went, the lamb was sure to go.
S: .
S: +OK Ok

BODY[id]

Returns the only the body portion of the specified MIME section. Example:


C: FETCH 1 "CONTENTS=BODY[1 1]"
S: {.80} FETCH 1 BODY
S: Itsy-bitsy spider went up the water spout,
S: Down came the rain, and washed the spider out.
S: .
S: +OK Ok

ALL

Returns both the headers and the body portion of the message.

ALL[id]

Returns the headers, a blank line, then the body portion of the specified MIME section. Example:


C: FETCH 1 "CONTENTS=ALL[1 1]"
S: {.120} FETCH 1 ALL
S: Content-Type: text/plain; charset=iso-8859-1
S: Content-Transfer-Encoding: 7bit
S:
S: Itsy-bitsy spider went up the water spout,
S: Down came the rain, and washed the spider out.
S: .
S: +OK Ok

Note

Unlike HEADERS, folded header lines are not unfolded by ALL.

BODY.DECODED

Same as BODY except that the server automatically decodes the MIME-encoded section, and sends the raw decoded content as a binary, multi-line reply. Example:


C: FETCH 1 CONTENTS=BODY.DECODED
S: {322/322} FETCH 1 BODY.DECODED
S:
S: [ 322 bytes, then a blank line, follows ]
S: +OK Ok.

BODY.DECODED[id]

Return the decoded contents of the indicated MIME section.