On this page
mailbox.Message
Prev: mailbox.mboxMessage | Up: mailbox | Next: mailbox.MH
Rel: mailbox.Babyl, mailbox.BabylMessage, mailbox.Error, mailbox.ExternalClashError
Ref: docs.python.org — mailbox.Message
Tags: #public #python3 #stdlib #mailbox
Import
import mailbox
from mailbox import Message
Signature & Overview
mailbox.Message(message=None)
Message with mailbox-format-specific properties.
Methods & Attributes
Message.add_header(self, _name, _value, **_params)— Extended header setting.Message.as_bytes(self, unixfrom=False, policy=None)— Return the entire formatted message as a bytes object.Message.as_string(self, unixfrom=False, maxheaderlen=0, policy=None)— Return the entire formatted message as a string.Message.attach(self, payload)— Add the given payload to the current payload.Message.del_param(self, param, header='content-type', requote=True)— Remove the given parameter completely from the Content-Type header.Message.get(self, name, failobj=None)— Get a header value.Message.get_all(self, name, failobj=None)— Return a list of all the values for the named field.Message.get_boundary(self, failobj=None)— Return the boundary associated with the payload if present.Message.get_charset(self)— Return the Charset instance associated with the message's payload.Message.get_charsets(self, failobj=None)— Return a list containing the charset(s) used in this message.Message.get_content_charset(self, failobj=None)— Return the charset parameter of the Content-Type header.Message.get_content_disposition(self)— Return the message's content-disposition if it exists, or None.Message.get_content_maintype(self)— Return the message's main content type.Message.get_content_subtype(self)— Returns the message's sub-content type.Message.get_content_type(self)— Return the message's content type.Message.get_default_type(self)— Return the 'default' content type.Message.get_filename(self, failobj=None)— Return the filename associated with the payload if present.Message.get_param(self, param, failobj=None, header='content-type', unquote=True)— Return the parameter value if found in the Content-Type header.Message.get_params(self, failobj=None, header='content-type', unquote=True)— Return the message's Content-Type parameters, as a list.Message.get_payload(self, i=None, decode=False)— Return a reference to the payload.Message.get_unixfrom(self)—Message.get_unixfrommethod/property.Message.is_multipart(self)— Return True if the message consists of multiple parts.Message.items(self)— Get all the message's header fields and values.Message.keys(self)— Return a list of all the message's header field names.Message.raw_items(self)— Return the (name, value) header pairs without modification.Message.replace_header(self, _name, _value)— Replace a header.Message.set_boundary(self, boundary)— Set the boundary parameter in Content-Type to 'boundary'.Message.set_charset(self, charset)— Set the charset of the payload to a given character set.Message.set_default_type(self, ctype)— Set the 'default' content type.Message.set_param(self, param, value, header='Content-Type', requote=True, charset=None, language='', replace=False)— Set a parameter in the Content-Type header.Message.set_payload(self, payload, charset=None)— Set the payload to the given value.Message.set_raw(self, name, value)— Store name and value in the model without modification.Message.set_type(self, type, header='Content-Type', requote=True)— Set the main type and subtype for the Content-Type header.Message.set_unixfrom(self, unixfrom)—Message.set_unixfrommethod/property.Message.values(self)— Return a list of all the message's header values.Message.walk(self)— Walk over the message tree, yielding each subpart.
Usage
import mailbox
msg = mailbox.Message()
msg["From"] = "a@example.com"
assert msg["From"] == "a@example.com"
Gotchas
- Inherits from legacy
email.message.Message: Pass a customfactory=usingemail.policy.defaultwhen opening mailboxes if you want modernEmailMessageAPIs.
REPL Inspect
from mailbox import Message
help(Message)
Linked from
Related notes
- tuts/python3/stdlib_module/mailbox/mboxMessage Linked here; links to this page; shared tags: #mailbox, #stdlib
- tuts/python3/stdlib_module/mailbox/MH Linked here; links to this page; shared tags: #mailbox, #stdlib
- tuts/python3/stdlib_module/mailbox/Babyl Linked here; shared tags: #mailbox, #stdlib
- tuts/python3/stdlib_module/mailbox/BabylMessage Linked here; shared tags: #mailbox, #stdlib
- tuts/python3/stdlib_module/mailbox/Error Linked here; shared tags: #mailbox, #stdlib
- tuts/python3/stdlib_module/mailbox/ExternalClashError Linked here; shared tags: #mailbox, #stdlib
- tuts/python3/stdlib_module/mailbox/Mailbox Linked here; shared tags: #mailbox, #stdlib
- tuts/python3/stdlib_module/mailbox links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/mailbox/FormatError shared tags: #mailbox, #stdlib
- tuts/python3/stdlib_module/mailbox/Maildir shared tags: #mailbox, #stdlib