use Mail::Box::Manager; my $mgr = Mail::Box::Manager->new; my $folder = $mgr->open(folder => $ENV{MAIL}, ...); print $folder->name; # Get the first message. print $folder->message(0); # Delete the third message $folder->message(3)->delete; # Get the number of messages in scalar context. my $emails = $folder->messages; # Iterate over the messages. foreach ($folder->messages) {...} # all messages foreach (@$folder) {...} # all messages $folder->addMessage(Mail::Box::Message->new(...));
Tied-interface:
tie my(@inbox), 'Mail::Box::Tie::ARRAY', $inbox; # Four times the same: $inbox[3]->print; # tied $folder->[3]->print; # overloaded folder $folder->message(3)->print; # usual print $folder->[3]; # overloaded message tie my(%inbox), 'Mail::Box::Tie::HASH', $inbox; # Twice times the same $inbox{$msgid}->print; # tied $folder->messageId($msgid)->print;# usual
See SYNOPSIS in Mail::Reporter
A Mail::Box::Manager creates Mail::Box
objects. But you already
knew, because you started with the Mail::Box-Overview manual page.
That page is obligatory reading, sorry!
Mail::Box
is the base class for accessing various types of mailboxes
(folders) in a uniform manner. The various folder types vary on how
they store their messages, but when some effort those differences could
be hidden behind a general API. For example, some folders store many
messages in one single file, where other store each message in a separate
file withing the same directory.
No object in your program will be of type Mail::Box
: it is only used
as base class for the real folder types. Mail::Box
is extended by
See DESCRIPTION in Mail::Reporter
In general, there are three classes of folders: those who group messages per file, those who group messages in a directory, and those do not provide direct access to the message data. These folder types are each based on a different base class.
File based folders maintain a folder (a set of messages) in one single file. The advantage is that your folder has only one single file to access, which speeds-up things when all messages must be accessed at once.
One of the main disadvantages over directory based folders is that you have to construct some means to keep all message apart. For instance MBOX adds a message separator line between the messages in the file, and this line can cause confusion with the message's contents.
Where access to all messages at once is faster in file based folders, access to a single message is (much) slower, because the whole folder must be read. However, in directory based folders you have to figure-out which message you need, which may be a hassle as well.
Examples of file based folders are MBOX, DBX, and NetScape.
In stead of collecting multiple messages in one file, you can also put each message in a separate file and collect those files in a directory to represent a folder.
The main disadvantages of these folders are the enormous amount of tiny files you usually get in your file-system. It is extremely slow to search through your whole folder, because many files have to be opened to do so.
The best feature of this organization is that each message is kept exactly as it was received, and can be processed with external scripts as well: you do not need any mail user agent (MUA).
Examples of directoy organized folders are MH, Maildir, EMH, and XMH.
Where both types described before provide direct access to the message data, maintain these folder types the message data for you: you have to request for messages or parts of them. These folders do not have a filename, file-system privileges and system locking to worry about, but typically require a hostname, folder and message IDs, and authorization.
Examples of these folder types are the popular POP and IMAP, and database oriented message storage.
Writing and deleting messages is not supported by the library, and therefore not by MailBox. Read access is enough to do folder conversions, for instance.
tmp
, new
, and cur
sub-directories, each containting
messages with a different purpose. Files with new messages are created
in tmp
, then moved to new
(ready to be accepted). Later, they are
moved to the cur
directory (accepted). Each message is one file with
a name starting with timestamp. The name also contains flags about the
status of the message.
Maildir folders can not be used on Windows by reason of file-name limitations on that platform.
.mh_sequences
file maintains flags
about the messages.
Other folder types are on the (long) wishlist to get implemented. Please, help implementing more of them.
The class structure of folders is very close to that of messages. For instance, a Mail::Box::File::Message relates to a Mail::Box::File folder. The folder types are:
Mail::Box::Netzwert Mail::Box::Mbox | Mail::Box::Maildir Mail::Box::POP3 | Mail::Box::Dbx | | Mail::Box::MH | Mail::Box::IMAP4 | | | | | | | | | | | | | | Mail::Box::File Mail::Box::Dir Mail::Box::Net | | | `--------------. | .---------------' | | | Mail::Box | | Mail::Reporter (general base class)
By far most folder features are implemented in Mail::Box, so available to all folder types. Sometimes, features which appear in only some of the folder types are simulated for folders that miss them, like sub-folder support for MBOX.