pymap.mime

class pymap.mime.MessageContent(data, header, body)[source]

Contains the message content, parsed for IMAP processing.

Parameters:
lines

The number of lines in the message content.

walk()[source]

Iterate through the message and all its nested sub-parts in the order they occur.

Return type:

Iterable[MessageContent]

property is_rfc822: bool

True if the content-type of the message is message/rfc822.

property json: Mapping[str, Any]

A dictionary that can be serialized (e.g. with json), so that this object may be re-created without parsing.

See also

from_json()

classmethod from_json(data, json)[source]

Recover the parsed message content without re-parsing, using the original raw data and the json.

In this example, content1 and content2 should be equivalent:

message = b'...'
content1 = MessageContent.parse(message)
content2 = MessageContent.from_json(message, content1.json)
Parameters:
  • data (bytes) – The bytestring that was parsed.

  • json (Mapping[str, Any]) – The json of a previously parsed message content.

Return type:

MessageContent

classmethod parse(data)[source]

Parse the bytestring into message content.

Parameters:

data (bytes) – The bytestring to parse.

Return type:

MessageContent

write(writer)[source]

Write the object to the stream, with one or more calls to write().

Parameters:

writer (WriteStream) – The output stream.

Return type:

None

class pymap.mime.MessageHeader(data, lines, folded)[source]

The message header. Contains lines in the form of Header: value\n, possibly folded onto multiple lines where subsequent lines start with whitespace.

Parameters:
  • data (bytes)

  • lines (_Lines)

  • folded (_Folded)

folded

A list of headers, as they occurred in the original data, as tuples of the lower-cased header name and the full header value, including the header name and any extra folded lines.

parsed

The message headers, as a dictionary-like object that parses headers on-demand.

property lines: int

The number of lines in the message header.

property json: Mapping[str, Any]

A dictionary that can be serialized (e.g. with json), so that this object may be re-created without parsing.

See also

from_json()

classmethod from_json(data, json)[source]

Recover the parsed message header without re-parsing, using the original raw data and the json.

Parameters:
  • data (bytes) – The bytestring that was parsed.

  • json (Mapping[str, Any]) – The json of a previously parsed message content.

Return type:

MessageHeader

classmethod empty()[source]

Return an empty header object.

Return type:

MessageHeader

write(writer)[source]

Write the object to the stream, with one or more calls to write().

Parameters:

writer (WriteStream) – The output stream.

Return type:

None

class pymap.mime.MessageBody(data, lines, content_type, nested)[source]

The message body, starting immediately after the header. The body may contain nested sub-parts, which are each valid MessageContent objects.

Parameters:
  • data (bytes)

  • lines (_Lines)

  • content_type (ContentTypeHeader)

  • nested (Sequence[MessageContent])

content_type

The content type of the message body.

property lines: int

The number of lines in the message body.

property has_nested: bool

True if the message body is composed of nested sub-parts.

property nested: Sequence[MessageContent]

If has_nested is True, contains the list of sub-parts.

property json: Mapping[str, Any]

A dictionary that can be serialized (e.g. with json), so that this object may be re-created without parsing.

See also

from_json()

classmethod from_json(data, json)[source]

Recover the parsed message body without re-parsing, using the original raw data and the json.

Parameters:
  • data (bytes) – The bytestring that was parsed.

  • json (Mapping[str, Any]) – The json of a previously parsed message content.

Return type:

MessageBody

classmethod empty()[source]

Return an empty body object.

Return type:

MessageBody

write(writer)[source]

Write the object to the stream, with one or more calls to write().

Parameters:

writer (WriteStream) – The output stream.

Return type:

None

pymap.mime.cte

class pymap.mime.cte.MessageDecoder[source]

Decodes a MessageBody as decided by its Content-Transfer-Encoding header.

registry

Registry of custom decoders. Keys should be lower-case.

Type:

Dict[str, MessageDecoder]

classmethod of(msg_header)[source]

Return a decoder from the message header object.

See also

of_cte()

Parameters:

msg_header (MessageHeader) – The message header object.

Return type:

MessageDecoder

classmethod of_cte(header)[source]

Return a decoder from the CTE header value.

There is built-in support for 7bit, 8bit, quoted-printable, and base64 CTE header values. Decoders can be added or overridden with the registry dictionary.

Parameters:

header (ContentTransferEncodingHeader | None) – The CTE header value.

Return type:

MessageDecoder

abstract decode(body)[source]

Decode and return the decoded body of the message.

Parameters:

body (MessageBody) – The message body.

Return type:

Writeable

pymap.mime.parsed

class pymap.mime.parsed.ParsedHeaders(headers)[source]

The mapping of message headers, parsed on-demand using a HeaderRegistry. Also provides typed properties for standard headers used in IMAP processing.

Parameters:

headers (_Headers)

property content_type: ContentTypeHeader | None

The Content-Type header.

property date: DateHeader | None

The Date header.

property subject: UnstructuredHeader | None

The Subject header.

property from_: Sequence[AddressHeader] | None

The From header.

property sender: Sequence[SingleAddressHeader] | None

The Sender header.

property reply_to: Sequence[AddressHeader] | None

The Reply-To header.

property to: Sequence[AddressHeader] | None

The To header.

property cc: Sequence[AddressHeader] | None

The Cc header.

property bcc: Sequence[AddressHeader] | None

The Bcc header.

property in_reply_to: UnstructuredHeader | None

The In-Reply-To header.

property references: UnstructuredHeader | None

The References header.

property message_id: UnstructuredHeader | None

The Message-Id header.

property content_disposition: ContentDispositionHeader | None

The Content-Disposition header.

property content_language: UnstructuredHeader | None

The Content-Language header.

property content_location: UnstructuredHeader | None

The Content-Location header.

property content_id: UnstructuredHeader | None

The Content-Id header.

property content_description: UnstructuredHeader | None

The Content-Description header.

property content_transfer_encoding: ContentTransferEncodingHeader | None

The Content-Transfer-Encoding header.