1Mail::Box::Manager(3) User Contributed Perl DocumentationMail::Box::Manager(3)
2
3
4

NAME

6       Mail::Box::Manager - manage a set of folders
7

INHERITANCE

9        Mail::Box::Manager
10          is a Mail::Reporter
11
12        Mail::Box::Manager is extended by
13          Mail::Box::Manage::User
14

SYNOPSIS

16        use Mail::Box::Manager;
17        my $mgr     = new Mail::Box::Manager;
18
19        # Create folder objects.
20        my $folder   = $mgr->open(folder => $ENV{MAIL});
21        my $message1 = $folder->message(0);
22        $mgr->copyMessage('Draft', $message);
23
24        my @messages = $folder->message(0,3);
25        $mgr->moveMessage('Outbox', @messages, create => 1 );
26        $mgr->close($folder);
27
28        # Create thread-detectors (see Mail::Box::Thread::Manager)
29        my $t       = $mgr->threads($inbox, $outbox);
30
31        my $threads = $mgr->threads(folder => $folder);
32        foreach my $thread ($threads->all)
33        {   $thread->print;
34        }
35
36        $mgr->registerType(mbox => 'Mail::Box::MyType');
37

DESCRIPTION

39       The manager keeps track on a set of open folders and a set of message-
40       thread supporting objects.  You are not obliged to use this object (you
41       can directly create a Mail::Box::Mbox if you prefer), but you will
42       create more portable and safer code if you do use it.
43
44       Extends "DESCRIPTION" in Mail::Reporter.
45

METHODS

47       Extends "METHODS" in Mail::Reporter.
48
49   Constructors
50       Extends "Constructors" in Mail::Reporter.
51
52       Mail::Box::Manager->new($args)
53            -Option             --Defined in     --Default
54             autodetect                            undef
55             default_folder_type                   'mbox'
56             folder_types                          <all standard types>
57             folderdir                             [ '.' ]
58             folderdirs                            <synonym for C<folderdir>>
59             log                  Mail::Reporter   'WARNINGS'
60             trace                Mail::Reporter   'WARNINGS'
61
62           autodetect => TYPE|ARRAY-OF-TYPES
63             Select only a subset of the folder types which are implemented by
64             MailBox to be detected automatically.  This may improve the auto-
65             detection of folder types.  Normally, all folder types will be
66             tried when a folder's name is incorrect, but this option limits
67             the types which are checked and therefore may respond faster.
68
69           default_folder_type => NAME|CLASS
70             Specifies the default folder type for newly created folders.  If
71             this option is not specified, the most recently registered type
72             is used (see registerType() and the new(folder_types) option.
73
74           folder_types => NEW-TYPE | ARRAY-OF-NEW-TYPES
75             Add one or more new folder types to the list of known types.  The
76             order is important: when you open a file without specifying its
77             type, the manager will start trying the last added list of types,
78             in order.
79
80             Each TYPE is specified as an array which contains name, class,
81             and defaults for options which overrule the usual defaults.  You
82             may specify folder-specific defaults as OPTIONS.  They override
83             the settings of the manager.
84
85           folderdir => DIRECTORY
86             The default directory, or directories, where folders are located.
87             The "Mail::Box::Manager" can autodetect the existing folder-
88             types.  There may be different kinds of folders opened at the
89             same time, and messages can be moved between those types,
90             although that may result in a loss of information depending on
91             the folder types.
92
93           folderdirs => [DIRECTORIES]
94           log => LEVEL
95           trace => LEVEL
96
97   Attributes
98       $obj->defaultFolderType()
99           Returns the default folder type, some class name.
100
101       $obj->folderTypes()
102           Returns the list of currently defined folder types.
103
104           example:
105
106            print join("\n", $manager->folderTypes), "\n";
107
108       $obj->folderdir()
109           In list context, this returns all folderdirs specified.  In SCALAR
110           context only the first.
111
112       $obj->registerType($type, $class, %options)
113           With "registerType" you can register one $type of folders.  The
114           $class is compiled automatically, so you do not need to "use" them
115           in your own modules.  The $type is just an arbitrary name.
116
117           The added types are prepended to the list of known types, so they
118           are checked first when a folder is opened in autodetect mode.
119
120           example:
121
122            $manager->registerType(mbox => 'Mail::Box::Mbox',
123                save_on_exit => 0, folderdir => '/tmp');
124
125   Manage open folders
126       $obj->close($folder, %options)
127           "close" removes the specified folder from the list of open folders.
128           Indirectly it will update the files on disk if needed (depends on
129           the Mail::Box::new(save_on_exit) flag for each folder). %options
130           are passed to Mail::Box::close() of the folder.
131
132           The folder's messages will also be withdrawn from the known message
133           threads.  You may also close the folder directly. The manager will
134           be informed about this event and take appropriate actions.
135
136            -Option       --Default
137             close_by_self  <false>
138
139           close_by_self => BOOLEAN
140             Used internally to avoid confusion about how the close was
141             started.  Do not change this.
142
143           example:
144
145            my $inbox = $mgr->open('inbox');
146            $mgr->close($inbox);
147            $inbox->close;        # alternative
148
149       $obj->closeAllFolders(, %options)
150           "closeAllFolders" calls close() for each folder managed by this
151           object.  It is called just before the program stops (before global
152           cleanup).
153
154       $obj->isOpenFolder($folder)
155           Returns true if the $folder is currently open.
156
157           example:
158
159            print "Yes\n" if $mgr->isOpenFolder('Inbox');
160
161       $obj->open( [$foldername], %options )
162           Open a folder which name is specified as first parameter or with
163           the option flag "folder".  The folder type is autodetected unless
164           the "type" is specified.
165
166           "open" carries options for the manager which are described here,
167           but may also have additional options for the folder type.  For a
168           description of the folder options, see the options to the
169           constructor Mail::Box::new() for each type of mail box.
170
171            -Option      --Default
172             authenticate  'AUTO'
173             create        <false>
174             folder        $ENV{MAIL}
175             folderdir     '.'
176             type          <first, usually C<mbox>>
177
178           authenticate => TYPE|ARRAY-OF-TYPES|'AUTO'
179             The TYPE of authentication to be used, or a list of TYPES which
180             the client prefers.  The server may provide preferences as well,
181             and that order will be kept.  This option is only supported by a
182             small subset of folder types, especially by POP and IMAP.
183
184           create => BOOLEAN
185             Create the folder if it does not exist. By default, this is not
186             done.  The "type" option specifies which type of folder is
187             created.
188
189           folder => NAME|URL
190             Which folder to open, specified by NAME or special URL.  The URL
191             format is composed as
192
193              type://username:password@hostname:port/foldername
194
195             Like real URLs, all fields are optional and have smart defaults,
196             as long as the string starts with a known folder type.  Far from
197             all folder types support all these options, but at least they are
198             always split-out.  Be warned that special characters in the
199             password should be properly url-encoded.
200
201             When you specify anything which does not match the URL format, it
202             is passed directly to the "new" method of the folder which is
203             opened.
204
205           folderdir => DIRECTORY
206             The directory where the folders are usually stored.
207
208           type => FOLDERTYPENAME|FOLDERTYPE
209             Specify the type of the folder.  If you do not specify this
210             option while opening a folder for reading, the manager checks all
211             registered folder types in order for the ability to open the
212             folder. If you open a new folder for writing, then the default
213             will be the most recently registered type. (If you add more than
214             one type at once, the first of the list is used.)
215
216             Currently, the types are mbox, mh, maildir, pop3, pop3s, and
217             imap4.
218
219           example: opening folders via the manager
220
221            my $jack  = $manager->open(folder => '=jack',
222               type => 'mbox');
223
224            my $rcvd  = $manager->open('myMail',
225               type => 'Mail::Box::Mbox', access => 'rw');
226
227            my $inbox = $manager->open('Inbox')
228               or die "Cannot open Inbox.\n";
229
230            my $pop   = 'pop3://myself:secret@pop3.server.com:120/x';
231            my $send  = $manager->open($url);
232
233            my $send  = $manager->open(folder => '/x',
234              type => 'pop3', username => 'myself', password => 'secret'
235              server_name => 'pop3.server.com', server_port => '120');
236
237       $obj->openFolders()
238           Returns a list of all open folders.
239
240   Manage existing folders
241       $obj->delete($foldername, %options)
242           Remove the named folder.  The %options are the same as those for
243           open().
244
245           The deletion of a folder can take some time.  Dependent on the type
246           of folder, the folder must be read first.  For some folder-types
247           this will be fast.
248
249            -Option   --Default
250             recursive  <folder's default>
251
252           recursive => BOOLEAN
253             Some folder can only be recursively deleted, other have more
254             flexibility.
255
256   Move messages to folders
257       $obj->appendMessage( [$folder|$foldername], $messages, %options )
258           Append one or more messages to a folder (therefore, an
259           "appendMessages()" is defined as well). You may specify a
260           $foldername or an opened folder as the first argument. When the
261           name is that of an open folder, it is treated as if the folder-
262           object was specified, and not directly access the folder-files.
263           You may also specify the foldername as part of the options list.
264
265           If a message is added to an already opened folder, it is only added
266           to the structure internally in the program.  The data will not be
267           written to disk until a write of that folder takes place.  When the
268           name of an unopened folder is given, the folder is opened, the
269           messages stored on disk, and then the folder is closed.
270
271           A message must be an instance of a Mail::Message.  The actual
272           message type does not have to match the folder type--the folder
273           will try to resolve the differences with minimal loss of
274           information.  The coerced messages (how the were actually written)
275           are returned as list.
276
277           The %options is a list of key/values, which are added to
278           (overriding) the default options for the detected folder type.
279
280           example:
281
282            $mgr->appendMessage('=send', $message, folderdir => '/');
283            $mgr->appendMessage($received, $inbox->messages);
284
285            my @appended = $mgr->appendMessages($inbox->messages,
286               folder => 'Drafts');
287            $_->label(seen => 1) foreach @appended;
288
289       $obj->copyMessage( [$folder|$foldername], $messages, %options )
290           Copy a message from one folder into another folder.  If the
291           destination folder is already opened, Mail::Box::copyTo() is used.
292           Otherwise, Mail::Box::appendMessages() is called.
293
294           You need to specify a folder's name or folder object as the first
295           argument, or in the options list.  The options are the same as
296           those which can be specified when opening a folder.
297
298            -Option--Default
299             share   <false>
300
301           share => BOOLEAN
302             Try to share the physical storage of the messages.  The folder
303             types may be different, but it all depends on the actual folder
304             where the message is copied to.  Silently ignored when not
305             possible to share.
306
307           example:
308
309            my $drafts = $mgr->open(folder => 'Drafts');
310            my $outbox = $mgr->open(folder => 'Outbox');
311            $mgr->copyMessage($outbox, $drafts->message(0));
312
313            my @messages = $drafts->message(1,2);
314            $mgr->copyMessage('=Trash', @messages,
315               folderdir => '/tmp', create => 1);
316
317            $mgr->copyMessage($drafts->message(1),
318               folder => '=Drafts' folderdir => '/tmp',
319               create => 1);
320
321       $obj->moveMessage( [$folder|$foldername], $messages, %options )
322           Move a message from one folder to another.
323
324           BE WARNED that removals from a folder only take place when the
325           folder is closed, so the message is only flagged to be deleted in
326           the opened source folder.
327
328           BE WARNED that message labels may get lost when a message is moved
329           from one folder type to an other.  An attempt is made to translate
330           labels, but there are many differences in interpretation by
331           applications.
332
333            $mgr->moveMessage($received, $inbox->message(1))
334
335           is equivalent to
336
337            $mgr->copyMessage($received, $inbox->message(1), share => 1);
338            $inbox->message(1)->delete;
339
340            -Option--Default
341             share   <true>
342
343           share => BOOLEAN
344
345   Manage message threads
346       $obj->threads( [$folders], %options )
347           Create a new object which keeps track of message threads.  You can
348           read about the possible options in Mail::Box::Thread::Manager.  As
349           %options specify one folder or an array of $folders.  It is also
350           permitted to specify folders before the options.
351
352           example:
353
354            my $t1 = $mgr->threads(folders => [ $inbox, $send ]);
355            my $t2 = $mgr->threads($inbox);
356            my $t3 = $mgr->threads($inbox, $send);
357
358   Internals
359       $obj->decodeFolderURL($url)
360           Try to decompose a folder name which is specified as $url (see
361           open()) into separate options.  Special characters like @-sign,
362           colon, and slash used in the user or password parts must be passed
363           $url-encoded.
364
365       $obj->toBeThreaded($folder, $messages)
366           Signal to the manager that all thread managers which are using the
367           specified folder must be informed that new messages are coming in.
368
369       $obj->toBeUnthreaded($folder, $messages)
370           Signal to the manager that all thread managers which are using the
371           specified folder must be informed that new messages are or going
372           out.
373
374   Error handling
375       Extends "Error handling" in Mail::Reporter.
376
377       $obj->AUTOLOAD()
378           Inherited, see "Error handling" in Mail::Reporter
379
380       $obj->addReport($object)
381           Inherited, see "Error handling" in Mail::Reporter
382
383       $obj->defaultTrace( [$level]|[$loglevel, $tracelevel]|[$level,
384       $callback] )
385       Mail::Box::Manager->defaultTrace( [$level]|[$loglevel,
386       $tracelevel]|[$level, $callback] )
387           Inherited, see "Error handling" in Mail::Reporter
388
389       $obj->errors()
390           Inherited, see "Error handling" in Mail::Reporter
391
392       $obj->log( [$level, [$strings]] )
393       Mail::Box::Manager->log( [$level, [$strings]] )
394           Inherited, see "Error handling" in Mail::Reporter
395
396       $obj->logPriority($level)
397       Mail::Box::Manager->logPriority($level)
398           Inherited, see "Error handling" in Mail::Reporter
399
400       $obj->logSettings()
401           Inherited, see "Error handling" in Mail::Reporter
402
403       $obj->notImplemented()
404           Inherited, see "Error handling" in Mail::Reporter
405
406       $obj->report( [$level] )
407           Inherited, see "Error handling" in Mail::Reporter
408
409       $obj->reportAll( [$level] )
410           Inherited, see "Error handling" in Mail::Reporter
411
412       $obj->trace( [$level] )
413           Inherited, see "Error handling" in Mail::Reporter
414
415       $obj->warnings()
416           Inherited, see "Error handling" in Mail::Reporter
417
418   Cleanup
419       Extends "Cleanup" in Mail::Reporter.
420
421       $obj->DESTROY()
422           Inherited, see "Cleanup" in Mail::Reporter
423

DETAILS

425       On many places in the documentation you can read that it is useful to
426       have a manager object.  There are two of them: the Mail::Box::Manager,
427       which maintains a set of open folders, and an extension of it: the
428       Mail::Box::Manage::User.
429
430   Managing open folders
431       It is useful to start your program by creating a folder manager object,
432       an Mail::Box::Manager.  The object takes a few burdons from your neck:
433
434       ·   autodetect the type of folder which is used.
435
436           This means that your application can be fully folder type
437           independent.
438
439       ·   autoload the required modules
440
441           There are so many modules involved in MailBox, that it is useful to
442           have some lazy autoloading of code.  The manager knows which
443           modules belong to which type of folder.
444
445       ·   avoid double openings
446
447           Your programming mistakes may cause the same folder to be opened
448           twice.  The result of that could be very destructive.  Therefore,
449           the manager keeps track on all open folders and avoids the same
450           folder to be opened for the second time.
451
452       ·   close folders at clean-up
453
454           When the program is ending, the manager will cleanly close all
455           folders which are still open.  This is required, because the
456           autodestruct sequence of Perl works in an unpredicatable order.
457
458       ·   message thread detection
459
460           MailBox can discover message threads which span multiple folders.
461           Any set of open folders may be grouped in a tree of replies on
462           replies on replies.  When a folder is closed, it will automatically
463           be removed from the threads, and a new folder can dynamically be
464           added to the structure.
465
466       The manager is really simplifying things, and should therefore be the
467       base of all programs. However, it is possible to write useful programs
468       without it.
469
470   Managing a user
471       One step further is the Mail::Box::Manage::User object (since MailBox
472       v2.057), which not only keeps track on open folders, but also collects
473       information about not-open folders.
474
475       The user class is, as the name says, targeted on managing one single
476       user.  Where the Mail::Box::Manager will open any set of folder files,
477       probably from multiple users, the user class want one root folder
478       directory.
479
480       In many aspects, the user manager simplifies the task for user-based
481       servers and other user-centric applications by setting smart defaults.
482

DIAGNOSTICS

484       Error: Folder $name is already open.
485           You cannot ask the manager for a folder which is already open. In
486           some older releases (before MailBox 2.049), this was permitted, but
487           then behaviour changed, because many nasty side-effects are to be
488           expected.  For instance, an Mail::Box::update() on one folder
489           handle would influence the second, probably unexpectedly.
490
491       Error: Folder $name is not a Mail::Box; cannot add a message.
492           The folder where the message should be appended to is an object
493           which is not a folder type which extends Mail::Box.  Probably, it
494           is not a folder at all.
495
496       Warning: Folder does not exist, failed opening $type folder $name.
497           The folder does not exist and creating is not permitted (see
498           open(create)) or did not succeed.  When you do not have sufficient
499           access rights to the folder (for instance wrong password for POP3),
500           this warning will be produced as well.
501
502           The manager tried to open a folder of the specified type.  It may
503           help to explicitly state the type of your folder with the "type"
504           option.  There will probably be another warning or error message
505           which is related to this report and provides more details about its
506           cause.  You may also have a look at new(autodetect) and
507           new(folder_types).
508
509       Warning: Folder type $type is unknown, using autodetect.
510           The specified folder type (see open(type), possibly derived from
511           the folder name when specified as url) is not known to the manager.
512           This may mean that you forgot to require the Mail::Box extension
513           which implements this folder type, but probably it is a typo.
514           Usually, the manager is able to figure-out which type to use by
515           itself.
516
517       Error: Illegal folder URL '$url'.
518           The folder name was specified as URL, but not according to the
519           syntax.  See decodeFolderURL() for an description of the syntax.
520
521       Error: No foldername specified to open.
522           "open()" needs a folder name as first argument (before the list of
523           options), or with the "folder" option within the list.  If no name
524           was found, the MAIL environment variable is checked.  When even
525           that does not result in a usable folder, then this error is
526           produced.  The error may be caused by an accidental odd-length
527           option list.
528
529       Error: Package $package does not implement $method.
530           Fatal error: the specific package (or one of its superclasses) does
531           not implement this method where it should. This message means that
532           some other related classes do implement this method however the
533           class at hand does not.  Probably you should investigate this and
534           probably inform the author of the package.
535
536       Error: Use appendMessage() to add messages which are not in a folder.
537           You do not need to copy this message into the folder, because you
538           do not share the message between folders.
539
540       Warning: Use moveMessage() or copyMessage() to move between open
541       folders.
542           The message is already part of a folder, and now it should be
543           appended to a different folder.  You need to decide between copy or
544           move, which both will clone the message (not the body, because they
545           are immutable).
546
547       Warning: Will never create a folder $name without having write access.
548           You have set open(create), but only want to read the folder.
549           Create is only useful for folders which have write or append access
550           modes (see Mail::Box::new(access)).
551

SEE ALSO

553       This module is part of Mail-Box distribution version 3.005, built on
554       March 04, 2018. Website: http://perl.overmeer.net/CPAN/
555

LICENSE

557       Copyrights 2001-2018 by [Mark Overmeer]. For other contributors see
558       ChangeLog.
559
560       This program is free software; you can redistribute it and/or modify it
561       under the same terms as Perl itself.  See http://dev.perl.org/licenses/
562
563
564
565perl v5.28.0                      2018-03-04             Mail::Box::Manager(3)
Impressum