| :class:`Mailbox` objects |
| ------------------------ |
| |
| |
| .. class:: Mailbox |
| |
| A mailbox, which may be inspected and modified. |
| |
n | The :class:`Mailbox` class defines an interface and is not intended to be |
| instantiated. Instead, format-specific subclasses should inherit from |
| :class:`Mailbox` and your code should instantiate a particular subclass. |
| |
| The :class:`Mailbox` interface is dictionary-like, with small keys corresponding |
| The :class:`Mailbox` interface is dictionary-like, with small keys |
| to messages. Keys are issued by the :class:`Mailbox` instance with which they |
| corresponding to messages. Keys are issued by the :class:`Mailbox` instance |
| will be used and are only meaningful to that :class:`Mailbox` instance. A key |
| with which they will be used and are only meaningful to that :class:`Mailbox` |
| continues to identify a message even if the corresponding message is modified, |
| instance. A key continues to identify a message even if the corresponding |
| such as by replacing it with another message. Messages may be added to a |
| message is modified, such as by replacing it with another message. |
| :class:`Mailbox` instance using the set-like method :meth:`add` and removed |
| using a ``del`` statement or the set-like methods :meth:`remove` and |
| :meth:`discard`. |
| |
n | Messages may be added to a :class:`Mailbox` instance using the set-like |
| method :meth:`add` and removed using a ``del`` statement or the set-like |
| methods :meth:`remove` and :meth:`discard`. |
| |
| :class:`Mailbox` interface semantics differ from dictionary semantics in some |
| :class:`Mailbox` interface semantics differ from dictionary semantics in some |
| noteworthy ways. Each time a message is requested, a new representation |
| noteworthy ways. Each time a message is requested, a new representation |
| (typically a :class:`Message` instance) is generated, based upon the current |
| (typically a :class:`Message` instance) is generated based upon the current |
| state of the mailbox. Similarly, when a message is added to a :class:`Mailbox` |
| state of the mailbox. Similarly, when a message is added to a |
| instance, the provided message representation's contents are copied. In neither |
| :class:`Mailbox` instance, the provided message representation's contents are |
| case is a reference to the message representation kept by the :class:`Mailbox` |
| copied. In neither case is a reference to the message representation kept by |
| instance. |
| the :class:`Mailbox` instance. |
| |
n | The default :class:`Mailbox` iterator iterates over message representations, not |
n | The default :class:`Mailbox` iterator iterates over message representations, |
| keys as the default dictionary iterator does. Moreover, modification of a |
| not keys as the default dictionary iterator does. Moreover, modification of a |
| mailbox during iteration is safe and well-defined. Messages added to the mailbox |
| mailbox during iteration is safe and well-defined. Messages added to the |
| after an iterator is created will not be seen by the iterator. Messages removed |
| mailbox after an iterator is created will not be seen by the |
| from the mailbox before the iterator yields them will be silently skipped, |
| iterator. Messages removed from the mailbox before the iterator yields them |
| though using a key from an iterator may result in a :exc:`KeyError` exception if |
| will be silently skipped, though using a key from an iterator may result in a |
| the corresponding message is subsequently removed. |
| :exc:`KeyError` exception if the corresponding message is subsequently |
| removed. |
| |
n | :class:`Mailbox` itself is intended to define an interface and to be inherited |
n | .. warning:: |
| from by format-specific subclasses but is not intended to be instantiated. |
| Instead, you should instantiate a subclass. |
| |
n | Be very cautious when modifying mailboxes that might be simultaneously |
| changed by some other process. The safest mailbox format to use for such |
| tasks is Maildir; try to avoid using single-file formats such as mbox for |
| concurrent writing. If you're modifying a mailbox, you *must* lock it by |
| calling the :meth:`lock` and :meth:`unlock` methods *before* reading any |
| messages in the file or making any changes by adding or deleting a |
| message. Failing to lock the mailbox runs the risk of losing messages or |
| corrupting the entire mailbox. |
| |
| :class:`Mailbox` instances have the following methods: |
| :class:`Mailbox` instances have the following methods: |
| |
| |
n | .. method:: Mailbox.add(message) |
n | .. method:: add(message) |
| |
n | Add *message* to the mailbox and return the key that has been assigned to it. |
n | Add *message* to the mailbox and return the key that has been assigned to |
| it. |
| |
n | Parameter *message* may be a :class:`Message` instance, an |
n | Parameter *message* may be a :class:`Message` instance, an |
| :class:`email.Message.Message` instance, a string, or a file-like object (which |
| :class:`email.Message.Message` instance, a string, or a file-like object |
| should be open in text mode). If *message* is an instance of the appropriate |
| (which should be open in text mode). If *message* is an instance of the |
| format-specific :class:`Message` subclass (e.g., if it's an :class:`mboxMessage` |
| appropriate format-specific :class:`Message` subclass (e.g., if it's an |
| instance and this is an :class:`mbox` instance), its format-specific information |
| :class:`mboxMessage` instance and this is an :class:`mbox` instance), its |
| is used. Otherwise, reasonable defaults for format-specific information are |
| format-specific information is used. Otherwise, reasonable defaults for |
| used. |
| format-specific information are used. |
| |
| |
n | .. method:: Mailbox.remove(key) |
n | .. method:: remove(key) |
| Mailbox.__delitem__(key) |
| __delitem__(key) |
| Mailbox.discard(key) |
| discard(key) |
| |
n | Delete the message corresponding to *key* from the mailbox. |
n | Delete the message corresponding to *key* from the mailbox. |
| |
n | If no such message exists, a :exc:`KeyError` exception is raised if the method |
n | If no such message exists, a :exc:`KeyError` exception is raised if the |
| was called as :meth:`remove` or :meth:`__delitem__` but no exception is raised |
| method was called as :meth:`remove` or :meth:`__delitem__` but no |
| if the method was called as :meth:`discard`. The behavior of :meth:`discard` may |
| exception is raised if the method was called as :meth:`discard`. The |
| be preferred if the underlying mailbox format supports concurrent modification |
| behavior of :meth:`discard` may be preferred if the underlying mailbox |
| by other processes. |
| format supports concurrent modification by other processes. |
| |
| |
n | .. method:: Mailbox.__setitem__(key, message) |
n | .. method:: __setitem__(key, message) |
| |
n | Replace the message corresponding to *key* with *message*. Raise a |
n | Replace the message corresponding to *key* with *message*. Raise a |
| :exc:`KeyError` exception if no message already corresponds to *key*. |
| :exc:`KeyError` exception if no message already corresponds to *key*. |
| |
n | As with :meth:`add`, parameter *message* may be a :class:`Message` instance, an |
n | As with :meth:`add`, parameter *message* may be a :class:`Message` |
| :class:`email.Message.Message` instance, a string, or a file-like object (which |
| instance, an :class:`email.Message.Message` instance, a string, or a |
| should be open in text mode). If *message* is an instance of the appropriate |
| file-like object (which should be open in text mode). If *message* is an |
| format-specific :class:`Message` subclass (e.g., if it's an :class:`mboxMessage` |
| instance of the appropriate format-specific :class:`Message` subclass |
| (e.g., if it's an :class:`mboxMessage` instance and this is an |
| instance and this is an :class:`mbox` instance), its format-specific information |
| :class:`mbox` instance), its format-specific information is |
| is used. Otherwise, the format-specific information of the message that |
| used. Otherwise, the format-specific information of the message that |
| currently corresponds to *key* is left unchanged. |
| currently corresponds to *key* is left unchanged. |
| |
| |
n | .. method:: Mailbox.iterkeys() |
n | .. method:: iterkeys() |
| Mailbox.keys() |
| keys() |
| |
n | Return an iterator over all keys if called as :meth:`iterkeys` or return a list |
n | Return an iterator over all keys if called as :meth:`iterkeys` or return a |
| of keys if called as :meth:`keys`. |
| list of keys if called as :meth:`keys`. |
| |
| |
n | .. method:: Mailbox.itervalues() |
n | .. method:: itervalues() |
| Mailbox.__iter__() |
| __iter__() |
| Mailbox.values() |
| values() |
| |
n | Return an iterator over representations of all messages if called as |
n | Return an iterator over representations of all messages if called as |
| :meth:`itervalues` or :meth:`__iter__` or return a list of such representations |
| :meth:`itervalues` or :meth:`__iter__` or return a list of such |
| if called as :meth:`values`. The messages are represented as instances of the |
| representations if called as :meth:`values`. The messages are represented |
| appropriate format-specific :class:`Message` subclass unless a custom message |
| as instances of the appropriate format-specific :class:`Message` subclass |
| factory was specified when the :class:`Mailbox` instance was initialized. |
| unless a custom message factory was specified when the :class:`Mailbox` |
| instance was initialized. |
| |
n | .. note:: |
n | .. note:: |
| |
n | The behavior of :meth:`__iter__` is unlike that of dictionaries, which iterate |
n | The behavior of :meth:`__iter__` is unlike that of dictionaries, which |
| over keys. |
| iterate over keys. |
| |
| |
n | .. method:: Mailbox.iteritems() |
n | .. method:: iteritems() |
| Mailbox.items() |
| items() |
| |
n | Return an iterator over (*key*, *message*) pairs, where *key* is a key and |
n | Return an iterator over (*key*, *message*) pairs, where *key* is a key and |
| *message* is a message representation, if called as :meth:`iteritems` or return |
| *message* is a message representation, if called as :meth:`iteritems` or |
| a list of such pairs if called as :meth:`items`. The messages are represented as |
| return a list of such pairs if called as :meth:`items`. The messages are |
| instances of the appropriate format-specific :class:`Message` subclass unless a |
| represented as instances of the appropriate format-specific |
| custom message factory was specified when the :class:`Mailbox` instance was |
| :class:`Message` subclass unless a custom message factory was specified |
| initialized. |
| when the :class:`Mailbox` instance was initialized. |
| |
| |
n | .. method:: Mailbox.get(key[, default=None]) |
n | .. method:: get(key[, default=None]) |
| Mailbox.__getitem__(key) |
| __getitem__(key) |
| |
n | Return a representation of the message corresponding to *key*. If no such |
n | Return a representation of the message corresponding to *key*. If no such |
| message exists, *default* is returned if the method was called as :meth:`get` |
| message exists, *default* is returned if the method was called as |
| and a :exc:`KeyError` exception is raised if the method was called as |
| :meth:`get` and a :exc:`KeyError` exception is raised if the method was |
| :meth:`__getitem__`. The message is represented as an instance of the |
| called as :meth:`__getitem__`. The message is represented as an instance |
| appropriate format-specific :class:`Message` subclass unless a custom message |
| of the appropriate format-specific :class:`Message` subclass unless a |
| factory was specified when the :class:`Mailbox` instance was initialized. |
| custom message factory was specified when the :class:`Mailbox` instance |
| was initialized. |
| |
| |
n | .. method:: Mailbox.get_message(key) |
n | .. method:: get_message(key) |
| |
n | Return a representation of the message corresponding to *key* as an instance of |
n | Return a representation of the message corresponding to *key* as an |
| the appropriate format-specific :class:`Message` subclass, or raise a |
| instance of the appropriate format-specific :class:`Message` subclass, or |
| :exc:`KeyError` exception if no such message exists. |
| raise a :exc:`KeyError` exception if no such message exists. |
| |
| |
n | .. method:: Mailbox.get_string(key) |
n | .. method:: get_string(key) |
| |
n | Return a string representation of the message corresponding to *key*, or raise a |
n | Return a string representation of the message corresponding to *key*, or |
| :exc:`KeyError` exception if no such message exists. |
| raise a :exc:`KeyError` exception if no such message exists. |
| |
| |
n | .. method:: Mailbox.get_file(key) |
n | .. method:: get_file(key) |
| |
n | Return a file-like representation of the message corresponding to *key*, or |
n | Return a file-like representation of the message corresponding to *key*, |
| raise a :exc:`KeyError` exception if no such message exists. The file-like |
| or raise a :exc:`KeyError` exception if no such message exists. The |
| object behaves as if open in binary mode. This file should be closed once it is |
| file-like object behaves as if open in binary mode. This file should be |
| no longer needed. |
| closed once it is no longer needed. |
| |
n | .. note:: |
n | .. note:: |
| |
n | Unlike other representations of messages, file-like representations are not |
n | Unlike other representations of messages, file-like representations are |
| necessarily independent of the :class:`Mailbox` instance that created them or of |
| not necessarily independent of the :class:`Mailbox` instance that |
| the underlying mailbox. More specific documentation is provided by each |
| created them or of the underlying mailbox. More specific documentation |
| subclass. |
| is provided by each subclass. |
| |
| |
n | .. method:: Mailbox.has_key(key) |
n | .. method:: has_key(key) |
| Mailbox.__contains__(key) |
| __contains__(key) |
| |
n | Return ``True`` if *key* corresponds to a message, ``False`` otherwise. |
n | Return ``True`` if *key* corresponds to a message, ``False`` otherwise. |
| |
| |
n | .. method:: Mailbox.__len__() |
n | .. method:: __len__() |
| |
n | Return a count of messages in the mailbox. |
n | Return a count of messages in the mailbox. |
| |
| |
n | .. method:: Mailbox.clear() |
n | .. method:: clear() |
| |
n | Delete all messages from the mailbox. |
n | Delete all messages from the mailbox. |
| |
| |
n | .. method:: Mailbox.pop(key[, default]) |
n | .. method:: pop(key[, default]) |
| |
n | Return a representation of the message corresponding to *key* and delete the |
n | Return a representation of the message corresponding to *key* and delete |
| message. If no such message exists, return *default* if it was supplied or else |
| the message. If no such message exists, return *default* if it was |
| raise a :exc:`KeyError` exception. The message is represented as an instance of |
| supplied or else raise a :exc:`KeyError` exception. The message is |
| the appropriate format-specific :class:`Message` subclass unless a custom |
| represented as an instance of the appropriate format-specific |
| message factory was specified when the :class:`Mailbox` instance was |
| :class:`Message` subclass unless a custom message factory was specified |
| initialized. |
| when the :class:`Mailbox` instance was initialized. |
| |
| |
n | .. method:: Mailbox.popitem() |
n | .. method:: popitem() |
| |
n | Return an arbitrary (*key*, *message*) pair, where *key* is a key and *message* |
n | Return an arbitrary (*key*, *message*) pair, where *key* is a key and |
| is a message representation, and delete the corresponding message. If the |
| *message* is a message representation, and delete the corresponding |
| mailbox is empty, raise a :exc:`KeyError` exception. The message is represented |
| message. If the mailbox is empty, raise a :exc:`KeyError` exception. The |
| as an instance of the appropriate format-specific :class:`Message` subclass |
| message is represented as an instance of the appropriate format-specific |
| unless a custom message factory was specified when the :class:`Mailbox` instance |
| :class:`Message` subclass unless a custom message factory was specified |
| was initialized. |
| when the :class:`Mailbox` instance was initialized. |
| |
| |
n | .. method:: Mailbox.update(arg) |
n | .. method:: update(arg) |
| |
n | Parameter *arg* should be a *key*-to-*message* mapping or an iterable of (*key*, |
n | Parameter *arg* should be a *key*-to-*message* mapping or an iterable of |
| *message*) pairs. Updates the mailbox so that, for each given *key* and |
| (*key*, *message*) pairs. Updates the mailbox so that, for each given |
| *message*, the message corresponding to *key* is set to *message* as if by using |
| *key* and *message*, the message corresponding to *key* is set to |
| :meth:`__setitem__`. As with :meth:`__setitem__`, each *key* must already |
| *message* as if by using :meth:`__setitem__`. As with :meth:`__setitem__`, |
| correspond to a message in the mailbox or else a :exc:`KeyError` exception will |
| each *key* must already correspond to a message in the mailbox or else a |
| be raised, so in general it is incorrect for *arg* to be a :class:`Mailbox` |
| :exc:`KeyError` exception will be raised, so in general it is incorrect |
| instance. |
| for *arg* to be a :class:`Mailbox` instance. |
| |
n | .. note:: |
n | .. note:: |
| |
n | Unlike with dictionaries, keyword arguments are not supported. |
n | Unlike with dictionaries, keyword arguments are not supported. |
| |
| |
n | .. method:: Mailbox.flush() |
n | .. method:: flush() |
| |
n | Write any pending changes to the filesystem. For some :class:`Mailbox` |
n | Write any pending changes to the filesystem. For some :class:`Mailbox` |
| subclasses, changes are always written immediately and this method does nothing. |
| subclasses, changes are always written immediately and :meth:`flush` does |
| nothing, but you should still make a habit of calling this method. |
| |
| |
n | .. method:: Mailbox.lock() |
n | .. method:: lock() |
| |
n | Acquire an exclusive advisory lock on the mailbox so that other processes know |
n | Acquire an exclusive advisory lock on the mailbox so that other processes |
| not to modify it. An :exc:`ExternalClashError` is raised if the lock is not |
| know not to modify it. An :exc:`ExternalClashError` is raised if the lock |
| available. The particular locking mechanisms used depend upon the mailbox |
| is not available. The particular locking mechanisms used depend upon the |
| format. |
| mailbox format. You should *always* lock the mailbox before making any |
| modifications to its contents. |
| |
| |
n | .. method:: Mailbox.unlock() |
n | .. method:: unlock() |
| |
n | Release the lock on the mailbox, if any. |
n | Release the lock on the mailbox, if any. |
| |
| |
n | .. method:: Mailbox.close() |
n | .. method:: close() |
| |
n | Flush the mailbox, unlock it if necessary, and close any open files. For some |
n | Flush the mailbox, unlock it if necessary, and close any open files. For |
| :class:`Mailbox` subclasses, this method does nothing. |
| some :class:`Mailbox` subclasses, this method does nothing. |
| |
| |
| .. _mailbox-maildir: |
| |
| :class:`Maildir` |
| ^^^^^^^^^^^^^^^^ |
| |
| |
| representation. If *create* is ``True``, the mailbox is created if it does not |
| exist. |
| |
| It is for historical reasons that *factory* defaults to :class:`rfc822.Message` |
| and that *dirname* is named as such rather than *path*. For a :class:`Maildir` |
| instance that behaves like instances of other :class:`Mailbox` subclasses, set |
| *factory* to ``None``. |
| |
n | Maildir is a directory-based mailbox format invented for the qmail mail transfer |
n | Maildir is a directory-based mailbox format invented for the qmail mail |
| agent and now widely supported by other programs. Messages in a Maildir mailbox |
| transfer agent and now widely supported by other programs. Messages in a |
| are stored in separate files within a common directory structure. This design |
| Maildir mailbox are stored in separate files within a common directory |
| allows Maildir mailboxes to be accessed and modified by multiple unrelated |
| structure. This design allows Maildir mailboxes to be accessed and modified |
| programs without data corruption, so file locking is unnecessary. |
| by multiple unrelated programs without data corruption, so file locking is |
| unnecessary. |
| |
n | Maildir mailboxes contain three subdirectories, namely: :file:`tmp`, |
n | Maildir mailboxes contain three subdirectories, namely: :file:`tmp`, |
| :file:`new`, and :file:`cur`. Messages are created momentarily in the |
| :file:`new`, and :file:`cur`. Messages are created momentarily in the |
| :file:`tmp` subdirectory and then moved to the :file:`new` subdirectory to |
| :file:`tmp` subdirectory and then moved to the :file:`new` subdirectory to |
| finalize delivery. A mail user agent may subsequently move the message to the |
| finalize delivery. A mail user agent may subsequently move the message to the |
| :file:`cur` subdirectory and store information about the state of the message in |
| :file:`cur` subdirectory and store information about the state of the message |
| a special "info" section appended to its file name. |
| in a special "info" section appended to its file name. |
| |
n | Folders of the style introduced by the Courier mail transfer agent are also |
n | Folders of the style introduced by the Courier mail transfer agent are also |
| supported. Any subdirectory of the main mailbox is considered a folder if |
| supported. Any subdirectory of the main mailbox is considered a folder if |
| ``'.'`` is the first character in its name. Folder names are represented by |
| ``'.'`` is the first character in its name. Folder names are represented by |
| :class:`Maildir` without the leading ``'.'``. Each folder is itself a Maildir |
| :class:`Maildir` without the leading ``'.'``. Each folder is itself a Maildir |
| mailbox but should not contain other folders. Instead, a logical nesting is |
| mailbox but should not contain other folders. Instead, a logical nesting is |
| indicated using ``'.'`` to delimit levels, e.g., "Archived.2005.07". |
| indicated using ``'.'`` to delimit levels, e.g., "Archived.2005.07". |
| |
n | .. note:: |
n | .. note:: |
| |
n | The Maildir specification requires the use of a colon (``':'``) in certain |
n | The Maildir specification requires the use of a colon (``':'``) in certain |
| message file names. However, some operating systems do not permit this character |
| message file names. However, some operating systems do not permit this |
| in file names, If you wish to use a Maildir-like format on such an operating |
| character in file names, If you wish to use a Maildir-like format on such |
| system, you should specify another character to use instead. The exclamation |
| an operating system, you should specify another character to use |
| point (``'!'``) is a popular choice. For example:: |
| instead. The exclamation point (``'!'``) is a popular choice. For |
| example:: |
| |
n | import mailbox |
n | import mailbox |
| mailbox.Maildir.colon = '!' |
| mailbox.Maildir.colon = '!' |
| |
n | The :attr:`colon` attribute may also be set on a per-instance basis. |
n | The :attr:`colon` attribute may also be set on a per-instance basis. |
| |
n | :class:`Maildir` instances have all of the methods of :class:`Mailbox` in |
n | :class:`Maildir` instances have all of the methods of :class:`Mailbox` in |
| addition to the following: |
| addition to the following: |
| |
| |
n | .. method:: Maildir.list_folders() |
n | .. method:: list_folders() |
| |
n | Return a list of the names of all folders. |
n | Return a list of the names of all folders. |
| |
| |
n | .. method:: Maildir.get_folder(folder) |
n | .. method:: .et_folder(folder) |
| |
n | Return a :class:`Maildir` instance representing the folder whose name is |
n | Return a :class:`Maildir` instance representing the folder whose name is |
| *folder*. A :exc:`NoSuchMailboxError` exception is raised if the folder does not |
| *folder*. A :exc:`NoSuchMailboxError` exception is raised if the folder |
| exist. |
| does not exist. |
| |
| |
n | .. method:: Maildir.add_folder(folder) |
n | .. method:: add_folder(folder) |
| |
n | Create a folder whose name is *folder* and return a :class:`Maildir` instance |
n | Create a folder whose name is *folder* and return a :class:`Maildir` |
| representing it. |
| instance representing it. |
| |
| |
n | .. method:: Maildir.remove_folder(folder) |
n | .. method:: remove_folder(folder) |
| |
n | Delete the folder whose name is *folder*. If the folder contains any messages, a |
n | Delete the folder whose name is *folder*. If the folder contains any |
| :exc:`NotEmptyError` exception will be raised and the folder will not be |
| messages, a :exc:`NotEmptyError` exception will be raised and the folder |
| deleted. |
| will not be deleted. |
| |
| |
n | .. method:: Maildir.clean() |
n | .. method:: clean() |
| |
n | Delete temporary files from the mailbox that have not been accessed in the last |
n | Delete temporary files from the mailbox that have not been accessed in the |
| 36 hours. The Maildir specification says that mail-reading programs should do |
| last 36 hours. The Maildir specification says that mail-reading programs |
| this occasionally. |
| should do this occasionally. |
| |
n | Some :class:`Mailbox` methods implemented by :class:`Maildir` deserve special |
n | Some :class:`Mailbox` methods implemented by :class:`Maildir` deserve special |
| remarks: |
| remarks: |
| |
| |
n | .. method:: Maildir.add(message) |
n | .. method:: add(message) |
| Maildir.__setitem__(key, message) |
| __setitem__(key, message) |
| Maildir.update(arg) |
| update(arg) |
| |
n | .. warning:: |
n | .. warning:: |
| |
n | These methods generate unique file names based upon the current process ID. When |
n | These methods generate unique file names based upon the current process |
| using multiple threads, undetected name clashes may occur and cause corruption |
| ID. When using multiple threads, undetected name clashes may occur and |
| of the mailbox unless threads are coordinated to avoid using these methods to |
| cause corruption of the mailbox unless threads are coordinated to avoid |
| manipulate the same mailbox simultaneously. |
| using these methods to manipulate the same mailbox simultaneously. |
| |
| |
n | .. method:: Maildir.flush() |
n | .. method:: flush() |
| |
n | All changes to Maildir mailboxes are immediately applied, so this method does |
n | All changes to Maildir mailboxes are immediately applied, so this method |
| nothing. |
| does nothing. |
| |
| |
n | .. method:: Maildir.lock() |
n | .. method:: lock() |
| Maildir.unlock() |
| unlock() |
| |
n | Maildir mailboxes do not support (or require) locking, so these methods do |
n | Maildir mailboxes do not support (or require) locking, so these methods do |
| nothing. |
| nothing. |
| |
| |
n | .. method:: Maildir.close() |
n | .. method:: close() |
| |
n | :class:`Maildir` instances do not keep any open files and the underlying |
n | :class:`Maildir` instances do not keep any open files and the underlying |
| mailboxes do not support locking, so this method does nothing. |
| mailboxes do not support locking, so this method does nothing. |
| |
| |
n | .. method:: Maildir.get_file(key) |
n | .. method:: get_file(key) |
| |
n | Depending upon the host platform, it may not be possible to modify or remove the |
n | Depending upon the host platform, it may not be possible to modify or |
| underlying message while the returned file remains open. |
| remove the underlying message while the returned file remains open. |
| |
| |
| .. seealso:: |
| |
| `maildir man page from qmail <http://www.qmail.org/man/man5/maildir.html>`_ |
| The original specification of the format. |
| |
| `Using maildir format <http://cr.yp.to/proto/maildir.html>`_ |
| Notes on Maildir by its inventor. Includes an updated name-creation scheme and |
| details on "info" semantics. |
| |
n | `maildir man page from Courier <http://www.courier-mta.org/?maildir.html>`_ |
n | `maildir man page from Courier <http://www.courier-mta.org/maildir.html>`_ |
| Another specification of the format. Describes a common extension for supporting |
| folders. |
| |
| |
| .. _mailbox-mbox: |
| |
| :class:`mbox` |
| ^^^^^^^^^^^^^ |
| |
| A subclass of :class:`Mailbox` for mailboxes in MH format. Parameter *factory* |
| is a callable object that accepts a file-like message representation (which |
| behaves as if opened in binary mode) and returns a custom representation. If |
| *factory* is ``None``, :class:`MHMessage` is used as the default message |
| representation. If *create* is ``True``, the mailbox is created if it does not |
| exist. |
| |
n | MH is a directory-based mailbox format invented for the MH Message Handling |
n | MH is a directory-based mailbox format invented for the MH Message Handling |
| System, a mail user agent. Each message in an MH mailbox resides in its own |
| System, a mail user agent. Each message in an MH mailbox resides in its own |
| file. An MH mailbox may contain other MH mailboxes (called :dfn:`folders`) in |
| file. An MH mailbox may contain other MH mailboxes (called :dfn:`folders`) in |
| addition to messages. Folders may be nested indefinitely. MH mailboxes also |
| addition to messages. Folders may be nested indefinitely. MH mailboxes also |
| support :dfn:`sequences`, which are named lists used to logically group messages |
| support :dfn:`sequences`, which are named lists used to logically group |
| without moving them to sub-folders. Sequences are defined in a file called |
| messages without moving them to sub-folders. Sequences are defined in a file |
| :file:`.mh_sequences` in each folder. |
| called :file:`.mh_sequences` in each folder. |
| |
n | The :class:`MH` class manipulates MH mailboxes, but it does not attempt to |
n | The :class:`MH` class manipulates MH mailboxes, but it does not attempt to |
| emulate all of :program:`mh`'s behaviors. In particular, it does not modify and |
| emulate all of :program:`mh`'s behaviors. In particular, it does not modify |
| is not affected by the :file:`context` or :file:`.mh_profile` files that are |
| and is not affected by the :file:`context` or :file:`.mh_profile` files that |
| used by :program:`mh` to store its state and configuration. |
| are used by :program:`mh` to store its state and configuration. |
| |
n | :class:`MH` instances have all of the methods of :class:`Mailbox` in addition to |
n | :class:`MH` instances have all of the methods of :class:`Mailbox` in addition |
| the following: |
| to the following: |
| |
| |
n | .. method:: MH.list_folders() |
n | .. method:: list_folders() |
| |
n | Return a list of the names of all folders. |
n | Return a list of the names of all folders. |
| |
| |
n | .. method:: MH.get_folder(folder) |
n | .. method:: get_folder(folder) |
| |
n | Return an :class:`MH` instance representing the folder whose name is *folder*. A |
n | Return an :class:`MH` instance representing the folder whose name is |
| :exc:`NoSuchMailboxError` exception is raised if the folder does not exist. |
| *folder*. A :exc:`NoSuchMailboxError` exception is raised if the folder |
| does not exist. |
| |
| |
n | .. method:: MH.add_folder(folder) |
n | .. method:: add_folder(folder) |
| |
n | Create a folder whose name is *folder* and return an :class:`MH` instance |
n | Create a folder whose name is *folder* and return an :class:`MH` instance |
| representing it. |
| representing it. |
| |
| |
n | .. method:: MH.remove_folder(folder) |
n | .. method:: remove_folder(folder) |
| |
n | Delete the folder whose name is *folder*. If the folder contains any messages, a |
n | Delete the folder whose name is *folder*. If the folder contains any |
| :exc:`NotEmptyError` exception will be raised and the folder will not be |
| messages, a :exc:`NotEmptyError` exception will be raised and the folder |
| deleted. |
| will not be deleted. |
| |
| |
n | .. method:: MH.get_sequences() |
n | .. method:: get_sequences() |
| |
n | Return a dictionary of sequence names mapped to key lists. If there are no |
n | Return a dictionary of sequence names mapped to key lists. If there are no |
| sequences, the empty dictionary is returned. |
| sequences, the empty dictionary is returned. |
| |
| |
n | .. method:: MH.set_sequences(sequences) |
n | .. method:: set_sequences(sequences) |
| |
n | Re-define the sequences that exist in the mailbox based upon *sequences*, a |
n | Re-define the sequences that exist in the mailbox based upon *sequences*, |
| dictionary of names mapped to key lists, like returned by :meth:`get_sequences`. |
| a dictionary of names mapped to key lists, like returned by |
| :meth:`get_sequences`. |
| |
| |
n | .. method:: MH.pack() |
n | .. method:: pack() |
| |
n | Rename messages in the mailbox as necessary to eliminate gaps in numbering. |
n | Rename messages in the mailbox as necessary to eliminate gaps in |
| Entries in the sequences list are updated correspondingly. |
| numbering. Entries in the sequences list are updated correspondingly. |
| |
n | .. note:: |
n | .. note:: |
| |
n | Already-issued keys are invalidated by this operation and should not be |
n | Already-issued keys are invalidated by this operation and should not be |
| subsequently used. |
| subsequently used. |
| |
n | Some :class:`Mailbox` methods implemented by :class:`MH` deserve special |
n | Some :class:`Mailbox` methods implemented by :class:`MH` deserve special |
| remarks: |
| remarks: |
| |
| |
n | .. method:: MH.remove(key) |
n | .. method:: remove(key) |
| MH.__delitem__(key) |
| __delitem__(key) |
| MH.discard(key) |
| discard(key) |
| |
n | These methods immediately delete the message. The MH convention of marking a |
n | These methods immediately delete the message. The MH convention of marking |
| message for deletion by prepending a comma to its name is not used. |
| a message for deletion by prepending a comma to its name is not used. |
| |
| |
n | .. method:: MH.lock() |
n | .. method:: lock() |
| MH.unlock() |
| unlock() |
| |
n | Three locking mechanisms are used---dot locking and, if available, the |
n | Three locking mechanisms are used---dot locking and, if available, the |
| :cfunc:`flock` and :cfunc:`lockf` system calls. For MH mailboxes, locking the |
| :cfunc:`flock` and :cfunc:`lockf` system calls. For MH mailboxes, locking |
| mailbox means locking the :file:`.mh_sequences` file and, only for the duration |
| the mailbox means locking the :file:`.mh_sequences` file and, only for the |
| of any operations that affect them, locking individual message files. |
| duration of any operations that affect them, locking individual message |
| files. |
| |
| |
n | .. method:: MH.get_file(key) |
n | .. method:: get_file(key) |
| |
n | Depending upon the host platform, it may not be possible to remove the |
n | Depending upon the host platform, it may not be possible to remove the |
| underlying message while the returned file remains open. |
| underlying message while the returned file remains open. |
| |
| |
n | .. method:: MH.flush() |
n | .. method:: flush() |
| |
n | All changes to MH mailboxes are immediately applied, so this method does |
n | All changes to MH mailboxes are immediately applied, so this method does |
| nothing. |
| nothing. |
| |
| |
n | .. method:: MH.close() |
n | .. method:: close() |
| |
n | :class:`MH` instances do not keep any open files, so this method is equivelant |
n | :class:`MH` instances do not keep any open files, so this method is |
| to :meth:`unlock`. |
| equivalent to :meth:`unlock`. |
| |
| |
| .. seealso:: |
| |
| `nmh - Message Handling System <http://www.nongnu.org/nmh/>`_ |
| Home page of :program:`nmh`, an updated version of the original :program:`mh`. |
| |
| `MH & nmh: Email for Users & Programmers <http://www.ics.uci.edu/~mh/book/>`_ |
| |
| A subclass of :class:`Mailbox` for mailboxes in Babyl format. Parameter |
| *factory* is a callable object that accepts a file-like message representation |
| (which behaves as if opened in binary mode) and returns a custom representation. |
| If *factory* is ``None``, :class:`BabylMessage` is used as the default message |
| representation. If *create* is ``True``, the mailbox is created if it does not |
| exist. |
| |
n | Babyl is a single-file mailbox format used by the Rmail mail user agent included |
n | Babyl is a single-file mailbox format used by the Rmail mail user agent |
| with Emacs. The beginning of a message is indicated by a line containing the two |
| included with Emacs. The beginning of a message is indicated by a line |
| characters Control-Underscore (``'\\037'``) and Control-L (``'\\014'``). The end |
| containing the two characters Control-Underscore (``'\037'``) and Control-L |
| of a message is indicated by the start of the next message or, in the case of |
| (``'\014'``). The end of a message is indicated by the start of the next |
| the last message, a line containing a Control-Underscore (``'\\037'``) |
| message or, in the case of the last message, a line containing a |
| character. |
| Control-Underscore (``'\037'``) character. |
| |
n | Messages in a Babyl mailbox have two sets of headers, original headers and so- |
n | Messages in a Babyl mailbox have two sets of headers, original headers and |
| called visible headers. Visible headers are typically a subset of the original |
| so-called visible headers. Visible headers are typically a subset of the |
| headers that have been reformatted or abridged to be more attractive. Each |
| original headers that have been reformatted or abridged to be more |
| message in a Babyl mailbox also has an accompanying list of :dfn:`labels`, or |
| attractive. Each message in a Babyl mailbox also has an accompanying list of |
| short strings that record extra information about the message, and a list of all |
| :dfn:`labels`, or short strings that record extra information about the |
| user-defined labels found in the mailbox is kept in the Babyl options section. |
| message, and a list of all user-defined labels found in the mailbox is kept |
| in the Babyl options section. |
| |
n | :class:`Babyl` instances have all of the methods of :class:`Mailbox` in addition |
n | :class:`Babyl` instances have all of the methods of :class:`Mailbox` in |
| to the following: |
| addition to the following: |
| |
| |
n | .. method:: Babyl.get_labels() |
n | .. method:: get_labels() |
| |
n | Return a list of the names of all user-defined labels used in the mailbox. |
n | Return a list of the names of all user-defined labels used in the mailbox. |
| |
n | .. note:: |
n | .. note:: |
| |
n | The actual messages are inspected to determine which labels exist in the mailbox |
n | The actual messages are inspected to determine which labels exist in |
| rather than consulting the list of labels in the Babyl options section, but the |
| the mailbox rather than consulting the list of labels in the Babyl |
| Babyl section is updated whenever the mailbox is modified. |
| options section, but the Babyl section is updated whenever the mailbox |
| is modified. |
| |
n | Some :class:`Mailbox` methods implemented by :class:`Babyl` deserve special |
n | Some :class:`Mailbox` methods implemented by :class:`Babyl` deserve special |
| remarks: |
| remarks: |
| |
| |
n | .. method:: Babyl.get_file(key) |
n | .. method:: get_file(key) |
| |
n | In Babyl mailboxes, the headers of a message are not stored contiguously with |
n | In Babyl mailboxes, the headers of a message are not stored contiguously |
| the body of the message. To generate a file-like representation, the headers and |
| with the body of the message. To generate a file-like representation, the |
| body are copied together into a :class:`StringIO` instance (from the |
| headers and body are copied together into a :class:`StringIO` instance |
| :mod:`StringIO` module), which has an API identical to that of a file. As a |
| (from the :mod:`StringIO` module), which has an API identical to that of a |
| result, the file-like object is truly independent of the underlying mailbox but |
| file. As a result, the file-like object is truly independent of the |
| does not save memory compared to a string representation. |
| underlying mailbox but does not save memory compared to a string |
| representation. |
| |
| |
n | .. method:: Babyl.lock() |
n | .. method:: lock() |
| Babyl.unlock() |
| unlock() |
| |
n | Three locking mechanisms are used---dot locking and, if available, the |
n | Three locking mechanisms are used---dot locking and, if available, the |
| :cfunc:`flock` and :cfunc:`lockf` system calls. |
| :cfunc:`flock` and :cfunc:`lockf` system calls. |
| |
| |
| .. seealso:: |
| |
| `Format of Version 5 Babyl Files <http://quimby.gnus.org/notes/BABYL>`_ |
| A specification of the Babyl format. |
| |
n | `Reading Mail with Rmail <http://www.gnu.org/software/emacs/manual/html_node/Rmail.html>`_ |
n | `Reading Mail with Rmail <http://www.gnu.org/software/emacs/manual/html_node/emacs/Rmail.html>`_ |
| The Rmail manual, with some information on Babyl semantics. |
| |
| |
| .. _mailbox-mmdf: |
| |
| :class:`MMDF` |
| ^^^^^^^^^^^^^ |
| |
| |
| If *message* is omitted, the new instance is created in a default, empty state. |
| If *message* is an :class:`email.Message.Message` instance, its contents are |
| copied; furthermore, any format-specific information is converted insofar as |
| possible if *message* is a :class:`Message` instance. If *message* is a string |
| or a file, it should contain an :rfc:`2822`\ -compliant message, which is read |
| and parsed. |
| |
n | The format-specific state and behaviors offered by subclasses vary, but in |
n | The format-specific state and behaviors offered by subclasses vary, but in |
| general it is only the properties that are not specific to a particular mailbox |
| general it is only the properties that are not specific to a particular |
| that are supported (although presumably the properties are specific to a |
| mailbox that are supported (although presumably the properties are specific |
| particular mailbox format). For example, file offsets for single-file mailbox |
| to a particular mailbox format). For example, file offsets for single-file |
| formats and file names for directory-based mailbox formats are not retained, |
| mailbox formats and file names for directory-based mailbox formats are not |
| because they are only applicable to the original mailbox. But state such as |
| retained, because they are only applicable to the original mailbox. But state |
| whether a message has been read by the user or marked as important is retained, |
| such as whether a message has been read by the user or marked as important is |
| because it applies to the message itself. |
| retained, because it applies to the message itself. |
| |
n | There is no requirement that :class:`Message` instances be used to represent |
n | There is no requirement that :class:`Message` instances be used to represent |
| messages retrieved using :class:`Mailbox` instances. In some situations, the |
| messages retrieved using :class:`Mailbox` instances. In some situations, the |
| time and memory required to generate :class:`Message` representations might not |
| time and memory required to generate :class:`Message` representations might |
| not acceptable. For such situations, :class:`Mailbox` instances also offer |
| not not acceptable. For such situations, :class:`Mailbox` instances also |
| string and file-like representations, and a custom message factory may be |
| offer string and file-like representations, and a custom message factory may |
| specified when a :class:`Mailbox` instance is initialized. |
| be specified when a :class:`Mailbox` instance is initialized. |
| |
| |
| .. _mailbox-maildirmessage: |
| |
| :class:`MaildirMessage` |
| ^^^^^^^^^^^^^^^^^^^^^^^ |
| |
| |
| .. class:: MaildirMessage([message]) |
| |
| A message with Maildir-specific behaviors. Parameter *message* has the same |
| meaning as with the :class:`Message` constructor. |
| |
n | Typically, a mail user agent application moves all of the messages in the |
n | Typically, a mail user agent application moves all of the messages in the |
| :file:`new` subdirectory to the :file:`cur` subdirectory after the first time |
| :file:`new` subdirectory to the :file:`cur` subdirectory after the first time |
| the user opens and closes the mailbox, recording that the messages are old |
| the user opens and closes the mailbox, recording that the messages are old |
| whether or not they've actually been read. Each message in :file:`cur` has an |
| whether or not they've actually been read. Each message in :file:`cur` has an |
| "info" section added to its file name to store information about its state. |
| "info" section added to its file name to store information about its state. |
| (Some mail readers may also add an "info" section to messages in :file:`new`.) |
| (Some mail readers may also add an "info" section to messages in |
| The "info" section may take one of two forms: it may contain "2," followed by a |
| :file:`new`.) The "info" section may take one of two forms: it may contain |
| list of standardized flags (e.g., "2,FR") or it may contain "1," followed by so- |
| "2," followed by a list of standardized flags (e.g., "2,FR") or it may |
| called experimental information. Standard flags for Maildir messages are as |
| contain "1," followed by so-called experimental information. Standard flags |
| follows: |
| for Maildir messages are as follows: |
| |
n | +------+---------+--------------------------------+ |
n | +------+---------+--------------------------------+ |
| | Flag | Meaning | Explanation | |
| | Flag | Meaning | Explanation | |
| +======+=========+================================+ |
| +======+=========+================================+ |
| | D | Draft | Under composition | |
| | D | Draft | Under composition | |
| +------+---------+--------------------------------+ |
| +------+---------+--------------------------------+ |
| | F | Flagged | Marked as important | |
| | F | Flagged | Marked as important | |
| +------+---------+--------------------------------+ |
| +------+---------+--------------------------------+ |
| | P | Passed | Forwarded, resent, or bounced | |
| | P | Passed | Forwarded, resent, or bounced | |
| +------+---------+--------------------------------+ |
| +------+---------+--------------------------------+ |
| | R | Replied | Replied to | |
| | R | Replied | Replied to | |
| +------+---------+--------------------------------+ |
| +------+---------+--------------------------------+ |
| | S | Seen | Read | |
| | S | Seen | Read | |
| +------+---------+--------------------------------+ |
| +------+---------+--------------------------------+ |
| | T | Trashed | Marked for subsequent deletion | |
| | T | Trashed | Marked for subsequent deletion | |
| +------+---------+--------------------------------+ |
| +------+---------+--------------------------------+ |
| |
n | :class:`MaildirMessage` instances offer the following methods: |
n | :class:`MaildirMessage` instances offer the following methods: |
| |
| |
n | .. method:: MaildirMessage.get_subdir() |
n | .. method:: get_subdir() |
| |
n | Return either "new" (if the message should be stored in the :file:`new` |
n | Return either "new" (if the message should be stored in the :file:`new` |
| subdirectory) or "cur" (if the message should be stored in the :file:`cur` |
| subdirectory) or "cur" (if the message should be stored in the :file:`cur` |
| subdirectory). |
| subdirectory). |
| |
n | .. note:: |
n | .. note:: |
| |
n | A message is typically moved from :file:`new` to :file:`cur` after its mailbox |
n | A message is typically moved from :file:`new` to :file:`cur` after its |
| has been accessed, whether or not the message is has been read. A message |
| mailbox has been accessed, whether or not the message is has been |
| ``msg`` has been read if ``"S" not in msg.get_flags()`` is ``True``. |
| read. A message ``msg`` has been read if ``"S" in msg.get_flags()`` is |
| ``True``. |
| |
| |
n | .. method:: MaildirMessage.set_subdir(subdir) |
n | .. method:: set_subdir(subdir) |
| |
n | Set the subdirectory the message should be stored in. Parameter *subdir* must be |
n | Set the subdirectory the message should be stored in. Parameter *subdir* |
| either "new" or "cur". |
| must be either "new" or "cur". |
| |
| |
n | .. method:: MaildirMessage.get_flags() |
n | .. method:: get_flags() |
| |
n | Return a string specifying the flags that are currently set. If the message |
n | Return a string specifying the flags that are currently set. If the |
| complies with the standard Maildir format, the result is the concatenation in |
| message complies with the standard Maildir format, the result is the |
| alphabetical order of zero or one occurrence of each of ``'D'``, ``'F'``, |
| concatenation in alphabetical order of zero or one occurrence of each of |
| ``'P'``, ``'R'``, ``'S'``, and ``'T'``. The empty string is returned if no flags |
| ``'D'``, ``'F'``, ``'P'``, ``'R'``, ``'S'``, and ``'T'``. The empty string |
| are set or if "info" contains experimental semantics. |
| is returned if no flags are set or if "info" contains experimental |
| semantics. |
| |
| |
n | .. method:: MaildirMessage.set_flags(flags) |
n | .. method:: set_flags(flags) |
| |
n | Set the flags specified by *flags* and unset all others. |
n | Set the flags specified by *flags* and unset all others. |
| |
| |
n | .. method:: MaildirMessage.add_flag(flag) |
n | .. method:: add_flag(flag) |
| |
n | Set the flag(s) specified by *flag* without changing other flags. To add more |
n | Set the flag(s) specified by *flag* without changing other flags. To add |
| than one flag at a time, *flag* may be a string of more than one character. The |
| more than one flag at a time, *flag* may be a string of more than one |
| current "info" is overwritten whether or not it contains experimental |
| character. The current "info" is overwritten whether or not it contains |
| information rather than flags. |
| experimental information rather than flags. |
| |
| |
n | .. method:: MaildirMessage.remove_flag(flag) |
n | .. method:: remove_flag(flag) |
| |
n | Unset the flag(s) specified by *flag* without changing other flags. To remove |
n | Unset the flag(s) specified by *flag* without changing other flags. To |
| more than one flag at a time, *flag* maybe a string of more than one character. |
| remove more than one flag at a time, *flag* maybe a string of more than |
| If "info" contains experimental information rather than flags, the current |
| one character. If "info" contains experimental information rather than |
| "info" is not modified. |
| flags, the current "info" is not modified. |
| |
| |
n | .. method:: MaildirMessage.get_date() |
n | .. method:: get_date() |
| |
n | Return the delivery date of the message as a floating-point number representing |
n | Return the delivery date of the message as a floating-point number |
| seconds since the epoch. |
| representing seconds since the epoch. |
| |
| |
n | .. method:: MaildirMessage.set_date(date) |
n | .. method:: set_date(date) |
| |
n | Set the delivery date of the message to *date*, a floating-point number |
n | Set the delivery date of the message to *date*, a floating-point number |
| representing seconds since the epoch. |
| representing seconds since the epoch. |
| |
| |
n | .. method:: MaildirMessage.get_info() |
n | .. method:: get_info() |
| |
n | Return a string containing the "info" for a message. This is useful for |
n | Return a string containing the "info" for a message. This is useful for |
| accessing and modifying "info" that is experimental (i.e., not a list of flags). |
| accessing and modifying "info" that is experimental (i.e., not a list of |
| flags). |
| |
| |
n | .. method:: MaildirMessage.set_info(info) |
n | .. method:: set_info(info) |
| |
n | Set "info" to *info*, which should be a string. |
n | Set "info" to *info*, which should be a string. |
| |
| When a :class:`MaildirMessage` instance is created based upon an |
| :class:`mboxMessage` or :class:`MMDFMessage` instance, the :mailheader:`Status` |
| and :mailheader:`X-Status` headers are omitted and the following conversions |
| take place: |
| |
| +--------------------+----------------------------------------------+ |
| | Resulting state | :class:`mboxMessage` or :class:`MMDFMessage` | |
| ^^^^^^^^^^^^^^^^^^^^ |
| |
| |
| .. class:: mboxMessage([message]) |
| |
| A message with mbox-specific behaviors. Parameter *message* has the same meaning |
| as with the :class:`Message` constructor. |
| |
n | Messages in an mbox mailbox are stored together in a single file. The sender's |
n | Messages in an mbox mailbox are stored together in a single file. The |
| envelope address and the time of delivery are typically stored in a line |
| sender's envelope address and the time of delivery are typically stored in a |
| beginning with "From " that is used to indicate the start of a message, though |
| line beginning with "From " that is used to indicate the start of a message, |
| there is considerable variation in the exact format of this data among mbox |
| though there is considerable variation in the exact format of this data among |
| implementations. Flags that indicate the state of the message, such as whether |
| mbox implementations. Flags that indicate the state of the message, such as |
| it has been read or marked as important, are typically stored in |
| whether it has been read or marked as important, are typically stored in |
| :mailheader:`Status` and :mailheader:`X-Status` headers. |
| :mailheader:`Status` and :mailheader:`X-Status` headers. |
| |
n | Conventional flags for mbox messages are as follows: |
n | Conventional flags for mbox messages are as follows: |
| |
n | +------+----------+--------------------------------+ |
n | +------+----------+--------------------------------+ |
| | Flag | Meaning | Explanation | |
| | Flag | Meaning | Explanation | |
| +======+==========+================================+ |
| +======+==========+================================+ |
| | R | Read | Read | |
| | R | Read | Read | |
| +------+----------+--------------------------------+ |
| +------+----------+--------------------------------+ |
| | O | Old | Previously detected by MUA | |
| | O | Old | Previously detected by MUA | |
| +------+----------+--------------------------------+ |
| +------+----------+--------------------------------+ |
| | D | Deleted | Marked for subsequent deletion | |
| | D | Deleted | Marked for subsequent deletion | |
| +------+----------+--------------------------------+ |
| +------+----------+--------------------------------+ |
| | F | Flagged | Marked as important | |
| | F | Flagged | Marked as important | |
| +------+----------+--------------------------------+ |
| +------+----------+--------------------------------+ |
| | A | Answered | Replied to | |
| | A | Answered | Replied to | |
| +------+----------+--------------------------------+ |
| +------+----------+--------------------------------+ |
| |
n | The "R" and "O" flags are stored in the :mailheader:`Status` header, and the |
n | The "R" and "O" flags are stored in the :mailheader:`Status` header, and the |
| "D", "F", and "A" flags are stored in the :mailheader:`X-Status` header. The |
| "D", "F", and "A" flags are stored in the :mailheader:`X-Status` header. The |
| flags and headers typically appear in the order mentioned. |
| flags and headers typically appear in the order mentioned. |
| |
n | :class:`mboxMessage` instances offer the following methods: |
n | :class:`mboxMessage` instances offer the following methods: |
| |
| |
n | .. method:: mboxMessage.get_from() |
n | .. method:: get_from() |
| |
n | Return a string representing the "From " line that marks the start of the |
n | Return a string representing the "From " line that marks the start of the |
| message in an mbox mailbox. The leading "From " and the trailing newline are |
| message in an mbox mailbox. The leading "From " and the trailing newline |
| excluded. |
| are excluded. |
| |
| |
n | .. method:: mboxMessage.set_from(from_[, time_=None]) |
n | .. method:: set_from(from_[, time_=None]) |
| |
n | Set the "From " line to *from_*, which should be specified without a leading |
n | Set the "From " line to *from_*, which should be specified without a |
| "From " or trailing newline. For convenience, *time_* may be specified and will |
| leading "From " or trailing newline. For convenience, *time_* may be |
| be formatted appropriately and appended to *from_*. If *time_* is specified, it |
| specified and will be formatted appropriately and appended to *from_*. If |
| should be a :class:`struct_time` instance, a tuple suitable for passing to |
| *time_* is specified, it should be a :class:`struct_time` instance, a |
| :meth:`time.strftime`, or ``True`` (to use :meth:`time.gmtime`). |
| tuple suitable for passing to :meth:`time.strftime`, or ``True`` (to use |
| :meth:`time.gmtime`). |
| |
| |
n | .. method:: mboxMessage.get_flags() |
n | .. method:: get_flags() |
| |
n | Return a string specifying the flags that are currently set. If the message |
n | Return a string specifying the flags that are currently set. If the |
| complies with the conventional format, the result is the concatenation in the |
| message complies with the conventional format, the result is the |
| following order of zero or one occurrence of each of ``'R'``, ``'O'``, ``'D'``, |
| concatenation in the following order of zero or one occurrence of each of |
| ``'F'``, and ``'A'``. |
| ``'R'``, ``'O'``, ``'D'``, ``'F'``, and ``'A'``. |
| |
| |
n | .. method:: mboxMessage.set_flags(flags) |
n | .. method:: set_flags(flags) |
| |
n | Set the flags specified by *flags* and unset all others. Parameter *flags* |
n | Set the flags specified by *flags* and unset all others. Parameter *flags* |
| should be the concatenation in any order of zero or more occurrences of each of |
| should be the concatenation in any order of zero or more occurrences of |
| ``'R'``, ``'O'``, ``'D'``, ``'F'``, and ``'A'``. |
| each of ``'R'``, ``'O'``, ``'D'``, ``'F'``, and ``'A'``. |
| |
| |
n | .. method:: mboxMessage.add_flag(flag) |
n | .. method:: add_flag(flag) |
| |
n | Set the flag(s) specified by *flag* without changing other flags. To add more |
n | Set the flag(s) specified by *flag* without changing other flags. To add |
| than one flag at a time, *flag* may be a string of more than one character. |
| more than one flag at a time, *flag* may be a string of more than one |
| character. |
| |
| |
n | .. method:: mboxMessage.remove_flag(flag) |
n | .. method:: remove_flag(flag) |
| |
n | Unset the flag(s) specified by *flag* without changing other flags. To remove |
n | Unset the flag(s) specified by *flag* without changing other flags. To |
| more than one flag at a time, *flag* maybe a string of more than one character. |
| remove more than one flag at a time, *flag* maybe a string of more than |
| one character. |
| |
| When an :class:`mboxMessage` instance is created based upon a |
| :class:`MaildirMessage` instance, a "From " line is generated based upon the |
| :class:`MaildirMessage` instance's delivery date, and the following conversions |
| take place: |
| |
| +-----------------+-------------------------------+ |
| | Resulting state | :class:`MaildirMessage` state | |
| ^^^^^^^^^^^^^^^^^^^^^ |
| |
| |
| .. class:: BabylMessage([message]) |
| |
| A message with Babyl-specific behaviors. Parameter *message* has the same |
| meaning as with the :class:`Message` constructor. |
| |
n | Certain message labels, called :dfn:`attributes`, are defined by convention to |
n | Certain message labels, called :dfn:`attributes`, are defined by convention |
| have special meanings. The attributes are as follows: |
| to have special meanings. The attributes are as follows: |
| |
n | +-----------+------------------------------------------+ |
n | +-----------+------------------------------------------+ |
| | Label | Explanation | |
| | Label | Explanation | |
| +===========+==========================================+ |
| +===========+==========================================+ |
| | unseen | Not read, but previously detected by MUA | |
| | unseen | Not read, but previously detected by MUA | |
| +-----------+------------------------------------------+ |
| +-----------+------------------------------------------+ |
| | deleted | Marked for subsequent deletion | |
| | deleted | Marked for subsequent deletion | |
| +-----------+------------------------------------------+ |
| +-----------+------------------------------------------+ |
| | filed | Copied to another file or mailbox | |
| | filed | Copied to another file or mailbox | |
| +-----------+------------------------------------------+ |
| +-----------+------------------------------------------+ |
| | answered | Replied to | |
| | answered | Replied to | |
| +-----------+------------------------------------------+ |
| +-----------+------------------------------------------+ |
| | forwarded | Forwarded | |
| | forwarded | Forwarded | |
| +-----------+------------------------------------------+ |
| +-----------+------------------------------------------+ |
| | edited | Modified by the user | |
| | edited | Modified by the user | |
| +-----------+------------------------------------------+ |
| +-----------+------------------------------------------+ |
| | resent | Resent | |
| | resent | Resent | |
| +-----------+------------------------------------------+ |
| +-----------+------------------------------------------+ |
| |
n | By default, Rmail displays only visible headers. The :class:`BabylMessage` |
n | By default, Rmail displays only visible headers. The :class:`BabylMessage` |
| class, though, uses the original headers because they are more complete. Visible |
| class, though, uses the original headers because they are more |
| headers may be accessed explicitly if desired. |
| complete. Visible headers may be accessed explicitly if desired. |
| |
n | :class:`BabylMessage` instances offer the following methods: |
n | :class:`BabylMessage` instances offer the following methods: |
| |
| |
n | .. method:: BabylMessage.get_labels() |
n | .. method:: get_labels() |
| |
n | Return a list of labels on the message. |
n | Return a list of labels on the message. |
| |
| |
n | .. method:: BabylMessage.set_labels(labels) |
n | .. method:: set_labels(labels) |
| |
n | Set the list of labels on the message to *labels*. |
n | Set the list of labels on the message to *labels*. |
| |
| |
n | .. method:: BabylMessage.add_label(label) |
n | .. method:: add_label(label) |
| |
n | Add *label* to the list of labels on the message. |
n | Add *label* to the list of labels on the message. |
| |
| |
n | .. method:: BabylMessage.remove_label(label) |
n | .. method:: remove_label(label) |
| |
n | Remove *label* from the list of labels on the message. |
n | Remove *label* from the list of labels on the message. |
| |
| |
n | .. method:: BabylMessage.get_visible() |
n | .. method:: get_visible() |
| |
n | Return an :class:`Message` instance whose headers are the message's visible |
n | Return an :class:`Message` instance whose headers are the message's |
| headers and whose body is empty. |
| visible headers and whose body is empty. |
| |
| |
n | .. method:: BabylMessage.set_visible(visible) |
n | .. method:: set_visible(visible) |
| |
n | Set the message's visible headers to be the same as the headers in *message*. |
n | Set the message's visible headers to be the same as the headers in |
| Parameter *visible* should be a :class:`Message` instance, an |
| *message*. Parameter *visible* should be a :class:`Message` instance, an |
| :class:`email.Message.Message` instance, a string, or a file-like object (which |
| :class:`email.Message.Message` instance, a string, or a file-like object |
| should be open in text mode). |
| (which should be open in text mode). |
| |
| |
n | .. method:: BabylMessage.update_visible() |
n | .. method:: update_visible() |
| |
n | When a :class:`BabylMessage` instance's original headers are modified, the |
n | When a :class:`BabylMessage` instance's original headers are modified, the |
| visible headers are not automatically modified to correspond. This method |
| visible headers are not automatically modified to correspond. This method |
| updates the visible headers as follows: each visible header with a corresponding |
| updates the visible headers as follows: each visible header with a |
| original header is set to the value of the original header, each visible header |
| corresponding original header is set to the value of the original header, |
| without a corresponding original header is removed, and any of |
| each visible header without a corresponding original header is removed, |
| :mailheader:`Date`, :mailheader:`From`, :mailheader:`Reply-To`, |
| and any of :mailheader:`Date`, :mailheader:`From`, :mailheader:`Reply-To`, |
| :mailheader:`To`, :mailheader:`CC`, and :mailheader:`Subject` that are present |
| :mailheader:`To`, :mailheader:`CC`, and :mailheader:`Subject` that are |
| in the original headers but not the visible headers are added to the visible |
| present in the original headers but not the visible headers are added to |
| headers. |
| the visible headers. |
| |
| When a :class:`BabylMessage` instance is created based upon a |
| :class:`MaildirMessage` instance, the following conversions take place: |
| |
| +-------------------+-------------------------------+ |
| | Resulting state | :class:`MaildirMessage` state | |
| +===================+===============================+ |
| | "unseen" label | no S flag | |
| ^^^^^^^^^^^^^^^^^^^^ |
| |
| |
| .. class:: MMDFMessage([message]) |
| |
| A message with MMDF-specific behaviors. Parameter *message* has the same meaning |
| as with the :class:`Message` constructor. |
| |
n | As with message in an mbox mailbox, MMDF messages are stored with the sender's |
n | As with message in an mbox mailbox, MMDF messages are stored with the |
| address and the delivery date in an initial line beginning with "From ". |
| sender's address and the delivery date in an initial line beginning with |
| Likewise, flags that indicate the state of the message are typically stored in |
| "From ". Likewise, flags that indicate the state of the message are |
| :mailheader:`Status` and :mailheader:`X-Status` headers. |
| typically stored in :mailheader:`Status` and :mailheader:`X-Status` headers. |
| |
n | Conventional flags for MMDF messages are identical to those of mbox message and |
n | Conventional flags for MMDF messages are identical to those of mbox message |
| are as follows: |
| and are as follows: |
| |
n | +------+----------+--------------------------------+ |
n | +------+----------+--------------------------------+ |
| | Flag | Meaning | Explanation | |
| | Flag | Meaning | Explanation | |
| +======+==========+================================+ |
| +======+==========+================================+ |
| | R | Read | Read | |
| | R | Read | Read | |
| +------+----------+--------------------------------+ |
| +------+----------+--------------------------------+ |
| | O | Old | Previously detected by MUA | |
| | O | Old | Previously detected by MUA | |
| +------+----------+--------------------------------+ |
| +------+----------+--------------------------------+ |
| | D | Deleted | Marked for subsequent deletion | |
| | D | Deleted | Marked for subsequent deletion | |
| +------+----------+--------------------------------+ |
| +------+----------+--------------------------------+ |
| | F | Flagged | Marked as important | |
| | F | Flagged | Marked as important | |
| +------+----------+--------------------------------+ |
| +------+----------+--------------------------------+ |
| | A | Answered | Replied to | |
| | A | Answered | Replied to | |
| +------+----------+--------------------------------+ |
| +------+----------+--------------------------------+ |
| |
n | The "R" and "O" flags are stored in the :mailheader:`Status` header, and the |
n | The "R" and "O" flags are stored in the :mailheader:`Status` header, and the |
| "D", "F", and "A" flags are stored in the :mailheader:`X-Status` header. The |
| "D", "F", and "A" flags are stored in the :mailheader:`X-Status` header. The |
| flags and headers typically appear in the order mentioned. |
| flags and headers typically appear in the order mentioned. |
| |
n | :class:`MMDFMessage` instances offer the following methods, which are identical |
n | :class:`MMDFMessage` instances offer the following methods, which are |
| to those offered by :class:`mboxMessage`: |
| identical to those offered by :class:`mboxMessage`: |
| |
| |
n | .. method:: MMDFMessage.get_from() |
n | .. method:: get_from() |
| |
n | Return a string representing the "From " line that marks the start of the |
n | Return a string representing the "From " line that marks the start of the |
| message in an mbox mailbox. The leading "From " and the trailing newline are |
| message in an mbox mailbox. The leading "From " and the trailing newline |
| excluded. |
| are excluded. |
| |
| |
n | .. method:: MMDFMessage.set_from(from_[, time_=None]) |
n | .. method:: set_from(from_[, time_=None]) |
| |
n | Set the "From " line to *from_*, which should be specified without a leading |
n | Set the "From " line to *from_*, which should be specified without a |
| "From " or trailing newline. For convenience, *time_* may be specified and will |
| leading "From " or trailing newline. For convenience, *time_* may be |
| be formatted appropriately and appended to *from_*. If *time_* is specified, it |
| specified and will be formatted appropriately and appended to *from_*. If |
| should be a :class:`struct_time` instance, a tuple suitable for passing to |
| *time_* is specified, it should be a :class:`struct_time` instance, a |
| :meth:`time.strftime`, or ``True`` (to use :meth:`time.gmtime`). |
| tuple suitable for passing to :meth:`time.strftime`, or ``True`` (to use |
| :meth:`time.gmtime`). |
| |
| |
n | .. method:: MMDFMessage.get_flags() |
n | .. method:: get_flags() |
| |
n | Return a string specifying the flags that are currently set. If the message |
n | Return a string specifying the flags that are currently set. If the |
| complies with the conventional format, the result is the concatenation in the |
| message complies with the conventional format, the result is the |
| following order of zero or one occurrence of each of ``'R'``, ``'O'``, ``'D'``, |
| concatenation in the following order of zero or one occurrence of each of |
| ``'F'``, and ``'A'``. |
| ``'R'``, ``'O'``, ``'D'``, ``'F'``, and ``'A'``. |
| |
| |
n | .. method:: MMDFMessage.set_flags(flags) |
n | .. method:: set_flags(flags) |
| |
n | Set the flags specified by *flags* and unset all others. Parameter *flags* |
n | Set the flags specified by *flags* and unset all others. Parameter *flags* |
| should be the concatenation in any order of zero or more occurrences of each of |
| should be the concatenation in any order of zero or more occurrences of |
| ``'R'``, ``'O'``, ``'D'``, ``'F'``, and ``'A'``. |
| each of ``'R'``, ``'O'``, ``'D'``, ``'F'``, and ``'A'``. |
| |
| |
n | .. method:: MMDFMessage.add_flag(flag) |
n | .. method:: add_flag(flag) |
| |
n | Set the flag(s) specified by *flag* without changing other flags. To add more |
n | Set the flag(s) specified by *flag* without changing other flags. To add |
| than one flag at a time, *flag* may be a string of more than one character. |
| more than one flag at a time, *flag* may be a string of more than one |
| character. |
| |
| |
n | .. method:: MMDFMessage.remove_flag(flag) |
n | .. method:: remove_flag(flag) |
| |
n | Unset the flag(s) specified by *flag* without changing other flags. To remove |
n | Unset the flag(s) specified by *flag* without changing other flags. To |
| more than one flag at a time, *flag* maybe a string of more than one character. |
| remove more than one flag at a time, *flag* maybe a string of more than |
| one character. |
| |
| When an :class:`MMDFMessage` instance is created based upon a |
| :class:`MaildirMessage` instance, a "From " line is generated based upon the |
| :class:`MaildirMessage` instance's delivery date, and the following conversions |
| take place: |
| |
| +-----------------+-------------------------------+ |
| | Resulting state | :class:`MaildirMessage` state | |