@@ -1501,133 +1501,6 @@ The following exception classes are defined in the :mod:`mailbox` module:
15011501 instance attempts to read a corrupted :file: `.mh_sequences ` file.
15021502
15031503
1504- .. _mailbox-deprecated :
1505-
1506- Deprecated classes and methods
1507- ------------------------------
1508-
1509- Older versions of the :mod: `mailbox ` module do not support modification of
1510- mailboxes, such as adding or removing message, and do not provide classes to
1511- represent format-specific message properties. For backward compatibility, the
1512- older mailbox classes are still available, but the newer classes should be used
1513- in preference to them.
1514-
1515- Older mailbox objects support only iteration and provide a single public method:
1516-
1517-
1518- .. method :: oldmailbox.next()
1519-
1520- Return the next message in the mailbox, created with the optional *factory *
1521- argument passed into the mailbox object's constructor. By default this is an
1522- :class: `rfc822.Message ` object (see the :mod: `rfc822 ` module). Depending on the
1523- mailbox implementation the *fp * attribute of this object may be a true file
1524- object or a class instance simulating a file object, taking care of things like
1525- message boundaries if multiple mail messages are contained in a single file,
1526- etc. If no more messages are available, this method returns ``None ``.
1527-
1528- Most of the older mailbox classes have names that differ from the current
1529- mailbox class names, except for :class: `Maildir `. For this reason, the new
1530- :class: `Maildir ` class defines a :meth: `next ` method and its constructor differs
1531- slightly from those of the other new mailbox classes.
1532-
1533- The older mailbox classes whose names are not the same as their newer
1534- counterparts are as follows:
1535-
1536-
1537- .. class :: UnixMailbox(fp[, factory])
1538-
1539- Access to a classic Unix-style mailbox, where all messages are contained in a
1540- single file and separated by ``From `` (a.k.a. ``From_ ``) lines. The file object
1541- *fp * points to the mailbox file. The optional *factory * parameter is a callable
1542- that should create new message objects. *factory * is called with one argument,
1543- *fp * by the :meth: `next ` method of the mailbox object. The default is the
1544- :class: `rfc822.Message ` class (see the :mod: `rfc822 ` module -- and the note
1545- below).
1546-
1547- .. note ::
1548-
1549- For reasons of this module's internal implementation, you will probably want to
1550- open the *fp * object in binary mode. This is especially important on Windows.
1551-
1552- For maximum portability, messages in a Unix-style mailbox are separated by any
1553- line that begins exactly with the string ``'From ' `` (note the trailing space)
1554- if preceded by exactly two newlines. Because of the wide-range of variations in
1555- practice, nothing else on the ``From_ `` line should be considered. However, the
1556- current implementation doesn't check for the leading two newlines. This is
1557- usually fine for most applications.
1558-
1559- The :class: `UnixMailbox ` class implements a more strict version of ``From_ ``
1560- line checking, using a regular expression that usually correctly matched
1561- ``From_ `` delimiters. It considers delimiter line to be separated by ``From
1562- name time `` lines. For maximum portability, use the
1563- :class: `PortableUnixMailbox ` class instead. This class is identical to
1564- :class: `UnixMailbox ` except that individual messages are separated by only
1565- ``From `` lines.
1566-
1567-
1568- .. class :: PortableUnixMailbox(fp[, factory])
1569-
1570- A less-strict version of :class: `UnixMailbox `, which considers only the ``From ``
1571- at the beginning of the line separating messages. The "*name * *time *" portion
1572- of the From line is ignored, to protect against some variations that are
1573- observed in practice. This works since lines in the message which begin with
1574- ``'From ' `` are quoted by mail handling software at delivery-time.
1575-
1576-
1577- .. class :: MmdfMailbox(fp[, factory])
1578-
1579- Access an MMDF-style mailbox, where all messages are contained in a single file
1580- and separated by lines consisting of 4 control-A characters. The file object
1581- *fp * points to the mailbox file. Optional *factory * is as with the
1582- :class: `UnixMailbox ` class.
1583-
1584-
1585- .. class :: MHMailbox(dirname[, factory])
1586-
1587- Access an MH mailbox, a directory with each message in a separate file with a
1588- numeric name. The name of the mailbox directory is passed in *dirname *.
1589- *factory * is as with the :class: `UnixMailbox ` class.
1590-
1591-
1592- .. class :: BabylMailbox(fp[, factory])
1593-
1594- Access a Babyl mailbox, which is similar to an MMDF mailbox. In Babyl format,
1595- each message has two sets of headers, the *original * headers and the *visible *
1596- headers. The original headers appear before a line containing only ``'*** EOOH
1597- ***' `` (End-Of-Original-Headers) and the visible headers appear after the
1598- ``EOOH `` line. Babyl-compliant mail readers will show you only the visible
1599- headers, and :class: `BabylMailbox ` objects will return messages containing only
1600- the visible headers. You'll have to do your own parsing of the mailbox file to
1601- get at the original headers. Mail messages start with the EOOH line and end
1602- with a line containing only ``'\037\014' ``. *factory * is as with the
1603- :class: `UnixMailbox ` class.
1604-
1605- If you wish to use the older mailbox classes with the :mod: `email ` module rather
1606- than the deprecated :mod: `rfc822 ` module, you can do so as follows::
1607-
1608- import email
1609- import email.Errors
1610- import mailbox
1611-
1612- def msgfactory(fp):
1613- try:
1614- return email.message_from_file(fp)
1615- except email.Errors.MessageParseError:
1616- # Don't return None since that will
1617- # stop the mailbox iterator
1618- return ''
1619-
1620- mbox = mailbox.UnixMailbox(fp, msgfactory)
1621-
1622- Alternatively, if you know your mailbox contains only well-formed MIME messages,
1623- you can simplify this to::
1624-
1625- import email
1626- import mailbox
1627-
1628- mbox = mailbox.UnixMailbox(fp, email.message_from_file)
1629-
1630-
16311504.. _mailbox-examples :
16321505
16331506Examples
0 commit comments