Added section on passing contextual information to logging and documentation for...
[python.git] / Doc / library / mhlib.rst
blobf6edf289c4015ce1e6ffbd01c6f41a78a468c645
1 :mod:`mhlib` --- Access to MH mailboxes
2 =======================================
4 .. module:: mhlib
5    :synopsis: Manipulate MH mailboxes from Python.
6 .. sectionauthor:: Skip Montanaro <skip@pobox.com>
8 The :mod:`mhlib` module provides a Python interface to MH folders and their
9 contents.
11 The module contains three basic classes, :class:`MH`, which represents a
12 particular collection of folders, :class:`Folder`, which represents a single
13 folder, and :class:`Message`, which represents a single message.
16 .. class:: MH([path[, profile]])
18    :class:`MH` represents a collection of MH folders.
21 .. class:: Folder(mh, name)
23    The :class:`Folder` class represents a single folder and its messages.
26 .. class:: Message(folder, number[, name])
28    :class:`Message` objects represent individual messages in a folder.  The Message
29    class is derived from :class:`mimetools.Message`.
32 .. _mh-objects:
34 MH Objects
35 ----------
37 :class:`MH` instances have the following methods:
40 .. method:: MH.error(format[, ...])
42    Print an error message -- can be overridden.
45 .. method:: MH.getprofile(key)
47    Return a profile entry (``None`` if not set).
50 .. method:: MH.getpath()
52    Return the mailbox pathname.
55 .. method:: MH.getcontext()
57    Return the current folder name.
60 .. method:: MH.setcontext(name)
62    Set the current folder name.
65 .. method:: MH.listfolders()
67    Return a list of top-level folders.
70 .. method:: MH.listallfolders()
72    Return a list of all folders.
75 .. method:: MH.listsubfolders(name)
77    Return a list of direct subfolders of the given folder.
80 .. method:: MH.listallsubfolders(name)
82    Return a list of all subfolders of the given folder.
85 .. method:: MH.makefolder(name)
87    Create a new folder.
90 .. method:: MH.deletefolder(name)
92    Delete a folder -- must have no subfolders.
95 .. method:: MH.openfolder(name)
97    Return a new open folder object.
100 .. _mh-folder-objects:
102 Folder Objects
103 --------------
105 :class:`Folder` instances represent open folders and have the following methods:
108 .. method:: Folder.error(format[, ...])
110    Print an error message -- can be overridden.
113 .. method:: Folder.getfullname()
115    Return the folder's full pathname.
118 .. method:: Folder.getsequencesfilename()
120    Return the full pathname of the folder's sequences file.
123 .. method:: Folder.getmessagefilename(n)
125    Return the full pathname of message *n* of the folder.
128 .. method:: Folder.listmessages()
130    Return a list of messages in the folder (as numbers).
133 .. method:: Folder.getcurrent()
135    Return the current message number.
138 .. method:: Folder.setcurrent(n)
140    Set the current message number to *n*.
143 .. method:: Folder.parsesequence(seq)
145    Parse msgs syntax into list of messages.
148 .. method:: Folder.getlast()
150    Get last message, or ``0`` if no messages are in the folder.
153 .. method:: Folder.setlast(n)
155    Set last message (internal use only).
158 .. method:: Folder.getsequences()
160    Return dictionary of sequences in folder.  The sequence names are used  as keys,
161    and the values are the lists of message numbers in the sequences.
164 .. method:: Folder.putsequences(dict)
166    Return dictionary of sequences in folder name: list.
169 .. method:: Folder.removemessages(list)
171    Remove messages in list from folder.
174 .. method:: Folder.refilemessages(list, tofolder)
176    Move messages in list to other folder.
179 .. method:: Folder.movemessage(n, tofolder, ton)
181    Move one message to a given destination in another folder.
184 .. method:: Folder.copymessage(n, tofolder, ton)
186    Copy one message to a given destination in another folder.
189 .. _mh-message-objects:
191 Message Objects
192 ---------------
194 The :class:`Message` class adds one method to those of
195 :class:`mimetools.Message`:
198 .. method:: Message.openmessage(n)
200    Return a new open message object (costs a file descriptor).