pymap.mime
¶
- class pymap.mime.MessageContent(data, header, body)[source]¶
Contains the message content, parsed for IMAP processing.
- Parameters:
data (bytes) – The message literal.
header (MessageHeader) – The parsed message header.
body (MessageBody) – The parsed message body.
- 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:
- 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
- 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
andcontent2
should be equivalent:message = b'...' content1 = MessageContent.parse(message) content2 = MessageContent.from_json(message, content1.json)
- classmethod parse(data)[source]¶
Parse the bytestring into message content.
- Parameters:
data (bytes) – The bytestring to parse.
- Return type:
- 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 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
- classmethod from_json(data, json)[source]¶
Recover the parsed message header without re-parsing, using the original raw data and the
json
.See also
- 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 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
- classmethod from_json(data, json)[source]¶
Recover the parsed message body without re-parsing, using the original raw data and the
json
.See also
- 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 itsContent-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
- Parameters:
msg_header (MessageHeader) – The message header object.
- Return type:
- classmethod of_cte(header)[source]¶
Return a decoder from the CTE header value.
There is built-in support for
7bit
,8bit
,quoted-printable
, andbase64
CTE header values. Decoders can be added or overridden with theregistry
dictionary.- Parameters:
header (ContentTransferEncodingHeader | None) – The CTE header value.
- Return type:
- abstract decode(body)[source]¶
Decode and return the decoded body of the message.
- Parameters:
body (MessageBody) – The message body.
- Return type:
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.