blob: e74848bb8225de2d07d072382389b7b9d2bfb2db [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}}
Fred Drake62700312001-02-02 03:51:05 +000012Access to a classic \UNIX-style mailbox, where all messages are
13contained in a single file and separated by \samp{From }
14(a.k.a.\ \samp{From_}) lines. The file object \var{fp} points to the
15mailbox file. The optional \var{factory} parameter is a callable that
16should create new message objects. \var{factory} is called with one
17argument, \var{fp} by the \method{next()} method of the mailbox
18object. The default is the \class{rfc822.Message} class (see the
Barry Warsaw30dbd142001-01-31 22:14:01 +000019\refmodule{rfc822} module).
20
Fred Drake62700312001-02-02 03:51:05 +000021For maximum portability, messages in a \UNIX-style mailbox are
22separated by any line that begins exactly with the string \code{'From
23'} (note the trailing space) if preceded by exactly two newlines.
24Because of the wide-range of variations in practice, nothing else on
25the From_ line should be considered. However, the current
26implementation doesn't check for the leading two newlines. This is
27usually fine for most applications.
Barry Warsaw30dbd142001-01-31 22:14:01 +000028
29The \class{UnixMailbox} class implements a more strict version of
30From_ line checking, using a regular expression that usually correctly
31matched From_ delimiters. It considers delimiter line to be separated
Fred Drake62700312001-02-02 03:51:05 +000032by \samp{From \var{name} \var{time}} lines. For maximum portability,
33use the \class{PortableUnixMailbox} class instead. This class is
34identical to \class{UnixMailbox} except that individual messages are
35separated by only \samp{From } lines.
Barry Warsaw30dbd142001-01-31 22:14:01 +000036
Fred Drake62700312001-02-02 03:51:05 +000037For more information, see
38\citetitle[http://home.netscape.com/eng/mozilla/2.0/relnotes/demo/content-length.html]{Configuring
39Netscape Mail on \UNIX: Why the Content-Length Format is Bad}.
40\end{classdesc}
41
42\begin{classdesc}{PortableUnixMailbox}{fp\optional{, factory}}
43A less-strict version of \class{UnixMailbox}, which considers only the
44\samp{From } at the beginning of the line separating messages. The
45``\var{name} \var{time}'' portion of the From line is ignored, to
46protect against some variations that are observed in practice. This
47works since lines in the message which begin with \code{'From '} are
48quoted by mail handling software well before delivery.
Fred Drake2e495c91998-03-14 06:48:33 +000049\end{classdesc}
Guido van Rossum39a23cc1997-06-02 21:04:41 +000050
Barry Warsaw30dbd142001-01-31 22:14:01 +000051\begin{classdesc}{MmdfMailbox}{fp\optional{, factory}}
Guido van Rossum39a23cc1997-06-02 21:04:41 +000052Access an MMDF-style mailbox, where all messages are contained
53in a single file and separated by lines consisting of 4 control-A
Fred Drake6e99adb1998-02-13 22:17:21 +000054characters. The file object \var{fp} points to the mailbox file.
Barry Warsaw30dbd142001-01-31 22:14:01 +000055Optional \var{factory} is as with the \class{UnixMailbox} class.
Fred Drake2e495c91998-03-14 06:48:33 +000056\end{classdesc}
Guido van Rossum39a23cc1997-06-02 21:04:41 +000057
Barry Warsaw30dbd142001-01-31 22:14:01 +000058\begin{classdesc}{MHMailbox}{dirname\optional{, factory}}
Guido van Rossum39a23cc1997-06-02 21:04:41 +000059Access an MH mailbox, a directory with each message in a separate
Fred Drake6e99adb1998-02-13 22:17:21 +000060file with a numeric name.
61The name of the mailbox directory is passed in \var{dirname}.
Barry Warsaw30dbd142001-01-31 22:14:01 +000062\var{factory} is as with the \class{UnixMailbox} class.
Fred Drake2e495c91998-03-14 06:48:33 +000063\end{classdesc}
Guido van Rossum39a23cc1997-06-02 21:04:41 +000064
Barry Warsaw30dbd142001-01-31 22:14:01 +000065\begin{classdesc}{Maildir}{dirname\optional{, factory}}
Fred Drake199b79c1999-02-20 05:04:59 +000066Access a Qmail mail directory. All new and current mail for the
67mailbox specified by \var{dirname} is made available.
Barry Warsaw30dbd142001-01-31 22:14:01 +000068\var{factory} is as with the \class{UnixMailbox} class.
Fred Drake199b79c1999-02-20 05:04:59 +000069\end{classdesc}
70
Barry Warsaw30dbd142001-01-31 22:14:01 +000071\begin{classdesc}{BabylMailbox}{fp\optional{, factory}}
Fred Drake199b79c1999-02-20 05:04:59 +000072Access a Babyl mailbox, which is similar to an MMDF mailbox. Mail
Fred Drake180b68b1999-02-22 13:45:09 +000073messages start with a line containing only \code{'*** EOOH ***'} and
Fred Drakefab41f11999-02-22 14:26:16 +000074end with a line containing only \code{'\e{}037\e{}014'}.
Barry Warsaw30dbd142001-01-31 22:14:01 +000075\var{factory} is as with the \class{UnixMailbox} class.
Fred Drake199b79c1999-02-20 05:04:59 +000076\end{classdesc}
77
78
79\subsection{Mailbox Objects \label{mailbox-objects}}
Guido van Rossum39a23cc1997-06-02 21:04:41 +000080
81All implementations of Mailbox objects have one externally visible
82method:
83
Fred Drake182bd2d1998-04-02 18:50:21 +000084\begin{methoddesc}[mailbox]{next}{}
Barry Warsaw30dbd142001-01-31 22:14:01 +000085Return the next message in the mailbox, created with the optional
86\var{factory} argument passed into the mailbox object's constructor.
87By defaul this is an \class{rfc822.Message}
Fred Drake806a4671999-03-27 05:45:46 +000088object (see the \refmodule{rfc822} module). Depending on the mailbox
89implementation the \var{fp} attribute of this object may be a true
90file object or a class instance simulating a file object, taking care
91of things like message boundaries if multiple mail messages are
Fred Drake2c4f5542000-10-10 22:00:03 +000092contained in a single file, etc. If no more messages are available,
93this method returns \code{None}.
Fred Drake182bd2d1998-04-02 18:50:21 +000094\end{methoddesc}