Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{mailbox} --- |
Fred Drake | 199b79c | 1999-02-20 05:04:59 +0000 | [diff] [blame] | 2 | Read various mailbox formats} |
| 3 | |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 4 | \declaremodule{standard}{mailbox} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 5 | \modulesynopsis{Read various mailbox formats.} |
| 6 | |
Guido van Rossum | 39a23cc | 1997-06-02 21:04:41 +0000 | [diff] [blame] | 7 | |
Guido van Rossum | 39a23cc | 1997-06-02 21:04:41 +0000 | [diff] [blame] | 8 | This module defines a number of classes that allow easy and uniform |
Fred Drake | 2e495c9 | 1998-03-14 06:48:33 +0000 | [diff] [blame] | 9 | access to mail messages in a (\UNIX{}) mailbox. |
Guido van Rossum | 39a23cc | 1997-06-02 21:04:41 +0000 | [diff] [blame] | 10 | |
Barry Warsaw | 30dbd14 | 2001-01-31 22:14:01 +0000 | [diff] [blame^] | 11 | \begin{classdesc}{UnixMailbox}{fp\optional{, factory}} |
| 12 | Access to a classic \UNIX{}-style mailbox, where all messages are |
| 13 | contained in a single file and separate by ``From '' (a.k.a ``From_'') |
| 14 | lines. The file object \var{fp} points to the mailbox file. Optional |
| 15 | \var{factory} is a callable that should create new message objects. |
| 16 | It is called with one argument, \var{fp} by the \method{next()} |
| 17 | method. The default is the \class{rfc822.Message} class (see the |
| 18 | \refmodule{rfc822} module). |
| 19 | |
| 20 | For maximum portability, messages in a \UNIX{}-style mailbox are |
| 21 | separated 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 |
| 23 | newlines. Because of the wide-range of variations in practice, |
| 24 | nothing else on the From_ line should be considered. However, the |
| 25 | current implementation doesn't check for the leading two newlines. |
| 26 | This is usually fine for most applications. |
| 27 | |
| 28 | The \class{UnixMailbox} class implements a more strict version of |
| 29 | From_ line checking, using a regular expression that usually correctly |
| 30 | matched From_ delimiters. It considers delimiter line to be separated |
| 31 | by ``From name time'' lines. For maximum portability, use the |
| 32 | \class{PortableUnixMailbox} class instead. This |
| 33 | class is completely identical to \class{UnixMailbox} except that |
| 34 | individual messages are separated by only ``From '' lines. |
| 35 | |
| 36 | For more |
| 37 | information see |
| 38 | \url{http://home.netscape.com/eng/mozilla/2.0/relnotes/demo/content-length.html}. |
Fred Drake | 2e495c9 | 1998-03-14 06:48:33 +0000 | [diff] [blame] | 39 | \end{classdesc} |
Guido van Rossum | 39a23cc | 1997-06-02 21:04:41 +0000 | [diff] [blame] | 40 | |
Barry Warsaw | 30dbd14 | 2001-01-31 22:14:01 +0000 | [diff] [blame^] | 41 | \begin{classdesc}{MmdfMailbox}{fp\optional{, factory}} |
Guido van Rossum | 39a23cc | 1997-06-02 21:04:41 +0000 | [diff] [blame] | 42 | Access an MMDF-style mailbox, where all messages are contained |
| 43 | in a single file and separated by lines consisting of 4 control-A |
Fred Drake | 6e99adb | 1998-02-13 22:17:21 +0000 | [diff] [blame] | 44 | characters. The file object \var{fp} points to the mailbox file. |
Barry Warsaw | 30dbd14 | 2001-01-31 22:14:01 +0000 | [diff] [blame^] | 45 | Optional \var{factory} is as with the \class{UnixMailbox} class. |
Fred Drake | 2e495c9 | 1998-03-14 06:48:33 +0000 | [diff] [blame] | 46 | \end{classdesc} |
Guido van Rossum | 39a23cc | 1997-06-02 21:04:41 +0000 | [diff] [blame] | 47 | |
Barry Warsaw | 30dbd14 | 2001-01-31 22:14:01 +0000 | [diff] [blame^] | 48 | \begin{classdesc}{MHMailbox}{dirname\optional{, factory}} |
Guido van Rossum | 39a23cc | 1997-06-02 21:04:41 +0000 | [diff] [blame] | 49 | Access an MH mailbox, a directory with each message in a separate |
Fred Drake | 6e99adb | 1998-02-13 22:17:21 +0000 | [diff] [blame] | 50 | file with a numeric name. |
| 51 | The name of the mailbox directory is passed in \var{dirname}. |
Barry Warsaw | 30dbd14 | 2001-01-31 22:14:01 +0000 | [diff] [blame^] | 52 | \var{factory} is as with the \class{UnixMailbox} class. |
Fred Drake | 2e495c9 | 1998-03-14 06:48:33 +0000 | [diff] [blame] | 53 | \end{classdesc} |
Guido van Rossum | 39a23cc | 1997-06-02 21:04:41 +0000 | [diff] [blame] | 54 | |
Barry Warsaw | 30dbd14 | 2001-01-31 22:14:01 +0000 | [diff] [blame^] | 55 | \begin{classdesc}{Maildir}{dirname\optional{, factory}} |
Fred Drake | 199b79c | 1999-02-20 05:04:59 +0000 | [diff] [blame] | 56 | Access a Qmail mail directory. All new and current mail for the |
| 57 | mailbox specified by \var{dirname} is made available. |
Barry Warsaw | 30dbd14 | 2001-01-31 22:14:01 +0000 | [diff] [blame^] | 58 | \var{factory} is as with the \class{UnixMailbox} class. |
Fred Drake | 199b79c | 1999-02-20 05:04:59 +0000 | [diff] [blame] | 59 | \end{classdesc} |
| 60 | |
Barry Warsaw | 30dbd14 | 2001-01-31 22:14:01 +0000 | [diff] [blame^] | 61 | \begin{classdesc}{BabylMailbox}{fp\optional{, factory}} |
Fred Drake | 199b79c | 1999-02-20 05:04:59 +0000 | [diff] [blame] | 62 | Access a Babyl mailbox, which is similar to an MMDF mailbox. Mail |
Fred Drake | 180b68b | 1999-02-22 13:45:09 +0000 | [diff] [blame] | 63 | messages start with a line containing only \code{'*** EOOH ***'} and |
Fred Drake | fab41f1 | 1999-02-22 14:26:16 +0000 | [diff] [blame] | 64 | end with a line containing only \code{'\e{}037\e{}014'}. |
Barry Warsaw | 30dbd14 | 2001-01-31 22:14:01 +0000 | [diff] [blame^] | 65 | \var{factory} is as with the \class{UnixMailbox} class. |
Fred Drake | 199b79c | 1999-02-20 05:04:59 +0000 | [diff] [blame] | 66 | \end{classdesc} |
| 67 | |
| 68 | |
| 69 | \subsection{Mailbox Objects \label{mailbox-objects}} |
Guido van Rossum | 39a23cc | 1997-06-02 21:04:41 +0000 | [diff] [blame] | 70 | |
| 71 | All implementations of Mailbox objects have one externally visible |
| 72 | method: |
| 73 | |
Fred Drake | 182bd2d | 1998-04-02 18:50:21 +0000 | [diff] [blame] | 74 | \begin{methoddesc}[mailbox]{next}{} |
Barry Warsaw | 30dbd14 | 2001-01-31 22:14:01 +0000 | [diff] [blame^] | 75 | Return the next message in the mailbox, created with the optional |
| 76 | \var{factory} argument passed into the mailbox object's constructor. |
| 77 | By defaul this is an \class{rfc822.Message} |
Fred Drake | 806a467 | 1999-03-27 05:45:46 +0000 | [diff] [blame] | 78 | object (see the \refmodule{rfc822} module). Depending on the mailbox |
| 79 | implementation the \var{fp} attribute of this object may be a true |
| 80 | file object or a class instance simulating a file object, taking care |
| 81 | of things like message boundaries if multiple mail messages are |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 82 | contained in a single file, etc. If no more messages are available, |
| 83 | this method returns \code{None}. |
Fred Drake | 182bd2d | 1998-04-02 18:50:21 +0000 | [diff] [blame] | 84 | \end{methoddesc} |