PyDocs

Nav

Internet Data Handling

Message

  • Message(policy=compat32)
Basic message object.

A message object is defined as something that has a bunch of RFC 5322
headers and a payload.  It may optionally have an envelope header
(a.k.a. Unix-From or From_ header).  If the message is a container (i.e. a
multipart or a message/rfc822), then the payload is a list of Message
objects, otherwise it is a string.

Message objects implement part of the 'mapping' interface, which assumes
there is exactly one occurrence of the header per message.  Some headers
do in fact appear multiple times (e.g. Received) and for those headers,
you must use the explicit API to set or get all the headers.  Not all of
the mapping methods are implemented.
Changed in 3.3
  • 3.3: The policy keyword argument was added.
Members of Message

_

__bytes__
Return the entire formatted message as a bytes object.
__contains__
Return True if the message object has a field named name.
__delitem__
Delete all occurrences of a header, if present.
__getitem__
Get a header value.
__len__
Return the total number of headers, including duplicates.
__setitem__
Set the value of a header.
__str__
Return the entire formatted message as a string.

a

add_header
Extended header setting.
as_bytes
Return the entire formatted message as a bytes object.
as_string
Return the entire formatted message as a string.
attach
Add the given payload to the current payload.

d

defects
The defects attribute contains a list of all the problems found when parsing this message.
del_param
Remove the given parameter completely from the Content-Type header.

e

epilogue
The epilogue attribute acts the same way as the preamble attribute, except that it contains text that appears between the last boundary and the end of the message.

g

get
Get a header value.
get_all
Return a list of all the values for the named field.
get_boundary
Return the boundary associated with the payload if present.
get_charset
Return the Charset instance associated with the message's payload.
get_charsets
Return a list containing the charset(s) used in this message.
get_content_charset
Return the charset parameter of the Content-Type header.
get_content_disposition
Return the message's content-disposition if it exists, or None.
get_content_maintype
Return the message's main content type.
get_content_subtype
Returns the message's sub-content type.
get_content_type
Return the message's content type.
get_default_type
Return the 'default' content type.
get_filename
Return the filename associated with the payload if present.
get_param
Return the parameter value if found in the Content-Type header.
get_params
Return the message's Content-Type parameters, as a list.
get_payload
Return a reference to the payload.
get_unixfrom
Return the message’s envelope header.

i

is_multipart
Return True if the message consists of multiple parts.
items
Get all the message's header fields and values.

k

keys
Return a list of all the message's header field names.

p

preamble
The format of a MIME document allows for some text between the blank line following the headers, and the first multipart boundary string.

r

replace_header
Replace a header.

s

set_boundary
Set the boundary parameter in Content-Type to 'boundary'.
set_charset
Set the charset of the payload to a given character set.
set_default_type
Set the 'default' content type.
set_param
Set a parameter in the Content-Type header.
set_payload
Set the payload to the given value.
set_type
Set the main type and subtype for the Content-Type header.
set_unixfrom
Set the message’s envelope header to unixfrom, which should be a string.

v

values
Return a list of all the message's header values.

w

walk
Walk over the message tree, yielding each subpart.
0 Examples
No examples for email.message/Message.
See Also
No see-alsos for email.message/Message
0 Notes
No notes for Message