blob: 07f99f4ae9e62b9f0baa2b564326d57d2934e048 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{mailbox} ---
Fred Drake199b79c1999-02-20 05:04:59 +00002 Read various mailbox formats}
3
Fred Drakeb91e9341998-07-23 17:59:49 +00004\declaremodule{standard}{mailbox}
Fred Drakeb91e9341998-07-23 17:59:49 +00005\modulesynopsis{Read various mailbox formats.}
6
Guido van Rossum39a23cc1997-06-02 21:04:41 +00007
Guido van Rossum39a23cc1997-06-02 21:04:41 +00008This module defines a number of classes that allow easy and uniform
Fred Drake2e495c91998-03-14 06:48:33 +00009access to mail messages in a (\UNIX{}) mailbox.
Guido van Rossum39a23cc1997-06-02 21:04:41 +000010
Barry Warsaw30dbd142001-01-31 22:14:01 +000011\begin{classdesc}{UnixMailbox}{fp\optional{, factory}}
12Access to a classic \UNIX{}-style mailbox, where all messages are
13contained in a single file and separate by ``From '' (a.k.a ``From_'')
14lines. The file object \var{fp} points to the mailbox file. Optional
15\var{factory} is a callable that should create new message objects.
16It is called with one argument, \var{fp} by the \method{next()}
17method. The default is the \class{rfc822.Message} class (see the
18\refmodule{rfc822} module).
19
20For maximum portability, messages in a \UNIX{}-style mailbox are
21separated by any line that begins exactly with the letters \emph{F},
22\emph{r}, \emph{o}, \emph{m}, \emph{[space]} if preceded by exactly two
23newlines. Because of the wide-range of variations in practice,
24nothing else on the From_ line should be considered. However, the
25current implementation doesn't check for the leading two newlines.
26This is usually fine for most applications.
27
28The \class{UnixMailbox} class implements a more strict version of
29From_ line checking, using a regular expression that usually correctly
30matched From_ delimiters. It considers delimiter line to be separated
31by ``From name time'' lines. For maximum portability, use the
32\class{PortableUnixMailbox} class instead. This
33class is completely identical to \class{UnixMailbox} except that
34individual messages are separated by only ``From '' lines.
35
36For more
37information see
38\url{http://home.netscape.com/eng/mozilla/2.0/relnotes/demo/content-length.html}.
Fred Drake2e495c91998-03-14 06:48:33 +000039\end{classdesc}
Guido van Rossum39a23cc1997-06-02 21:04:41 +000040
Barry Warsaw30dbd142001-01-31 22:14:01 +000041\begin{classdesc}{MmdfMailbox}{fp\optional{, factory}}
Guido van Rossum39a23cc1997-06-02 21:04:41 +000042Access an MMDF-style mailbox, where all messages are contained
43in a single file and separated by lines consisting of 4 control-A
Fred Drake6e99adb1998-02-13 22:17:21 +000044characters. The file object \var{fp} points to the mailbox file.
Barry Warsaw30dbd142001-01-31 22:14:01 +000045Optional \var{factory} is as with the \class{UnixMailbox} class.
Fred Drake2e495c91998-03-14 06:48:33 +000046\end{classdesc}
Guido van Rossum39a23cc1997-06-02 21:04:41 +000047
Barry Warsaw30dbd142001-01-31 22:14:01 +000048\begin{classdesc}{MHMailbox}{dirname\optional{, factory}}
Guido van Rossum39a23cc1997-06-02 21:04:41 +000049Access an MH mailbox, a directory with each message in a separate
Fred Drake6e99adb1998-02-13 22:17:21 +000050file with a numeric name.
51The name of the mailbox directory is passed in \var{dirname}.
Barry Warsaw30dbd142001-01-31 22:14:01 +000052\var{factory} is as with the \class{UnixMailbox} class.
Fred Drake2e495c91998-03-14 06:48:33 +000053\end{classdesc}
Guido van Rossum39a23cc1997-06-02 21:04:41 +000054
Barry Warsaw30dbd142001-01-31 22:14:01 +000055\begin{classdesc}{Maildir}{dirname\optional{, factory}}
Fred Drake199b79c1999-02-20 05:04:59 +000056Access a Qmail mail directory. All new and current mail for the
57mailbox specified by \var{dirname} is made available.
Barry Warsaw30dbd142001-01-31 22:14:01 +000058\var{factory} is as with the \class{UnixMailbox} class.
Fred Drake199b79c1999-02-20 05:04:59 +000059\end{classdesc}
60
Barry Warsaw30dbd142001-01-31 22:14:01 +000061\begin{classdesc}{BabylMailbox}{fp\optional{, factory}}
Fred Drake199b79c1999-02-20 05:04:59 +000062Access a Babyl mailbox, which is similar to an MMDF mailbox. Mail
Fred Drake180b68b1999-02-22 13:45:09 +000063messages start with a line containing only \code{'*** EOOH ***'} and
Fred Drakefab41f11999-02-22 14:26:16 +000064end with a line containing only \code{'\e{}037\e{}014'}.
Barry Warsaw30dbd142001-01-31 22:14:01 +000065\var{factory} is as with the \class{UnixMailbox} class.
Fred Drake199b79c1999-02-20 05:04:59 +000066\end{classdesc}
67
68
69\subsection{Mailbox Objects \label{mailbox-objects}}
Guido van Rossum39a23cc1997-06-02 21:04:41 +000070
71All implementations of Mailbox objects have one externally visible
72method:
73
Fred Drake182bd2d1998-04-02 18:50:21 +000074\begin{methoddesc}[mailbox]{next}{}
Barry Warsaw30dbd142001-01-31 22:14:01 +000075Return the next message in the mailbox, created with the optional
76\var{factory} argument passed into the mailbox object's constructor.
77By defaul this is an \class{rfc822.Message}
Fred Drake806a4671999-03-27 05:45:46 +000078object (see the \refmodule{rfc822} module). Depending on the mailbox
79implementation the \var{fp} attribute of this object may be a true
80file object or a class instance simulating a file object, taking care
81of things like message boundaries if multiple mail messages are
Fred Drake2c4f5542000-10-10 22:00:03 +000082contained in a single file, etc. If no more messages are available,
83this method returns \code{None}.
Fred Drake182bd2d1998-04-02 18:50:21 +000084\end{methoddesc}