1
:mod:`mhlib` --- Access to MH mailboxes
2
=======================================
5
:synopsis: Manipulate MH mailboxes from Python.
9
The :mod:`mhlib` module has been removed in Python 3.0. Use the
10
:mod:`mailbox` instead.
12
.. sectionauthor:: Skip Montanaro <skip@pobox.com>
14
The :mod:`mhlib` module provides a Python interface to MH folders and their
17
The module contains three basic classes, :class:`MH`, which represents a
18
particular collection of folders, :class:`Folder`, which represents a single
19
folder, and :class:`Message`, which represents a single message.
22
.. class:: MH([path[, profile]])
24
:class:`MH` represents a collection of MH folders.
27
.. class:: Folder(mh, name)
29
The :class:`Folder` class represents a single folder and its messages.
32
.. class:: Message(folder, number[, name])
34
:class:`Message` objects represent individual messages in a folder. The Message
35
class is derived from :class:`mimetools.Message`.
43
:class:`MH` instances have the following methods:
46
.. method:: MH.error(format[, ...])
48
Print an error message -- can be overridden.
51
.. method:: MH.getprofile(key)
53
Return a profile entry (``None`` if not set).
56
.. method:: MH.getpath()
58
Return the mailbox pathname.
61
.. method:: MH.getcontext()
63
Return the current folder name.
66
.. method:: MH.setcontext(name)
68
Set the current folder name.
71
.. method:: MH.listfolders()
73
Return a list of top-level folders.
76
.. method:: MH.listallfolders()
78
Return a list of all folders.
81
.. method:: MH.listsubfolders(name)
83
Return a list of direct subfolders of the given folder.
86
.. method:: MH.listallsubfolders(name)
88
Return a list of all subfolders of the given folder.
91
.. method:: MH.makefolder(name)
96
.. method:: MH.deletefolder(name)
98
Delete a folder -- must have no subfolders.
101
.. method:: MH.openfolder(name)
103
Return a new open folder object.
106
.. _mh-folder-objects:
111
:class:`Folder` instances represent open folders and have the following methods:
114
.. method:: Folder.error(format[, ...])
116
Print an error message -- can be overridden.
119
.. method:: Folder.getfullname()
121
Return the folder's full pathname.
124
.. method:: Folder.getsequencesfilename()
126
Return the full pathname of the folder's sequences file.
129
.. method:: Folder.getmessagefilename(n)
131
Return the full pathname of message *n* of the folder.
134
.. method:: Folder.listmessages()
136
Return a list of messages in the folder (as numbers).
139
.. method:: Folder.getcurrent()
141
Return the current message number.
144
.. method:: Folder.setcurrent(n)
146
Set the current message number to *n*.
149
.. method:: Folder.parsesequence(seq)
151
Parse msgs syntax into list of messages.
154
.. method:: Folder.getlast()
156
Get last message, or ``0`` if no messages are in the folder.
159
.. method:: Folder.setlast(n)
161
Set last message (internal use only).
164
.. method:: Folder.getsequences()
166
Return dictionary of sequences in folder. The sequence names are used as keys,
167
and the values are the lists of message numbers in the sequences.
170
.. method:: Folder.putsequences(dict)
172
Return dictionary of sequences in folder name: list.
175
.. method:: Folder.removemessages(list)
177
Remove messages in list from folder.
180
.. method:: Folder.refilemessages(list, tofolder)
182
Move messages in list to other folder.
185
.. method:: Folder.movemessage(n, tofolder, ton)
187
Move one message to a given destination in another folder.
190
.. method:: Folder.copymessage(n, tofolder, ton)
192
Copy one message to a given destination in another folder.
195
.. _mh-message-objects:
200
The :class:`Message` class adds one method to those of
201
:class:`mimetools.Message`:
204
.. method:: Message.openmessage(n)
206
Return a new open message object (costs a file descriptor).