pymap.message

Base implementations of the pymap.interfaces.message interfaces.

class pymap.message.BaseMessage(uid, internal_date, permanent_flags, *, email_id=None, thread_id=None, expunged=False)[source]

Message metadata such as UID, permanent flags, and when the message was added to the system.

Parameters:
  • uid (int) – The UID of the message.

  • internal_date (datetime) – The internal date of the message.

  • permanent_flags (Iterable[Flag]) – Permanent flags for the message.

  • email_id (ObjectId | None) – The message content identifier for the message.

  • thread_id (ObjectId | None) – The thread identifier for the message.

  • expunged (bool) – True if this message has been expunged from the mailbox.

property email_id: ObjectId

The message’s email object ID, which can identify its content.

See also

RFC 8474 5.1.

property thread_id: ObjectId

The message’s thread object ID, which groups messages together.

See also

RFC 8474 5.2.

property permanent_flags: frozenset[Flag]

The permanent flags for the message.

get_flags(session_flags)[source]

Get the full set of permanent and session flags for the message.

Parameters:

session_flags (SessionFlags) – The current session flags.

Return type:

frozenset[Flag]

property flags_key: tuple[int, frozenset[Flag]]

Hashable value that represents the current flags of this message, used for detecting mailbox updates.

class pymap.message.BaseLoadedMessage(message, requirement, content)[source]

The loaded message content, implemented using an instance of MessageContent.

Parameters:
property requirement: FetchRequirement

The FetchRequirement used to load the message content.

get_header(name)[source]

Get the values of a header from the message.

Parameters:

name (bytes) – The name of the header.

Return type:

Sequence[str]

get_headers(section)[source]

Get the headers from the message part.

The section argument indexes a nested sub-part of the message. For example, [2, 3] would get the 2nd sub-part of the message and then index it for its 3rd sub-part.

Parameters:

section (Sequence[int]) – Nested list of sub-part indexes.

Return type:

Writeable

get_body(section=None, binary=False)[source]

Get the full body of the message part, including headers.

The section argument can index a nested sub-part of the message. For example, [2, 3] would get the 2nd sub-part of the message and then index it for its 3rd sub-part.

Parameters:
  • section (Sequence[int] | None) – Optional nested list of sub-part indexes.

  • binary (bool) – True if the result has decoded any Content-Transfer-Encoding.

Return type:

Writeable

get_message_headers(section=None, subset=None, inverse=False)[source]

Get the headers from the message or a message/rfc822 sub-part of the message..

The section argument can index a nested sub-part of the message. For example, [2, 3] would get the 2nd sub-part of the message and then index it for its 3rd sub-part.

Parameters:
  • section (Sequence[int] | None) – Optional nested list of sub-part indexes.

  • subset (Collection[bytes] | None) – Subset of headers to get.

  • inverse (bool) – If subset is given, this flag will invert it so that the headers not in subset are returned.

Return type:

Writeable

get_message_text(section=None)[source]

Get the text of the message part, not including headers.

The section argument can index a nested sub-part of the message. For example, [2, 3] would get the 2nd sub-part of the message and then index it for its 3rd sub-part.

Parameters:

section (Sequence[int] | None) – Optional nested list of sub-part indexes.

Return type:

Writeable

get_size(section=None)[source]

Return the size of the message, in octets.

Parameters:

section (Sequence[int] | None) – Optional nested list of sub-part indexes.

Return type:

int

get_envelope_structure()[source]

Build and return the envelope structure.

See also

RFC 3501 2.3.5.

Return type:

EnvelopeStructure

get_body_structure()[source]

Build and return the body structure.

See also

RFC 3501 2.3.6

Return type:

BodyStructure

contains(value)[source]

Check the body of the message for a sub-string. This may be optimized to only search headers and text/* MIME parts.

Parameters:

value (bytes) – The sub-string to find.

Return type:

bool