NAME
Mail::Box::MH - handle folders with a file per message.
CLASS HIERARCHY
Mail::Box::MH
is a Mail::Box
is a Mail::Reporter
SYNOPSIS
use Mail::Box::MH;
my $folder = new Mail::Box::MH folder => $ENV{MAIL}, ...;
DESCRIPTION
This documentation describes how MH mailboxes work, and what you can do with the MH folder object Mail::Box::MH
. Please read Mail::Box-Overview
and Mail::Box
first.
The internal organization and details are found at the bottom of this manual-page. The working of MH-messages are described in Mail::Box::MH::Message.
METHOD INDEX
The general methods for Mail::Box::MH
objects:
MB addMessage MESSAGE MR log [LEVEL [,STRINGS]]
MB addMessages MESSAGE [, MESS... MB message INDEX [,MESSAGE]
MB allMessageIds MB messageId MESSAGE-ID [,MESS...
MB close OPTIONS MB messages
MB create FOLDERNAME [, OPTIONS] MB modified [BOOLEAN]
MB current [NUMBER|MESSAGE|MES... MB name
MB delete new OPTIONS
directory MB openSubFolder NAME [,OPTIONS]
MR errors MR report [LEVEL]
MB find MESSAGE-ID MR reportAll [LEVEL]
MB listSubFolders OPTIONS MR trace [LEVEL]
MB locker MR warnings
The extra methods for extension writers:
MR AUTOLOAD MR logSettings
MB DESTROY MR notImplemented
MB appendMessages OPTIONS MB organization
MB clone OPTIONS MB read OPTIONS
MB coerce MESSAGE readAllHeaders
MB determineBodyType MESSAGE, ... readMessageFilenames DIRECTORY
folderToDirectory FOLDERNAM... MB readMessages
MB folderdir [DIR] MB scanForMessages MESSAGE, ME...
MB foundIn [FOLDERNAME], OPTIONS MB sort PREPARE, COMPARE, LIST
highestMessageNumber MB storeMessage MESSAGE
MR inGlobalDestruction MB timespan2seconds TIME
index MB toBeThreaded MESSAGES
labels MB toBeUnthreaded MESSAGES
MR logPriority LEVEL MB write OPTIONS
Methods prefixed with an abbreviation are described in the following manual-pages:
MB = L<Mail::Box>
MR = L<Mail::Reporter>
METHODS
- new OPTIONS
-
Create a new folder. The are many options which are taken from other objects. For some, different options are set. For MH-specific options see below, but first the full list.
OPTION DEFINED BY DEFAULT access Mail::Box 'r' create Mail::Box 0 folder Mail::Box $ENV{MAIL} folderdir Mail::Box <no default> head_wrap Mail::Box 72 index_filename Mail::Box::MH foldername.'/.index' keep_index Mail::Box::MH 0 labels_filename Mail::Box::MH foldername.'/.mh_sequence' extract Mail::Box 10kB lock_file Mail::Box foldername.'/.lock' lock_timeout Mail::Box 3600 (1 hour) lock_wait Mail::Box 10 (seconds) log Mail::Reporter 'WARNINGS' remove_when_empty Mail::Box 1 save_on_exit Mail::Box 1 trace Mail::Reporter 'WARNINGS' trusted Mail::Box <depends on folder location>
Only useful to write extension to
Mail::Box::Mbox
. Common users of folders you will not specify these:OPTION DEFINED BY DEFAULT body_type Mail::Box::MH <see below> body_delayed_type Mail::Box 'Mail::Message::Body::Delayed' coerce_options Mail::Box [] field_type Mail::Box undef head_type Mail::Box 'Mail::Message::Head::Complete' head_delayed_type Mail::Box::MH 'Mail::Message::Head::Delayed' index Mail::Box::MH undef index_type Mail::Box::MH 'Mail::Box::MH::Index' labels Mail::Box::MH undef labels_type Mail::Box::MH 'Mail::Box::MH::Labels' locker Mail::Box undef lock_type Mail::Box 'DOTLOCK' multipart_type Mail::Box 'Mail::Message::Body::Multipart' manager Mail::Box undef message_type Mail::Box 'Mail::Box::MH::Message' organization Mail::Box 'DIRECTORY' realhead_type Mail::Box 'Mail::Message::Head'
MH specific options:
keep_index => BOOL
Keep an index file of the specified mailbox, one file per directory. Using an index file will speed up things considerably, because it avoids reading all the message files the moment that you open the folder. When you open a folder, you can use the index file to retrieve information such as the subject of each message, instead of having to read possibly thousands of messages.
head_delayed_type => CLASS
The headers which are delayed: which will be read from file when it is needed, but not before.
index_filename => FILENAME
The FILENAME which is used in each directory to store the headers of all mails. The filename shall not contain a directory path. (e.g. Do not use
/usr/people/jan/.index
, norsubdir/.index
, but say.index
.)index => OBJECT
You may specify an OBJECT of a type which extends
Mail::Box::MH::Index
(at least implements theget()
method), as alternative for an index file reader as created byMail::Box::MH
.labels_filename => FILENAME
In MH-folders, messages can be labeled, for instance based on the sender or whether it is read or not. This status is kept in a file which is usually called
.mh_sequences
, but that name can be overruled with this flag.labels => OBJECT
You may specify an OBJECT of a type which extends
Mail::Box::MH::Labels
(at least implements theget()
method), as alternative for labels file reader as created byMail::Box::MH
.
The
body_type
options for Mbox folders defaults to:sub determine_body_type($$) { my $head = shift; my $size = shift || 0; 'Mail::Message::Body::' . ($size > 10000 ? 'File' : 'Lines'); }
which will cause messages larger than 10kB to be stored in files, and smaller files in memory.
- directory
-
Returns the directory related to this folder.
Example:
print $folder->directory;
METHODS for extension writers
- folderToDirectory FOLDERNAME, FOLDERDIR
-
(class method) Translate a foldername into a filename, with use of the FOLDERDIR to replace a leading
=
. - highestMessageNumber
-
Returns the highest number which is used in the folder to store a file. This method may be called when the folder is read (then this number can be derived without file-system access), but also when the folder is not read (yet).
- index
-
Create a index reader/writer object.
- labels
-
Create a label reader/writer object.
- readMessageFilenames DIRECTORY
-
Returns a list of all filenames which are found in this folder directory and represent a message. Message files are recognized by having a number as name.
- writeMessages [OPTIONS]
-
Write all messages to the folder-file.
OPTION DEFINED BY DEFAULT force Mail::Box <true> head_wrap Mail::Box 72 keep_deleted Mail::Box <false> renumber Mail::Box::MH <true> save_deleted Mail::Box <false>
MH specific options:
renumber => BOOL
Permit renumbering of message. Bij default this is true, but for some unknown reason, you may be thinking that messages should not be renumbered.
- readAllHeaders
-
Force all messages to be read at least till their header information is known.
IMPLEMENTATION
The explanation is complicated, but for normal use you should bother yourself with all details.
How MH-folders work
MH-type folders use a directory to store the messages of one folder. Each message is stored in a seperate file. This seems useful, because changes in a folder change only a few of these small files, in contrast with file-based folders where changes in a folder cause rewrites of huge folder-files.
However, MH-based folders perform very bad if you need header-information of all messages. For instance, if you want to have full knowledge about all message-threads (see Mail::Box::Thread::Manager
) in the folder, it requires to read all header-lines in all message-files. And usually, reading your messages as threads is desired.
So, each message is written in a seperate file. The file-names are numbers, which count from 1
. Next to these message-files, a directory may contain a file named .mh_sequences
, storing labels which relate to the messages. Furthermore, a folder-directory may contain sub-directories, which are seen as sub-folders.
This implementation
This implementation supports the .mh-sequences
file and sub-folders. Next to this, considerable effort it made to avoid reading each message-file. This should boost performance of the Mail::Box
module over other Perl-modules which are able to read folders.
Folder-types which store their messages each in one file, together in one directory, are bad for performance. Consider that you want to know the subjects of all messages, while browser through a folder with your mail-reading client. This would cause all message-files to be read.
Mail::Box::MH
has two ways to try improve performance. You can use an index-file, and use on delay-loading. The combination performs even better. Both are explained in the next sections.
An index-file
If you specify keep_index
as option to the folder creation method new()
, then all header-lines of all messages from the folder which have been read once, will also be written into one dedicated index-file (one file per folder). The default filename is .index
However, index-files are not supported by any other reader which supports MH (as far as I know). If you read the folders with such I client, it will not cause unrecoverable conflicts with this index-file, but at most be bad for performance.
If you do not (want to) use an index-file, then delay-loading may save your day.
Delayed loading
SEE ALSO
AUTHOR
Mark Overmeer (mailbox@overmeer.net). All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
VERSION
This code is beta, version 2.00_20.
Copyright (c) 2001 Mark Overmeer. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.