{
    "content": [
        {
            "type": "text",
            "text": "# Mail::Box::Manager (perldoc)\n\n## NAME\n\nMail::Box::Manager - manage a set of folders\n\n## SYNOPSIS\n\nuse Mail::Box::Manager;\nmy $mgr     = new Mail::Box::Manager;\n# Create folder objects.\nmy $folder   = $mgr->open(folder => $ENV{MAIL});\nmy $message1 = $folder->message(0);\n$mgr->copyMessage('Draft', $message);\nmy @messages = $folder->message(0,3);\n$mgr->moveMessage('Outbox', @messages, create => 1 );\n$mgr->close($folder);\n# Create thread-detectors (see Mail::Box::Thread::Manager)\nmy $t       = $mgr->threads($inbox, $outbox);\nmy $threads = $mgr->threads(folder => $folder);\nforeach my $thread ($threads->all)\n{   $thread->print;\n}\n$mgr->registerType(mbox => 'Mail::Box::MyType');\n\n## DESCRIPTION\n\nThe manager keeps track on a set of open folders and a set of message-thread supporting objects.\nYou are not obliged to use this object (you can directly create a Mail::Box::Mbox if you\nprefer), but you will create more portable and safer code if you do use it.\n\n## Sections\n\n- **NAME**\n- **INHERITANCE**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **METHODS** (9 subsections)\n- **DETAILS** (2 subsections)\n- **DIAGNOSTICS**\n- **SEE ALSO**\n- **LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Mail::Box::Manager",
        "section": "",
        "mode": "perldoc",
        "summary": "Mail::Box::Manager - manage a set of folders",
        "synopsis": "use Mail::Box::Manager;\nmy $mgr     = new Mail::Box::Manager;\n# Create folder objects.\nmy $folder   = $mgr->open(folder => $ENV{MAIL});\nmy $message1 = $folder->message(0);\n$mgr->copyMessage('Draft', $message);\nmy @messages = $folder->message(0,3);\n$mgr->moveMessage('Outbox', @messages, create => 1 );\n$mgr->close($folder);\n# Create thread-detectors (see Mail::Box::Thread::Manager)\nmy $t       = $mgr->threads($inbox, $outbox);\nmy $threads = $mgr->threads(folder => $folder);\nforeach my $thread ($threads->all)\n{   $thread->print;\n}\n$mgr->registerType(mbox => 'Mail::Box::MyType');",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "INHERITANCE",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 22,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 2,
                "subsections": [
                    {
                        "name": "Constructors",
                        "lines": 42
                    },
                    {
                        "name": "Attributes",
                        "lines": 26
                    },
                    {
                        "name": "Manage open folders",
                        "lines": 103
                    },
                    {
                        "name": "Manage existing folders",
                        "lines": 12
                    },
                    {
                        "name": "Move messages to folders",
                        "lines": 80
                    },
                    {
                        "name": "Manage message threads",
                        "lines": 11
                    },
                    {
                        "name": "Internals",
                        "lines": 13
                    },
                    {
                        "name": "Error handling",
                        "lines": 41
                    },
                    {
                        "name": "Cleanup",
                        "lines": 5
                    }
                ]
            },
            {
                "name": "DETAILS",
                "lines": 4,
                "subsections": [
                    {
                        "name": "Managing open folders",
                        "lines": 34
                    },
                    {
                        "name": "Managing a user",
                        "lines": 10
                    }
                ]
            },
            {
                "name": "DIAGNOSTICS",
                "lines": 55,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "LICENSE",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Mail::Box::Manager - manage a set of folders\n",
                "subsections": []
            },
            "INHERITANCE": {
                "content": "Mail::Box::Manager\nis a Mail::Reporter\n\nMail::Box::Manager is extended by\nMail::Box::Manage::User\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Mail::Box::Manager;\nmy $mgr     = new Mail::Box::Manager;\n\n# Create folder objects.\nmy $folder   = $mgr->open(folder => $ENV{MAIL});\nmy $message1 = $folder->message(0);\n$mgr->copyMessage('Draft', $message);\n\nmy @messages = $folder->message(0,3);\n$mgr->moveMessage('Outbox', @messages, create => 1 );\n$mgr->close($folder);\n\n# Create thread-detectors (see Mail::Box::Thread::Manager)\nmy $t       = $mgr->threads($inbox, $outbox);\n\nmy $threads = $mgr->threads(folder => $folder);\nforeach my $thread ($threads->all)\n{   $thread->print;\n}\n\n$mgr->registerType(mbox => 'Mail::Box::MyType');\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "The manager keeps track on a set of open folders and a set of message-thread supporting objects.\nYou are not obliged to use this object (you can directly create a Mail::Box::Mbox if you\nprefer), but you will create more portable and safer code if you do use it.\n\nExtends \"DESCRIPTION\" in Mail::Reporter.\n",
                "subsections": []
            },
            "METHODS": {
                "content": "Extends \"METHODS\" in Mail::Reporter.\n",
                "subsections": [
                    {
                        "name": "Constructors",
                        "content": "Extends \"Constructors\" in Mail::Reporter.\n\nMail::Box::Manager->new($args)\n-Option             --Defined in     --Default\nautodetect                            undef\ndefaultfoldertype                   'mbox'\nfoldertypes                          <all standard types>\nfolderdir                             [ '.' ]\nfolderdirs                            <synonym for C<folderdir>>\nlog                  Mail::Reporter   'WARNINGS'\ntrace                Mail::Reporter   'WARNINGS'\n\nautodetect => TYPE|ARRAY-OF-TYPES\nSelect only a subset of the folder types which are implemented by MailBox to be detected\nautomatically. This may improve the auto-detection of folder types. Normally, all folder\ntypes will be tried when a folder's name is incorrect, but this option limits the types\nwhich are checked and therefore may respond faster.\n\ndefaultfoldertype => NAME|CLASS\nSpecifies the default folder type for newly created folders. If this option is not\nspecified, the most recently registered type is used (see registerType() and the\nnew(foldertypes) option.\n\nfoldertypes => NEW-TYPE | ARRAY-OF-NEW-TYPES\nAdd one or more new folder types to the list of known types. The order is important: when\nyou open a file without specifying its type, the manager will start trying the last added\nlist of types, in order.\n\nEach TYPE is specified as an array which contains name, class, and defaults for options\nwhich overrule the usual defaults. You may specify folder-specific defaults as OPTIONS.\nThey override the settings of the manager.\n\nfolderdir => DIRECTORY\nThe default directory, or directories, where folders are located. The \"Mail::Box::Manager\"\ncan autodetect the existing folder-types. There may be different kinds of folders opened\nat the same time, and messages can be moved between those types, although that may result\nin a loss of information depending on the folder types.\n\nfolderdirs => [DIRECTORIES]\nlog => LEVEL\ntrace => LEVEL\n"
                    },
                    {
                        "name": "Attributes",
                        "content": "$obj->defaultFolderType()\nReturns the default folder type, some class name.\n\n$obj->folderTypes()\nReturns the list of currently defined folder types.\n\nexample:\n\nprint join(\"\\n\", $manager->folderTypes), \"\\n\";\n\n$obj->folderdir()\nIn list context, this returns all folderdirs specified. In SCALAR context only the first.\n\n$obj->registerType($type, $class, %options)\nWith \"registerType\" you can register one $type of folders. The $class is compiled\nautomatically, so you do not need to \"use\" them in your own modules. The $type is just an\narbitrary name.\n\nThe added types are prepended to the list of known types, so they are checked first when a\nfolder is opened in autodetect mode.\n\nexample:\n\n$manager->registerType(mbox => 'Mail::Box::Mbox',\nsaveonexit => 0, folderdir => '/tmp');\n"
                    },
                    {
                        "name": "Manage open folders",
                        "content": "$obj->close($folder, %options)\n\"close\" removes the specified folder from the list of open folders. Indirectly it will\nupdate the files on disk if needed (depends on the Mail::Box::new(saveonexit) flag for\neach folder). %options are passed to Mail::Box::close() of the folder.\n\nThe folder's messages will also be withdrawn from the known message threads. You may also\nclose the folder directly. The manager will be informed about this event and take\nappropriate actions.\n\n-Option       --Default\nclosebyself  <false>\n\nclosebyself => BOOLEAN\nUsed internally to avoid confusion about how the close was started. Do not change this.\n\nexample:\n\nmy $inbox = $mgr->open('inbox');\n$mgr->close($inbox);\n$inbox->close;        # alternative\n\n$obj->closeAllFolders(, %options)\n\"closeAllFolders\" calls close() for each folder managed by this object. It is called just\nbefore the program stops (before global cleanup).\n\n$obj->isOpenFolder($folder)\nReturns true if the $folder is currently open.\n\nexample:\n\nprint \"Yes\\n\" if $mgr->isOpenFolder('Inbox');\n\n$obj->open( [$foldername], %options )\nOpen a folder which name is specified as first parameter or with the option flag \"folder\".\nThe folder type is autodetected unless the \"type\" is specified.\n\n\"open\" carries options for the manager which are described here, but may also have\nadditional options for the folder type. For a description of the folder options, see the\noptions to the constructor Mail::Box::new() for each type of mail box.\n\n-Option      --Default\nauthenticate  'AUTO'\ncreate        <false>\nfolder        $ENV{MAIL}\nfolderdir     '.'\ntype          <first, usually C<mbox>>\n\nauthenticate => TYPE|ARRAY-OF-TYPES|'AUTO'\nThe TYPE of authentication to be used, or a list of TYPES which the client prefers. The\nserver may provide preferences as well, and that order will be kept. This option is only\nsupported by a small subset of folder types, especially by POP and IMAP.\n\ncreate => BOOLEAN\nCreate the folder if it does not exist. By default, this is not done. The \"type\" option\nspecifies which type of folder is created.\n\nfolder => NAME|URL\nWhich folder to open, specified by NAME or special URL. The URL format is composed as\n\ntype://username:password@hostname:port/foldername\n\nLike real URLs, all fields are optional and have smart defaults, as long as the string\nstarts with a known folder type. Far from all folder types support all these options, but\nat least they are always split-out. Be warned that special characters in the password\nshould be properly url-encoded.\n\nWhen you specify anything which does not match the URL format, it is passed directly to\nthe \"new\" method of the folder which is opened.\n\nfolderdir => DIRECTORY\nThe directory where the folders are usually stored.\n\ntype => FOLDERTYPENAME|FOLDERTYPE\nSpecify the type of the folder. If you do not specify this option while opening a folder\nfor reading, the manager checks all registered folder types in order for the ability to\nopen the folder. If you open a new folder for writing, then the default will be the most\nrecently registered type. (If you add more than one type at once, the first of the list is\nused.)\n\nCurrently, the types are \"mbox\", \"mh\", \"maildir\", \"pop3\", \"pop3s\", \"imap4\", and \"imap4s\".\nYou may also use names \"pop\", \"pops\", \"imap\", and \"imaps\".\n\nexample: opening folders via the manager\n\nmy $jack  = $manager->open(folder => '=jack',\ntype => 'mbox');\n\nmy $rcvd  = $manager->open('myMail',\ntype => 'Mail::Box::Mbox', access => 'rw');\n\nmy $inbox = $manager->open('Inbox')\nor die \"Cannot open Inbox.\\n\";\n\nmy $pop   = 'pop3://myself:secret@pop3.server.com:120/x';\nmy $send  = $manager->open($url);\n\nmy $send  = $manager->open(folder => '/x',\ntype => 'pop3', username => 'myself', password => 'secret'\nservername => 'pop3.server.com', serverport => '120');\n\n$obj->openFolders()\nReturns a list of all open folders.\n"
                    },
                    {
                        "name": "Manage existing folders",
                        "content": "$obj->delete($foldername, %options)\nRemove the named folder. The %options are the same as those for open().\n\nThe deletion of a folder can take some time. Dependent on the type of folder, the folder\nmust be read first. For some folder-types this will be fast.\n\n-Option   --Default\nrecursive  <folder's default>\n\nrecursive => BOOLEAN\nSome folder can only be recursively deleted, other have more flexibility.\n"
                    },
                    {
                        "name": "Move messages to folders",
                        "content": "$obj->appendMessage( [$folder|$foldername], $messages, %options )\nAppend one or more messages to a folder (therefore, an \"appendMessages()\" is defined as\nwell). You may specify a $foldername or an opened folder as the first argument. When the\nname is that of an open folder, it is treated as if the folder-object was specified, and not\ndirectly access the folder-files. You may also specify the foldername as part of the options\nlist.\n\nIf a message is added to an already opened folder, it is only added to the structure\ninternally in the program. The data will not be written to disk until a write of that folder\ntakes place. When the name of an unopened folder is given, the folder is opened, the\nmessages stored on disk, and then the folder is closed.\n\nA message must be an instance of a Mail::Message. The actual message type does not have to\nmatch the folder type--the folder will try to resolve the differences with minimal loss of\ninformation. The coerced messages (how the were actually written) are returned as list.\n\nThe %options is a list of key/values, which are added to (overriding) the default options\nfor the detected folder type.\n\nexample:\n\n$mgr->appendMessage('=send', $message, folderdir => '/');\n$mgr->appendMessage($received, $inbox->messages);\n\nmy @appended = $mgr->appendMessages($inbox->messages,\nfolder => 'Drafts');\n$->label(seen => 1) foreach @appended;\n\n$obj->copyMessage( [$folder|$foldername], $messages, %options )\nCopy a message from one folder into another folder. If the destination folder is already\nopened, Mail::Box::copyTo() is used. Otherwise, Mail::Box::appendMessages() is called.\n\nYou need to specify a folder's name or folder object as the first argument, or in the\noptions list. The options are the same as those which can be specified when opening a\nfolder.\n\n-Option--Default\nshare   <false>\n\nshare => BOOLEAN\nTry to share the physical storage of the messages. The folder types may be different, but\nit all depends on the actual folder where the message is copied to. Silently ignored when\nnot possible to share.\n\nexample:\n\nmy $drafts = $mgr->open(folder => 'Drafts');\nmy $outbox = $mgr->open(folder => 'Outbox');\n$mgr->copyMessage($outbox, $drafts->message(0));\n\nmy @messages = $drafts->message(1,2);\n$mgr->copyMessage('=Trash', @messages,\nfolderdir => '/tmp', create => 1);\n\n$mgr->copyMessage($drafts->message(1),\nfolder => '=Drafts' folderdir => '/tmp',\ncreate => 1);\n\n$obj->moveMessage( [$folder|$foldername], $messages, %options )\nMove a message from one folder to another.\n\nBE WARNED that removals from a folder only take place when the folder is closed, so the\nmessage is only flagged to be deleted in the opened source folder.\n\nBE WARNED that message labels may get lost when a message is moved from one folder type to\nan other. An attempt is made to translate labels, but there are many differences in\ninterpretation by applications.\n\n$mgr->moveMessage($received, $inbox->message(1))\n\nis equivalent to\n\n$mgr->copyMessage($received, $inbox->message(1), share => 1);\n$inbox->message(1)->delete;\n\n-Option--Default\nshare   <true>\n\nshare => BOOLEAN\n"
                    },
                    {
                        "name": "Manage message threads",
                        "content": "$obj->threads( [$folders], %options )\nCreate a new object which keeps track of message threads. You can read about the possible\noptions in Mail::Box::Thread::Manager. As %options specify one folder or an array of\n$folders. It is also permitted to specify folders before the options.\n\nexample:\n\nmy $t1 = $mgr->threads(folders => [ $inbox, $send ]);\nmy $t2 = $mgr->threads($inbox);\nmy $t3 = $mgr->threads($inbox, $send);\n"
                    },
                    {
                        "name": "Internals",
                        "content": "$obj->decodeFolderURL($url)\nTry to decompose a folder name which is specified as $url (see open()) into separate\noptions. Special characters like @-sign, colon, and slash used in the user or password parts\nmust be passed $url-encoded.\n\n$obj->toBeThreaded($folder, $messages)\nSignal to the manager that all thread managers which are using the specified folder must be\ninformed that new messages are coming in.\n\n$obj->toBeUnthreaded($folder, $messages)\nSignal to the manager that all thread managers which are using the specified folder must be\ninformed that new messages are or going out.\n"
                    },
                    {
                        "name": "Error handling",
                        "content": "Extends \"Error handling\" in Mail::Reporter.\n\n$obj->AUTOLOAD()\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->addReport($object)\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->defaultTrace( [$level]|[$loglevel, $tracelevel]|[$level, $callback] )\nMail::Box::Manager->defaultTrace( [$level]|[$loglevel, $tracelevel]|[$level, $callback] )\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->errors()\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->log( [$level, [$strings]] )\nMail::Box::Manager->log( [$level, [$strings]] )\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->logPriority($level)\nMail::Box::Manager->logPriority($level)\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->logSettings()\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->notImplemented()\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->report( [$level] )\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->reportAll( [$level] )\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->trace( [$level] )\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->warnings()\nInherited, see \"Error handling\" in Mail::Reporter\n"
                    },
                    {
                        "name": "Cleanup",
                        "content": "Extends \"Cleanup\" in Mail::Reporter.\n\n$obj->DESTROY()\nInherited, see \"Cleanup\" in Mail::Reporter\n"
                    }
                ]
            },
            "DETAILS": {
                "content": "On many places in the documentation you can read that it is useful to have a manager object.\nThere are two of them: the Mail::Box::Manager, which maintains a set of open folders, and an\nextension of it: the Mail::Box::Manage::User.\n",
                "subsections": [
                    {
                        "name": "Managing open folders",
                        "content": "It is useful to start your program by creating a folder manager object, an Mail::Box::Manager.\nThe object takes a few burdons from your neck:\n\n*   autodetect the type of folder which is used.\n\nThis means that your application can be fully folder type independent.\n\n*   autoload the required modules\n\nThere are so many modules involved in MailBox, that it is useful to have some lazy\nautoloading of code. The manager knows which modules belong to which type of folder.\n\n*   avoid double openings\n\nYour programming mistakes may cause the same folder to be opened twice. The result of that\ncould be very destructive. Therefore, the manager keeps track on all open folders and avoids\nthe same folder to be opened for the second time.\n\n*   close folders at clean-up\n\nWhen the program is ending, the manager will cleanly close all folders which are still open.\nThis is required, because the autodestruct sequence of Perl works in an unpredicatable\norder.\n\n*   message thread detection\n\nMailBox can discover message threads which span multiple folders. Any set of open folders\nmay be grouped in a tree of replies on replies on replies. When a folder is closed, it will\nautomatically be removed from the threads, and a new folder can dynamically be added to the\nstructure.\n\nThe manager is really simplifying things, and should therefore be the base of all programs.\nHowever, it is possible to write useful programs without it.\n"
                    },
                    {
                        "name": "Managing a user",
                        "content": "One step further is the Mail::Box::Manage::User object (since MailBox v2.057), which not only\nkeeps track on open folders, but also collects information about not-open folders.\n\nThe user class is, as the name says, targeted on managing one single user. Where the\nMail::Box::Manager will open any set of folder files, probably from multiple users, the user\nclass want one root folder directory.\n\nIn many aspects, the user manager simplifies the task for user-based servers and other\nuser-centric applications by setting smart defaults.\n"
                    }
                ]
            },
            "DIAGNOSTICS": {
                "content": "Error: Folder $name is already open.\nYou cannot ask the manager for a folder which is already open. In some older releases\n(before MailBox 2.049), this was permitted, but then behaviour changed, because many nasty\nside-effects are to be expected. For instance, an Mail::Box::update() on one folder handle\nwould influence the second, probably unexpectedly.\n\nError: Folder $name is not a Mail::Box; cannot add a message.\nThe folder where the message should be appended to is an object which is not a folder type\nwhich extends Mail::Box. Probably, it is not a folder at all.\n\nWarning: Folder does not exist, failed opening $type folder $name.\nThe folder does not exist and creating is not permitted (see open(create)) or did not\nsucceed. When you do not have sufficient access rights to the folder (for instance wrong\npassword for POP3), this warning will be produced as well.\n\nThe manager tried to open a folder of the specified type. It may help to explicitly state\nthe type of your folder with the \"type\" option. There will probably be another warning or\nerror message which is related to this report and provides more details about its cause. You\nmay also have a look at new(autodetect) and new(foldertypes).\n\nWarning: Folder type $type is unknown, using autodetect.\nThe specified folder type (see open(type), possibly derived from the folder name when\nspecified as url) is not known to the manager. This may mean that you forgot to require the\nMail::Box extension which implements this folder type, but probably it is a typo. Usually,\nthe manager is able to figure-out which type to use by itself.\n\nError: Illegal folder URL '$url'.\nThe folder name was specified as URL, but not according to the syntax. See decodeFolderURL()\nfor an description of the syntax.\n\nError: No foldername specified to open.\n\"open()\" needs a folder name as first argument (before the list of options), or with the\n\"folder\" option within the list. If no name was found, the MAIL environment variable is\nchecked. When even that does not result in a usable folder, then this error is produced. The\nerror may be caused by an accidental odd-length option list.\n\nError: Package $package does not implement $method.\nFatal error: the specific package (or one of its superclasses) does not implement this\nmethod where it should. This message means that some other related classes do implement this\nmethod however the class at hand does not. Probably you should investigate this and probably\ninform the author of the package.\n\nError: Use appendMessage() to add messages which are not in a folder.\nYou do not need to copy this message into the folder, because you do not share the message\nbetween folders.\n\nWarning: Use moveMessage() or copyMessage() to move between open folders.\nThe message is already part of a folder, and now it should be appended to a different\nfolder. You need to decide between copy or move, which both will clone the message (not the\nbody, because they are immutable).\n\nWarning: Will never create a folder $name without having write access.\nYou have set open(create), but only want to read the folder. Create is only useful for\nfolders which have write or append access modes (see Mail::Box::new(access)).\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "This module is part of Mail-Box distribution version 3.009, built on August 18, 2020. Website:\nhttp://perl.overmeer.net/CPAN/\n",
                "subsections": []
            },
            "LICENSE": {
                "content": "Copyrights 2001-2020 by [Mark Overmeer]. For other contributors see ChangeLog.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself. See http://dev.perl.org/licenses/\n",
                "subsections": []
            }
        }
    }
}