NAME
Mail::Box::Manager - manage a set of folders
CLASS HIERARCHY
Mail::Box::Manager
is a Mail::Reporter
SYNOPSIS
use Mail::Box::Manager;
my $mgr = new Mail::Box::Manager;
$mgr->registerType(mbox => 'Mail::Box::Mbox');
# Create folder objects.
my $folder = $mgr->open(folder => $ENV{MAIL});
my $message = $folder->message(0);
my ($message1, $message2) = ($folder->message(1), $folder->message(2));
$mgr->copyMessage('Draft', $message);
$mgr->moveMessage('Outbox', $message1, $message2, create => 1 );
$mgr->close($folder);
# Create thread-detectors (see Mail::Box::Thread::Manager)
my $threads = $mgr->threads(folder => $folder);
foreach my $thread ($threads->all)
{ $thread->print;
}
DESCRIPTION
The manager keeps track on a set of open folders and a set of message-thread supporting objects. You are not obliged to use this object (you can directly create a Mail::Box::Mbox
if you prefer), but you will create more portable and safer code if you do use it.
Read Mail::Box-Overview
first.
METHOD INDEX
The general methods for Mail::Box::Manager
objects:
appendMessages [FOLDER|FOLD... new ARGS
close FOLDER open [FOLDERNAME], OPTIONS
closeAllFolders openFolders
copyMessage [FOLDER|FOLDERN... registerType TYPE =E<gt> CL...
delete FOLDERNAME [,OPTIONS] MR report [LEVEL]
MR errors MR reportAll [LEVEL]
folderTypes threads OPTIONS
isOpenFolder FOLDER toBeThreaded FOLDER, MESSAGES
MR log [LEVEL [,STRINGS]] toBeUnthreaded FOLDER, MESS...
moveMessage [FOLDER|FOLDERN... MR trace [LEVEL]
The extra methods for extension writers:
MR AUTOLOAD MR logPriority LEVEL
MR DESTROY MR logSettings
MR inGlobalDestruction MR notImplemented
Prefixed methods are described in MR = Mail::Reporter.
METHODS
- new ARGS
-
(class method) Create a new folder manager. This constructor may specify the following options:
OPTION DESCRIBED IN DEFAULT default_folder_type Mail::Box::Manager 'mbox' folder_types Mail::Box::Manager <mbox and mh> folderdir Mail::Box::Manager [ '.' ] folderdirs Mail::Box::Manager <synon for folderdir> log Mail::Reporter 'WARNINGS' trace Mail::Reporter 'WARNINGS'
folder_types => [ NAME => CLASS [,OPTIONS] ]
folder_types => [ [ NAME => CLASS [,OPTIONS] ], [...] ]
Add one or more folder_types to the list of known types. The order is important: when you open a file without specifying its type, the manager will start trying the last added list of types, in order.
You may specify folder-specific defaults as OPTIONS. They override the settings of the manager.
default_folder_type => NAME|CLASS
Specifies the default folder type for newly created folders. If this option is not specified, the most recently registered type is used (see
registerType
and thefolder_types
option.folderdir => DIRECTORY
folderdirs => [ DIRECTORY, ... ]
The default directory, or directories, where folders are located.
Mail::Box::Manager
can autodetect the existing folder-types. There may be different kinds of folders opened at the same time, and messages can be moved between those types, although that may result in a loss of information depending on the folder types.
- registerType TYPE => CLASS [,OPTIONS]
-
With
registerType
you can register one TYPE of folders. The CLASS is compiled automatically, so you do not need touse
them in your own modules. The TYPE is just an arbitrary name.The added types are prepended to the list of known types, so they are checked first when a folder is opened in autodetect mode.
Example:
$manager->registerType(mbox => 'Mail::Box::Mbox', save_on_exit => 0, folderdir => '/tmp');
- folderTypes
-
The
folderTypes
returns the list of currently defined folder types.Example:
print join("\n", $manager->folderTypes), "\n";
METHODS to handle folders
- open [FOLDERNAME], OPTIONS
-
Open a folder which name is specified as first parameter or with the option flag
folder
. The folder type is autodetected unless thetype
is specified.open
carries options for the manager which are described here, but may also have additional options for the folder type. For a description of the folder options, see the options to the constructor (thenew
method) for each type of mail-box, as well as the general folder options for the constructor of theMail::Box
base class.The options which are most common to
open()
:folder => FOLDERNAME
Which folder to open. The default folder is $ENV{MAIL}.
folderdir => DIRECTORY
The directory where the folders are usually stored.
type => FOLDERTYPENAME|FOLDERTYPE
Specify the type of the folder. If you do not specify this option while opening a folder for reading, the manager checks all registered folder types in order for the ability to open the folder. If you open a new folder for writing, then the default will be the most recently registered type. (If you add more than one type at once, the first of the list is used.)
create => BOOL
Create the folder if it does not exist. By default, this is not done. The
type
option specifies which type of folder is created.
Examples:
my $jack = $manager->open(folder => '=jack', type => 'mbox'); my $rcvd = $manager->open(type => 'Mail::Box::Mbox', access => 'rw'); my $inbox = $manager->open('Inbox');
- openFolders
-
Returns a list of all open folders.
- isOpenFolder FOLDER
-
Returns true if the FOLDER is currently open.
Example:
print "Yes\n" if $mgr->isOpenFolder('Inbox');
- close FOLDER
- closeAllFolders
-
close
removes the specified folder from the list of open folders. Indirectly it will update the files on disk if needed (depends on thesave_on_exit
flag for each folder). The folder's messages will also be withdrawn from the known message threads.You may also close the folder directly. The manager will be informed about this event and take appropriate actions.
Examples:
my $inbox = $mgr->open('inbox'); $mgr->close($inbox); $inbox->close; # alternative
closeAllFolders
callsclose
for each folder managed by this object. - appendMessages [FOLDER|FOLDERNAME,] MESSAGES, OPTIONS
-
Append one or more messages to a folder. You may specify a FOLDERNAME or an opened folder as the first argument. When the name is that of an open folder, it is treated as if the folder-object was specified, and not directly access the folder-files. You may also specify the foldername as part of the options list.
If a message is added to an already opened folder, it is only added to the structure internally in the program. The data will not be written to disk until a write of that folder takes place. When the name of an unopened folder is given, the folder is opened, the messages stored on disk, and then the folder is closed.
A message must be an instance of an
Mail::Message
. The actual message type does not have to match the folder type--the folder will try to resolve the differences with minimal loss of information.The OPTIONS is a list of key/values, which are added to (overriding) the default options for the detected folder type.
Examples:
$mgr->appendMessages('=send', $message, folderdir => '/'); $mgr->appendMessages('=received', $inbox->messages); $mgr->appendMessages($inbox->messages, folder => 'Drafts');
- copyMessage [FOLDER|FOLDERNAME,] MESSAGES, OPTIONS
-
Copy a message from one folder into another folder. If the destination folder is already opened, the copied message is stored in memory and written to disk when a write of the folder is later performed. Otherwise, the destination folder will be opened, the message written, and then the folder closed.
You need to specify a folder's name or folder object as the first argument, or in the options list. The options are the same as those which can be specified when opening a folder.
Examples:
my $drafts = $mgr->open(folder => 'Drafts'); my $outbox = $mgr->open(folder => 'Outbox'); $mgr->copyMessage($outbox, $drafts->message(0)); $mgr->copyMessage('Trash', $drafts->message(1), $drafts->message(2), folderdir => '/tmp', create => 1); $mgr->copyMessage($drafts->message(1), folder => 'Drafts' folderdir => '/tmp', create => 1);
- moveMessage [FOLDER|FOLDERNAME,] MESSAGES, OPTIONS
-
Move a message from one folder to another. Be warned that removals from a folder only take place when the folder is closed, so the message is only flagged to be deleted in the opened source folder.
$mgr->moveMessage($received, $inbox->message(1))
is equivalent to
$mgr->copyMessage($received, $inbox->message(1)); $inbox->message(1)->delete;
- delete FOLDERNAME [,OPTIONS]
-
Remove the named folder, including all its sub-folders. The OPTIONS are the same as those for
open()
.The deletion of a folder can take some time. Dependent on the type of folder, the folder must be read first. For some folder-types this will be fast.
METHODS to handle thread-objects
- threads OPTIONS
-
Create a new object which keeps track of message threads. You can read about the possible options in the
Mail::Box::Thread::Manager
documentation.Example:
$mgr->threads(folders => [ $inbox, $send ]);
- toBeThreaded FOLDER, MESSAGES
- toBeUnthreaded FOLDER, MESSAGES
-
Signal to the manager that all thread managers which are using the specified folder must be informed that new messages are coming in (or going out).
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.