Toggle navigation

mhlib --- Access to MH mailboxes

mhlib --- Access to MH mailboxes

Deprecated since version 2.6: The mhlib module has been removed in Python 3. Use the mailbox instead.

The mhlib module provides a Python interface to MH folders and their contents.

The module contains three basic classes, MH, which represents a particular collection of folders, Folder, which represents a single folder, and Message, which represents a single message.

class mhlib.MH([path[, profile]])[source]

MH represents a collection of MH folders.

class mhlib.Folder(mh, name)[source]

The Folder class represents a single folder and its messages.

class mhlib.Message(folder, number[, name])[source]

Message objects represent individual messages in a folder. The Message class is derived from mimetools.Message.

MH Objects

MH instances have the following methods:

MH.error(format[, ...])[source]

Print an error message -- can be overridden.

MH.getprofile(key)[source]

Return a profile entry (None if not set).

MH.getpath()[source]

Return the mailbox pathname.

MH.getcontext()[source]

Return the current folder name.

MH.setcontext(name)[source]

Set the current folder name.

MH.listfolders()[source]

Return a list of top-level folders.

MH.listallfolders()[source]

Return a list of all folders.

MH.listsubfolders(name)[source]

Return a list of direct subfolders of the given folder.

MH.listallsubfolders(name)[source]

Return a list of all subfolders of the given folder.

MH.makefolder(name)[source]

Create a new folder.

MH.deletefolder(name)[source]

Delete a folder -- must have no subfolders.

MH.openfolder(name)[source]

Return a new open folder object.

Folder Objects

Folder instances represent open folders and have the following methods:

Folder.error(format[, ...])[source]

Print an error message -- can be overridden.

Folder.getfullname()[source]

Return the folder's full pathname.

Folder.getsequencesfilename()[source]

Return the full pathname of the folder's sequences file.

Folder.getmessagefilename(n)[source]

Return the full pathname of message n of the folder.

Folder.listmessages()[source]

Return a list of messages in the folder (as numbers).

Folder.getcurrent()[source]

Return the current message number.

Folder.setcurrent(n)[source]

Set the current message number to n.

Folder.parsesequence(seq)[source]

Parse msgs syntax into list of messages.

Folder.getlast()[source]

Get last message, or 0 if no messages are in the folder.

Folder.setlast(n)[source]

Set last message (internal use only).

Folder.getsequences()[source]

Return dictionary of sequences in folder. The sequence names are used as keys, and the values are the lists of message numbers in the sequences.

Folder.putsequences(dict)[source]

Return dictionary of sequences in folder name: list.

Folder.removemessages(list)[source]

Remove messages in list from folder.

Folder.refilemessages(list, tofolder)[source]

Move messages in list to other folder.

Folder.movemessage(n, tofolder, ton)[source]

Move one message to a given destination in another folder.

Folder.copymessage(n, tofolder, ton)[source]

Copy one message to a given destination in another folder.

Message Objects

The Message class adds one method to those of mimetools.Message:

Message.openmessage(n)

Return a new open message object (costs a file descriptor).