mailbox.Mailbox.get_file()

get_file(key) Return a file-like representation of the message corresponding to key, or raise a KeyError exception if no such message exists. The file-like object behaves as if open in binary mode. This file should be closed once it is no longer needed. Changed in version 3.2: The file object really is a binary file; previously it was incorrectly returned in text mode. Also, the file-like object now supports the context management protocol: you can use a with statement to automatically clos

mailbox.Mailbox.get_bytes()

get_bytes(key) Return a byte representation of the message corresponding to key, or raise a KeyError exception if no such message exists. New in version 3.2.

mailbox.Mailbox.get()

get(key, default=None) __getitem__(key) Return a representation of the message corresponding to key. If no such message exists, default is returned if the method was called as get() and a KeyError exception is raised if the method was called as __getitem__(). The message is represented as an instance of the appropriate format-specific Message subclass unless a custom message factory was specified when the Mailbox instance was initialized.

mailbox.Mailbox.flush()

flush() Write any pending changes to the filesystem. For some Mailbox subclasses, changes are always written immediately and flush() does nothing, but you should still make a habit of calling this method.

mailbox.Mailbox.discard()

discard(key) Delete the message corresponding to key from the mailbox. If no such message exists, a KeyError exception is raised if the method was called as remove() or __delitem__() but no exception is raised if the method was called as discard(). The behavior of discard() may be preferred if the underlying mailbox format supports concurrent modification by other processes.

mailbox.Mailbox.close()

close() Flush the mailbox, unlock it if necessary, and close any open files. For some Mailbox subclasses, this method does nothing.

mailbox.Mailbox.clear()

clear() Delete all messages from the mailbox.

mailbox.Mailbox.add()

add(message) Add message to the mailbox and return the key that has been assigned to it. Parameter message may be a Message instance, an email.message.Message instance, a string, a byte string, or a file-like object (which should be open in binary mode). If message is an instance of the appropriate format-specific Message subclass (e.g., if it’s an mboxMessage instance and this is an mbox instance), its format-specific information is used. Otherwise, reasonable defaults for format-specific i

mailbox.Mailbox

class mailbox.Mailbox A mailbox, which may be inspected and modified. The Mailbox class defines an interface and is not intended to be instantiated. Instead, format-specific subclasses should inherit from Mailbox and your code should instantiate a particular subclass. The Mailbox interface is dictionary-like, with small keys corresponding to messages. Keys are issued by the Mailbox instance with which they will be used and are only meaningful to that Mailbox instance. A key continues to iden

mailbox.FormatError

exception mailbox.FormatError Raised when the data in a file cannot be parsed, such as when an MH instance attempts to read a corrupted .mh_sequences file.