Extends "METHODS" in Mail::Reporter.
Constructors
Extends "Constructors" in Mail::Reporter.
Mail::Box::Manager->new($args)
-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'
autodetect => TYPE|ARRAY-OF-TYPES
Select only a subset of the folder types which are implemented by MailBox to be detected
automatically. This may improve the auto-detection of folder types. Normally, all folder types
will be tried when a folder's name is incorrect, but this option limits the types which are checked
and therefore may respond faster.
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 the new(folder_types) option.
folder_types => NEW-TYPE | ARRAY-OF-NEW-TYPES
Add one or more new 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.
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.
folderdir => DIRECTORY
The default directory, or directories, where folders are located. The "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.
folderdirs => [DIRECTORIES]
log => LEVEL
trace => LEVEL
Attributes
$obj->defaultFolderType()
Returns the default folder type, some class name.
$obj->folderTypes()
Returns the list of currently defined folder types.
example:
print join("\n", $manager->folderTypes), "\n";
$obj->folderdir()
In list context, this returns all folderdirs specified. In SCALAR context only the first.
$obj->registerType($type, $class, %options)
With "registerType" you can register one $type of folders. The $class is compiled automatically, so
you do not need to "use" 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');
Manageopenfolders
$obj->close($folder, %options)
"close" removes the specified folder from the list of open folders. Indirectly it will update the
files on disk if needed (depends on the Mail::Box::new(save_on_exit) flag for each folder). %options
are passed to Mail::Box::close() of the 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.
-Option --Default
close_by_self <false>
close_by_self => BOOLEAN
Used internally to avoid confusion about how the close was started. Do not change this.
example:
my $inbox = $mgr->open('inbox');
$mgr->close($inbox);
$inbox->close; # alternative
$obj->closeAllFolders(, %options)
"closeAllFolders" calls close() for each folder managed by this object. It is called just before the
program stops (before global cleanup).
$obj->isOpenFolder($folder)
Returns true if the $folder is currently open.
example:
print "Yes\n" if $mgr->isOpenFolder('Inbox');
$obj->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 the "type" 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
Mail::Box::new() for each type of mail box.
-Option --Default
authenticate 'AUTO'
create <false>
folder $ENV{MAIL}
folderdir '.'
type <first, usually C<mbox>>
authenticate => TYPE|ARRAY-OF-TYPES|'AUTO'
The TYPE of authentication to be used, or a list of TYPES which the client prefers. The server may
provide preferences as well, and that order will be kept. This option is only supported by a small
subset of folder types, especially by POP and IMAP.
create => BOOLEAN
Create the folder if it does not exist. By default, this is not done. The "type" option specifies
which type of folder is created.
folder => NAME|URL
Which folder to open, specified by NAME or special URL. The URL format is composed as
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.
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.)
Currently, the types are "mbox", "mh", "maildir", "pop3", "pop3s", "imap4", and "imap4s". You may
also use names "pop", "pops", "imap", and "imaps".
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');
$obj->openFolders()
Returns a list of all open folders.
Manageexistingfolders
$obj->delete($foldername, %options)
Remove the named folder. 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.
-Option --Default
recursive <folder's default>
recursive => BOOLEAN
Some folder can only be recursively deleted, other have more flexibility.
Movemessagestofolders
$obj->appendMessage( [$folder|$foldername], $messages, %options )
Append one or more messages to a folder (therefore, an appendMessages() is defined as well). 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 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;
$obj->copyMessage( [$folder|$foldername], $messages, %options )
Copy a message from one folder into another folder. If the destination folder is already opened,
Mail::Box::copyTo() is used. Otherwise, Mail::Box::appendMessages() is called.
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>
share => BOOLEAN
Try to share the physical storage of the messages. The folder types may be different, but it all
depends on the actual folder where the message is copied to. Silently ignored when not possible to
share.
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);
$obj->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.
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>
share => BOOLEAN
Managemessagethreads
$obj->threads( [$folders], %options )
Create a new object which keeps track of message threads. You can read about the possible options in
Mail::Box::Thread::Manager. As %options specify one folder or an array of $folders. It is also
permitted to specify folders before the options.
example:
my $t1 = $mgr->threads(folders => [ $inbox, $send ]);
my $t2 = $mgr->threads($inbox);
my $t3 = $mgr->threads($inbox, $send);
Internals
$obj->decodeFolderURL($url)
Try to decompose a folder name which is specified as $url (see open()) into separate options.
Special characters like @-sign, colon, and slash used in the user or password parts must be passed
$url-encoded.
$obj->toBeThreaded($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.
$obj->toBeUnthreaded($folder, $messages)
Signal to the manager that all thread managers which are using the specified folder must be informed
that new messages are or going out.
Errorhandling
Extends "Error handling" in Mail::Reporter.
$obj->AUTOLOAD()
Inherited, see "Error handling" in Mail::Reporter
$obj->addReport($object)
Inherited, see "Error handling" in Mail::Reporter
$obj->defaultTrace( [$level]|[$loglevel, $tracelevel]|[$level, $callback] )
Mail::Box::Manager->defaultTrace( [$level]|[$loglevel, $tracelevel]|[$level, $callback] )
Inherited, see "Error handling" in Mail::Reporter
$obj->errors()
Inherited, see "Error handling" in Mail::Reporter
$obj->log( [$level, [$strings]] )
Mail::Box::Manager->log( [$level, [$strings]] )
Inherited, see "Error handling" in Mail::Reporter
$obj->logPriority($level)
Mail::Box::Manager->logPriority($level)
Inherited, see "Error handling" in Mail::Reporter
$obj->logSettings()
Inherited, see "Error handling" in Mail::Reporter
$obj->notImplemented()
Inherited, see "Error handling" in Mail::Reporter
$obj->report( [$level] )
Inherited, see "Error handling" in Mail::Reporter
$obj->reportAll( [$level] )
Inherited, see "Error handling" in Mail::Reporter
$obj->trace( [$level] )
Inherited, see "Error handling" in Mail::Reporter
$obj->warnings()
Inherited, see "Error handling" in Mail::Reporter
Cleanup
Extends "Cleanup" in Mail::Reporter.
$obj->DESTROY()
Inherited, see "Cleanup" in Mail::Reporter