| Mail::Box::Manager(3pm) | User Contributed Perl Documentation | Mail::Box::Manager(3pm) |
Mail::Box::Manager - manage a set of folders
Mail::Box::Manager is a Mail::Reporter Mail::Box::Manager is extended by Mail::Box::Manage::User
use Mail::Box::Manager;
my $mgr = new Mail::Box::Manager;
# Create folder objects.
my $folder = $mgr->open(folder => $ENV{MAIL});
my $message1 = $folder->message(0);
$mgr->copyMessage('Draft', $message);
my @messages = $folder->message(0,3);
$mgr->moveMessage('Outbox', @messages, create => 1 );
$mgr->close($folder);
# Create thread-detectors (see Mail::Box::Thread::Manager)
my $t = $mgr->threads($inbox, $outbox);
my $threads = $mgr->threads(folder => $folder);
foreach my $thread ($threads->all)
{ $thread->print;
}
$mgr->registerType(mbox => 'Mail::Box::MyType');
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.
Extends "DESCRIPTION" in Mail::Reporter.
Extends "METHODS" in Mail::Reporter.
Extends "Constructors" in Mail::Reporter.
-Option --Defined in --Default
autodetect undef
default_folder_type 'mbox'
folder_types <all standard types>
folderdir [ '.' ]
folderdirs <synonym for C<folderdir>>
log Mail::Reporter 'WARNINGS'
trace Mail::Reporter 'WARNINGS'
Each TYPE is specified as an array which contains name, class, and defaults for options which overrule the usual defaults. You may specify folder-specific defaults as OPTIONS. They override the settings of the manager.
example:
print join("\n", $manager->folderTypes), "\n";
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');
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.
-Option --Default
close_by_self <false>
example:
my $inbox = $mgr->open('inbox');
$mgr->close($inbox);
$inbox->close; # alternative
example:
print "Yes\n" if $mgr->isOpenFolder('Inbox');
"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 Mail::Box::new() for each type of mail box.
-Option --Default
authenticate 'AUTO'
create <false>
folder $ENV{MAIL}
folderdir '.'
type <first, usually C<mbox>>
type://username:password@hostname:port/foldername
Like real URLs, all fields are optional and have smart defaults, as long as the string starts with a known folder type. Far from all folder types support all these options, but at least they are always split-out. Be warned that special characters in the password should be properly url-encoded.
When you specify anything which does not match the URL format, it is passed directly to the "new" method of the folder which is opened.
Currently, the types are mbox, mh, maildir, pop3, pop3s, and imap4.
example: opening folders via the manager
my $jack = $manager->open(folder => '=jack',
type => 'mbox');
my $rcvd = $manager->open('myMail',
type => 'Mail::Box::Mbox', access => 'rw');
my $inbox = $manager->open('Inbox')
or die "Cannot open Inbox.\n";
my $pop = 'pop3://myself:secret@pop3.server.com:120/x';
my $send = $manager->open($url);
my $send = $manager->open(folder => '/x',
type => 'pop3', username => 'myself', password => 'secret'
server_name => 'pop3.server.com', server_port => '120');
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.
-Option --Default
recursive <folder's default>
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 a 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 coerced messages (how the were actually written) are returned as list.
The %options is a list of key/values, which are added to (overriding) the default options for the detected folder type.
example:
$mgr->appendMessage('=send', $message, folderdir => '/');
$mgr->appendMessage($received, $inbox->messages);
my @appended = $mgr->appendMessages($inbox->messages,
folder => 'Drafts');
$_->label(seen => 1) foreach @appended;
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.
-Option--Default
share <false>
example:
my $drafts = $mgr->open(folder => 'Drafts'); my $outbox = $mgr->open(folder => 'Outbox'); $mgr->copyMessage($outbox, $drafts->message(0)); my @messages = $drafts->message(1,2); $mgr->copyMessage('=Trash', @messages, folderdir => '/tmp', create => 1); $mgr->copyMessage($drafts->message(1), folder => '=Drafts' folderdir => '/tmp', create => 1);
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.
BE WARNED that message labels may get lost when a message is moved from one folder type to an other. An attempt is made to translate labels, but there are many differences in interpretation by applications.
$mgr->moveMessage($received, $inbox->message(1))
is equivalent to
$mgr->copyMessage($received, $inbox->message(1), share => 1); $inbox->message(1)->delete; -Option--Default share <true>
example:
my $t1 = $mgr->threads(folders => [ $inbox, $send ]);
my $t2 = $mgr->threads($inbox);
my $t3 = $mgr->threads($inbox, $send);
Extends "Error handling" in Mail::Reporter.
Extends "Cleanup" in Mail::Reporter.
On many places in the documentation you can read that it is useful to have a manager object. There are two of them: the Mail::Box::Manager, which maintains a set of open folders, and an extension of it: the Mail::Box::Manage::User.
It is useful to start your program by creating a folder manager object, an Mail::Box::Manager. The object takes a few burdons from your neck:
This means that your application can be fully folder type independent.
There are so many modules involved in MailBox, that it is useful to have some lazy autoloading of code. The manager knows which modules belong to which type of folder.
Your programming mistakes may cause the same folder to be opened twice. The result of that could be very destructive. Therefore, the manager keeps track on all open folders and avoids the same folder to be opened for the second time.
When the program is ending, the manager will cleanly close all folders which are still open. This is required, because the autodestruct sequence of Perl works in an unpredicatable order.
MailBox can discover message threads which span multiple folders. Any set of open folders may be grouped in a tree of replies on replies on replies. When a folder is closed, it will automatically be removed from the threads, and a new folder can dynamically be added to the structure.
The manager is really simplifying things, and should therefore be the base of all programs. However, it is possible to write useful programs without it.
One step further is the Mail::Box::Manage::User object (since MailBox v2.057), which not only keeps track on open folders, but also collects information about not-open folders.
The user class is, as the name says, targeted on managing one single user. Where the Mail::Box::Manager will open any set of folder files, probably from multiple users, the user class want one root folder directory.
In many aspects, the user manager simplifies the task for user-based servers and other user-centric applications by setting smart defaults.
The manager tried to open a folder of the specified type. It may help to explicitly state the type of your folder with the "type" option. There will probably be another warning or error message which is related to this report and provides more details about its cause. You may also have a look at new(autodetect) and new(folder_types).
This module is part of Mail-Box distribution version 3.006, built on February 15, 2019. Website: http://perl.overmeer.net/CPAN/
Copyrights 2001-2019 by [Mark Overmeer]. For other contributors see ChangeLog.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://dev.perl.org/licenses/
| 2019-02-15 | perl v5.28.1 |