The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mail::Box::MH - handle MH folders

CLASS INHERITANCE

Mail::Box::MH is a Mail::Box::Dir 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.

METHODS

Initiation

new OPTIONS
 OPTION               DEFAULT
 access               'r'
 body_delayed_type    'Mail::Message::Body::Delayed'
 body_type            'Mail::Message::Body::Lines'
 coerce_options       []
 create               <false>
 extract              10240
 field_type           undef
 folder               $ENV{MAIL}
 folderdir            $ENV{HOME}/.mh
 head_delayed_type    'Mail::Message::Head::Delayed'
 head_type            'Mail::Message::Head::Complete'
 index                undef
 index_filename       foldername.'/.index'
 index_type           'Mail::Box::MH::Index'
 keep_dups            <false>
 keep_index           0
 labels               undef
 labels_filename      foldername.'/.mh_sequence'
 labels_type          'Mail::Box::MH::Labels'
 lock_file            <index_file>
 lock_timeout         1 hour
 lock_type            'Mail::Box::Locker::DotLock'
 lock_wait            10 seconds
 locker               undef
 log                  'WARNINGS'
 manager              undef
 message_type         'Mail::Box::Message'
 multipart_type       'Mail::Message::Body::Multipart'
 remove_when_empty    <true>
 save_on_exit         <true>
 trace                'WARNINGS'
 trusted              <depends on folder location>
access => MODE

See Mail::Box::new(access)

body_delayed_type => CLASS

See Mail::Box::new(body_delayed_type)

body_type => CLASS|CODE

See Mail::Box::new(body_type)

coerce_options => ARRAY

See Mail::Box::new(coerce_options)

create => BOOLEAN

See Mail::Box::new(create)

extract => INTEGER | CODE | METHOD | 'LAZY'|'ALWAYS'

See Mail::Box::new(extract)

field_type => CLASS

See Mail::Box::new(field_type)

folder => FOLDERNAME

See Mail::Box::new(folder)

folderdir => DIRECTORY

See Mail::Box::new(folderdir)

head_delayed_type => CLASS

See Mail::Box::new(head_delayed_type)

head_type => CLASS

See Mail::Box::new(head_type)

index => OBJECT

You may specify an OBJECT of a type which extends Mail::Box::MH::Index (at least implements the get() method), as alternative for an index file reader as created by Mail::Box::MH.

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, nor subdir/.index, but say .index.)

index_type => CLASS
keep_dups => BOOLEAN

See Mail::Box::new(keep_dups)

keep_index => BOOLEAN

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.

labels => OBJECT

You may specify an OBJECT of a type which extends Mail::Box::MH::Labels (at least implements the get() method), as alternative for labels file reader as created by Mail::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_type => CLASS
lock_file => FILENAME

See Mail::Box::new(lock_file)

lock_timeout => SECONDS

See Mail::Box::new(lock_timeout)

lock_type => CLASS|STRING

See Mail::Box::new(lock_type)

lock_wait => SECONDS

See Mail::Box::new(lock_wait)

locker => OBJECT

See Mail::Box::new(locker)

log => LEVEL

See Mail::Reporter::new(log)

manager => MANAGER

See Mail::Box::new(manager)

message_type => CLASS

See Mail::Box::new(message_type)

multipart_type => CLASS

See Mail::Box::new(multipart_type)

remove_when_empty => BOOLEAN

See Mail::Box::new(remove_when_empty)

save_on_exit => BOOLEAN

See Mail::Box::new(save_on_exit)

trace => LEVEL

See Mail::Reporter::new(trace)

trusted => BOOLEAN

See Mail::Box::new(trusted)

Opening folders

clone OPTIONS

See Mail::Box::clone()

create FOLDERNAME, OPTIONS

See Mail::Box::create()

folderdir [DIRECTORY]

See Mail::Box::folderdir()

foundIn [FOLDERNAME], OPTIONS

See Mail::Box::foundIn()

On open folders

addMessage MESSAGE

See Mail::Box::addMessage()

addMessages MESSAGE [, MESSAGE, ...]

See Mail::Box::addMessages()

copyTo FOLDER, OPTIONS

See Mail::Box::copyTo()

modified [BOOLEAN]

See Mail::Box::modified()

name

See Mail::Box::name()

organization

See Mail::Box::organization()

type

See Mail::Box::type()

update OPTIONS

See Mail::Box::update()

url

See Mail::Box::url()

writable

See Mail::Box::writable()

Closing the folder

DESTROY

See Mail::Box::DESTROY()

close OPTIONS

See Mail::Box::close()

delete

See Mail::Box::delete()

The messages

current [NUMBER|MESSAGE|MESSAGE-ID]

See Mail::Box::current()

find MESSAGE-ID

See Mail::Box::find()

message INDEX [,MESSAGE]

See Mail::Box::message()

messageId MESSAGE-ID [,MESSAGE]

See Mail::Box::messageId()

messageIds

See Mail::Box::messageIds()

messages ['ALL',RANGE,'ACTIVE','DELETED',LABEL,!LABEL,FILTER]

See Mail::Box::messages()

scanForMessages MESSAGE, MESSAGE-IDS, TIMESTAMP, WINDOW

See Mail::Box::scanForMessages()

Sub-folders

listSubFolders OPTIONS

See Mail::Box::listSubFolders()

openRelatedFolder OPTIONS

See Mail::Box::openRelatedFolder()

openSubFolder NAME, OPTIONS

See Mail::Box::openSubFolder()

Message threads [internals]

toBeThreaded MESSAGES

See Mail::Box::toBeThreaded()

toBeUnthreaded MESSAGES

See Mail::Box::toBeUnthreaded()

Reading and Writing [internals]

appendMessages OPTIONS

See Mail::Box::appendMessages()

coerce MESSAGE

See Mail::Box::coerce()

determineBodyType MESSAGE, HEAD

See Mail::Box::determineBodyType()

directory

See Mail::Box::Dir::directory()

folderToDirectory FOLDERNAME, FOLDERDIR

See Mail::Box::Dir::folderToDirectory()

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.

lineSeparator [STRING|'CR'|'LF'|'CRLF']

See Mail::Box::lineSeparator()

locker

See Mail::Box::locker()

read OPTIONS

See Mail::Box::read()

readMessageFilenames DIRECTORY

See Mail::Box::Dir::readMessageFilenames()

readMessages OPTIONS

See Mail::Box::readMessages()

storeMessage MESSAGE

See Mail::Box::storeMessage()

updateMessages OPTIONS

See Mail::Box::updateMessages()

write OPTIONS

See Mail::Box::write()

writeMessages OPTIONS
 OPTION               DEFAULT
 renumber             <true>
renumber => BOOLEAN

Permit renumbering of message. By default this is true, but for some unknown reason, you may be thinking that messages should not be renumbered.

Logging and Tracing

defaultTrace [LEVEL, [LEVEL]

See Mail::Reporter::defaultTrace()

errors

See Mail::Reporter::errors()

log [LEVEL [,STRINGS]]

See Mail::Reporter::log()

report [LEVEL]

See Mail::Reporter::report()

reportAll [LEVEL]

See Mail::Reporter::reportAll()

trace [LEVEL]

See Mail::Reporter::trace()

warnings

See Mail::Reporter::warnings()

Other Methods

AUTOLOAD

See Mail::Reporter::AUTOLOAD()

inGlobalDestruction

See Mail::Reporter::inGlobalDestruction()

logPriority LEVEL

See Mail::Reporter::logPriority()

logSettings

See Mail::Reporter::logSettings()

notImplemented

See Mail::Reporter::notImplemented()

timespan2seconds TIME

See Mail::Box::timespan2seconds()

IMPLEMENTATION

How MH-folders work

MH-type folders use a directory to store the messages of one folder. Each message is stored in a separate 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 in threads is desired.

So, each message is written in a separate file. The filenames 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.

Labels

User actions on a message are flagged with a label. When the folder is opened, these flags are read from the .mh_sequences file. When the folder is closed that file gets updated. Status and X-Status lines in the message headers -as used by Mbox folders- are only looked at when new messages are added to the folder. These lines are only updated when a MH message has to be written to a folder for some reason.

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.

SEE ALSO

A good start to read is Mail::Box-Overview. More documentation and a mailinglist are available from the project's website at http://perl.overmeer.net/mailbox/.

AUTHOR

Written by Mark Overmeer (mark@overmeer.net) with the help of many. See the ChangeLog for details.

VERSION

This code is beta, version 2.029.

Copyright (c) 2001-2002 by the authors. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.