On this page
mailbox.mboxMessage
Prev: mailbox.mbox | Up: mailbox | Next: mailbox.Message
Rel: mailbox.Babyl, mailbox.BabylMessage, mailbox.Error, mailbox.ExternalClashError
Ref: docs.python.org — mailbox.mboxMessage
Tags: #public #python3 #stdlib #mailbox
Import
import mailbox
from mailbox import mboxMessage
Signature & Overview
mailbox.mboxMessage(message=None)
Message with mbox-specific properties.
Methods & Attributes
mboxMessage.add_flag(self, flag)— Set the given flag(s) without changing others.mboxMessage.add_header(self, _name, _value, **_params)— Extended header setting.mboxMessage.as_bytes(self, unixfrom=False, policy=None)— Return the entire formatted message as a bytes object.mboxMessage.as_string(self, unixfrom=False, maxheaderlen=0, policy=None)— Return the entire formatted message as a string.mboxMessage.attach(self, payload)— Add the given payload to the current payload.mboxMessage.del_param(self, param, header='content-type', requote=True)— Remove the given parameter completely from the Content-Type header.mboxMessage.get(self, name, failobj=None)— Get a header value.mboxMessage.get_all(self, name, failobj=None)— Return a list of all the values for the named field.mboxMessage.get_boundary(self, failobj=None)— Return the boundary associated with the payload if present.mboxMessage.get_charset(self)— Return the Charset instance associated with the message's payload.mboxMessage.get_charsets(self, failobj=None)— Return a list containing the charset(s) used in this message.mboxMessage.get_content_charset(self, failobj=None)— Return the charset parameter of the Content-Type header.mboxMessage.get_content_disposition(self)— Return the message's content-disposition if it exists, or None.mboxMessage.get_content_maintype(self)— Return the message's main content type.mboxMessage.get_content_subtype(self)— Returns the message's sub-content type.mboxMessage.get_content_type(self)— Return the message's content type.mboxMessage.get_default_type(self)— Return the 'default' content type.mboxMessage.get_filename(self, failobj=None)— Return the filename associated with the payload if present.mboxMessage.get_flags(self)— Return as a string the flags that are set.mboxMessage.get_from(self)— Return contents of "From " line.mboxMessage.get_param(self, param, failobj=None, header='content-type', unquote=True)— Return the parameter value if found in the Content-Type header.mboxMessage.get_params(self, failobj=None, header='content-type', unquote=True)— Return the message's Content-Type parameters, as a list.mboxMessage.get_payload(self, i=None, decode=False)— Return a reference to the payload.mboxMessage.get_unixfrom(self)—mboxMessage.get_unixfrommethod/property.mboxMessage.is_multipart(self)— Return True if the message consists of multiple parts.mboxMessage.items(self)— Get all the message's header fields and values.mboxMessage.keys(self)— Return a list of all the message's header field names.mboxMessage.raw_items(self)— Return the (name, value) header pairs without modification.mboxMessage.remove_flag(self, flag)— Unset the given string flag(s) without changing others.mboxMessage.replace_header(self, _name, _value)— Replace a header.mboxMessage.set_boundary(self, boundary)— Set the boundary parameter in Content-Type to 'boundary'.mboxMessage.set_charset(self, charset)— Set the charset of the payload to a given character set.mboxMessage.set_default_type(self, ctype)— Set the 'default' content type.mboxMessage.set_flags(self, flags)— Set the given flags and unset all others.mboxMessage.set_from(self, from_, time_=None)— Set "From " line, formatting and appending time_ if specified.mboxMessage.set_param(self, param, value, header='Content-Type', requote=True, charset=None, language='', replace=False)— Set a parameter in the Content-Type header.mboxMessage.set_payload(self, payload, charset=None)— Set the payload to the given value.mboxMessage.set_raw(self, name, value)— Store name and value in the model without modification.mboxMessage.set_type(self, type, header='Content-Type', requote=True)— Set the main type and subtype for the Content-Type header.mboxMessage.set_unixfrom(self, unixfrom)—mboxMessage.set_unixfrommethod/property.
Usage
import mailbox
m = mailbox.mboxMessage()
m.set_from("alice@example.com")
m.add_flag("R")
assert "alice@example.com" in m.get_from() and "R" in m.get_flags()
Gotchas
- Manages the
Fromenvelope line andStatus/X-Statusheaders.
REPL Inspect
from mailbox import mboxMessage
help(mboxMessage)
Linked from
Related notes
- tuts/python3/stdlib_module/mailbox/mbox Linked here; links to this page; shared tags: #mailbox, #stdlib
- tuts/python3/stdlib_module/mailbox/Message 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