Kaydet (Commit) 30dbd142 authored tarafından Barry Warsaw's avatar Barry Warsaw

Document the two changes to the mailbox.py module:

- All constructors grow an optional argument `factory' which is a
  callable used when new message instances are created by the next()
  methods.  Defaults to the rfc822.Message class.

- A new subclass of UnixMailbox is added, called PortableUnixMailbox.
  It's identical to UnixMailbox, but uses a more portable test for
  From_ delimiter lines.  With PortableUnixMailbox, any line that
  starts with "From " is considered a delimiter (this should really
  check for two newlines before the F, but it doesn't.
üst 81ad67cd
...@@ -8,33 +8,61 @@ ...@@ -8,33 +8,61 @@
This module defines a number of classes that allow easy and uniform This module defines a number of classes that allow easy and uniform
access to mail messages in a (\UNIX{}) mailbox. access to mail messages in a (\UNIX{}) mailbox.
\begin{classdesc}{UnixMailbox}{fp} \begin{classdesc}{UnixMailbox}{fp\optional{, factory}}
Access a classic \UNIX{}-style mailbox, where all messages are contained Access to a classic \UNIX{}-style mailbox, where all messages are
in a single file and separated by ``From name time'' lines. contained in a single file and separate by ``From '' (a.k.a ``From_'')
The file object \var{fp} points to the mailbox file. lines. The file object \var{fp} points to the mailbox file. Optional
\var{factory} is a callable that should create new message objects.
It is called with one argument, \var{fp} by the \method{next()}
method. The default is the \class{rfc822.Message} class (see the
\refmodule{rfc822} module).
For maximum portability, messages in a \UNIX{}-style mailbox are
separated by any line that begins exactly with the letters \emph{F},
\emph{r}, \emph{o}, \emph{m}, \emph{[space]} if preceded by exactly two
newlines. Because of the wide-range of variations in practice,
nothing else on the From_ line should be considered. However, the
current implementation doesn't check for the leading two newlines.
This is usually fine for most applications.
The \class{UnixMailbox} class implements a more strict version of
From_ line checking, using a regular expression that usually correctly
matched From_ delimiters. It considers delimiter line to be separated
by ``From name time'' lines. For maximum portability, use the
\class{PortableUnixMailbox} class instead. This
class is completely identical to \class{UnixMailbox} except that
individual messages are separated by only ``From '' lines.
For more
information see
\url{http://home.netscape.com/eng/mozilla/2.0/relnotes/demo/content-length.html}.
\end{classdesc} \end{classdesc}
\begin{classdesc}{MmdfMailbox}{fp} \begin{classdesc}{MmdfMailbox}{fp\optional{, factory}}
Access an MMDF-style mailbox, where all messages are contained Access an MMDF-style mailbox, where all messages are contained
in a single file and separated by lines consisting of 4 control-A in a single file and separated by lines consisting of 4 control-A
characters. The file object \var{fp} points to the mailbox file. characters. The file object \var{fp} points to the mailbox file.
Optional \var{factory} is as with the \class{UnixMailbox} class.
\end{classdesc} \end{classdesc}
\begin{classdesc}{MHMailbox}{dirname} \begin{classdesc}{MHMailbox}{dirname\optional{, factory}}
Access an MH mailbox, a directory with each message in a separate Access an MH mailbox, a directory with each message in a separate
file with a numeric name. file with a numeric name.
The name of the mailbox directory is passed in \var{dirname}. The name of the mailbox directory is passed in \var{dirname}.
\var{factory} is as with the \class{UnixMailbox} class.
\end{classdesc} \end{classdesc}
\begin{classdesc}{Maildir}{dirname} \begin{classdesc}{Maildir}{dirname\optional{, factory}}
Access a Qmail mail directory. All new and current mail for the Access a Qmail mail directory. All new and current mail for the
mailbox specified by \var{dirname} is made available. mailbox specified by \var{dirname} is made available.
\var{factory} is as with the \class{UnixMailbox} class.
\end{classdesc} \end{classdesc}
\begin{classdesc}{BabylMailbox}{fp} \begin{classdesc}{BabylMailbox}{fp\optional{, factory}}
Access a Babyl mailbox, which is similar to an MMDF mailbox. Mail Access a Babyl mailbox, which is similar to an MMDF mailbox. Mail
messages start with a line containing only \code{'*** EOOH ***'} and messages start with a line containing only \code{'*** EOOH ***'} and
end with a line containing only \code{'\e{}037\e{}014'}. end with a line containing only \code{'\e{}037\e{}014'}.
\var{factory} is as with the \class{UnixMailbox} class.
\end{classdesc} \end{classdesc}
...@@ -44,7 +72,9 @@ All implementations of Mailbox objects have one externally visible ...@@ -44,7 +72,9 @@ All implementations of Mailbox objects have one externally visible
method: method:
\begin{methoddesc}[mailbox]{next}{} \begin{methoddesc}[mailbox]{next}{}
Return the next message in the mailbox, as a \class{rfc822.Message} Return the next message in the mailbox, created with the optional
\var{factory} argument passed into the mailbox object's constructor.
By defaul this is an \class{rfc822.Message}
object (see the \refmodule{rfc822} module). Depending on the mailbox object (see the \refmodule{rfc822} module). Depending on the mailbox
implementation the \var{fp} attribute of this object may be a true implementation the \var{fp} attribute of this object may be a true
file object or a class instance simulating a file object, taking care file object or a class instance simulating a file object, taking care
......
...@@ -15,6 +15,13 @@ Core language, builtins, and interpreter ...@@ -15,6 +15,13 @@ Core language, builtins, and interpreter
Standard library Standard library
- mailbox.py now has a new class, PortableUnixMailbox which is
identical to UnixMailbox but uses a more portable scheme for
determining From_ separators. Also, the constructors for all the
classes in this module have a new optional `factory' argument, which
is a callable used when new message classes must be instantiated by
the next() method.
- random.py is now self-contained, and offers all the functionality of - random.py is now self-contained, and offers all the functionality of
the now-deprecated whrandom.py. See the docs for details. random.py the now-deprecated whrandom.py. See the docs for details. random.py
also supports new functions getstate() and setstate(), for saving also supports new functions getstate() and setstate(), for saving
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment