Mail::Box::Mbox(3pm)
π Mail::Box::Mbox π
okay bestie, welcome to the glow-up of Mail::Box::Mbox(3pm) β the manual page for handling folders in Mbox format. this is the User Contributed Perl Documentation version, and we're about to make it make sense. no cap. π
πΈ NAME πΈ
Mail::Box::Mbox - handle folders in Mbox format β¨
this is literally the whole point of the module, and yes it's serving exactly what it says on the tin. π
π¦ INHERITANCE π¦
the family tree goes like this, and yes it's giving royal lineage π:
Mail::Box::Mbox
is a Mail::Box::File
is a Mail::Box
is a Mail::Reporter
so like, everything Mail::Box::File, Mail::Box, and Mail::Reporter can do? it's inherited. main character energy by bloodline fr fr. π«Ά
β¨ SYNOPSIS β¨
here's the vibe check β how you actually summon this thing into existence:
use Mail::Box::Mbox;
my $folder = Mail::Box::Mbox->new(folder => $ENV{MAIL}, ...);
that ... at the end? that's you, bestie, filling in the rest of your options. we love a flexible icon. π
π DESCRIPTION π
so this page does two things, and it does both flawlessly:
- it describes how Mbox mailboxes work, like the actual mechanics of the format β the way that mbox just is, iykyk
- it describes what you can actually do with the Mbox folder object
Mail::Box::Mboxβ all the moves you can pull π
Extends "DESCRIPTION" in Mail::Box::File. π₯
(translation: there's a whole other description living in Mail::Box::File and this one builds on top of it, so if you want the full lore you go read that one too. homework but make it β¨loreβ¨.)
π OVERLOADED π
Extends "OVERLOADED" in Mail::Box::File.
these are the operators this object plays pretend with, aka its decorated alter egos. each one is inherited, so for the full tea you gotta check Mail::Box:
overload: '""'β stringification β it can act like a string when you quote it π¬ Inherited, see "OVERLOADED" in Mail::Boxoverload: '@{}'β use as ARRAY β it can act like an array when you dereference it π Inherited, see "OVERLOADED" in Mail::Boxoverload: cmpβ string comparison β it can be compared like a string withcmpβοΈ Inherited, see "OVERLOADED" in Mail::Box
that's the trio right there, and honestly? they ate. π
π METHODS π
Extends "METHODS" in Mail::Box::File.
π Constructors π
Extends "Constructors" in Mail::Box::File.
$class->new(%options)
Inherited bestie, see "Constructors" in Mail::Box. β¨
Here's the whole option table, no skips, no cap:
-Option --Defined in --Default
access Mail::Box 'r'
body_delayed_type Mail::Box Mail::Message::Body::Delayed
body_type Mail::Box::File <see description>
coerce_options Mail::Box +[]
create Mail::Box false
extract Mail::Box 10240
field_type Mail::Box undef
fix_headers Mail::Box false
folder Mail::Box $ENV{MAIL}
folderdir Mail::Box $ENV{HOME}.'/Mail'
head_delayed_type Mail::Box Mail::Message::Head::Delayed
head_type Mail::Box Mail::Message::Head::Complete
keep_dups Mail::Box false
lock_extension Mail::Box::File '.lock'
lock_file Mail::Box <foldername><lock-extension>
lock_timeout Mail::Box 1 hour
lock_type Mail::Box Mail::Box::Locker::DotLock
lock_wait Mail::Box 10 seconds
locker Mail::Box undef
manager Mail::Box undef
message_type Mail::Box Mail::Box::Mbox::Message
multipart_type Mail::Box Mail::Message::Body::Multipart
remove_when_empty Mail::Box true
save_on_exit Mail::Box true
subfolder_extension '.d'
trusted Mail::Box <depends on folder location>
write_policy Mail::Box::File undef
Now the option-by-option breakdown, one at a time, because we do NOT skip π :
access => $modebody_delayed_type => CLASSbody_type => CLASS|CODEcoerce_options => ARRAYcreate => BOOLEANextract => INTEGER|CODE|METHOD|'LAZY'|'ALWAYS'field_type => $classfix_headers => BOOLEANfolder => $namefolderdir => $directoryhead_delayed_type => $classhead_type => $classkeep_dups => BOOLEANlock_extension => $file|STRINGlock_file => $filelock_timeout => $secondslock_type => $class|$name|\@nameslock_wait => $secondslocker => $lockermanager => $managermessage_type => $classmultipart_type => CLASSremove_when_empty => BOOLEANsave_on_exit => BOOLEANsubfolder_extension => STRINGβ okay so mbox folders genuinely do not support sub-folders, like at all. BUT bestie, this module can simulate sub-directories if the user wants it to. So when a subfolder of folder"xyz"gets created, we make a directory called"xyz.d"to hold them all. That".d"extension? Changeable with this option. π¦trusted => BOOLEANwrite_policy => 'REPLACE'|'INPLACE'|undef
π Attributes π
Extends "Attributes" in Mail::Box::File.
$obj->filename()
Inherited, see "Attributes" in Mail::Box::File.
$obj->fixHeaders()
Inherited, see "Attributes" in Mail::Box.
$obj->folderdir( [$directory] )
Inherited, see "Attributes" in Mail::Box.
$obj->isTrusted()
Inherited, see "Attributes" in Mail::Box.
$obj->name()
Inherited, see "Attributes" in Mail::Box.
$obj->removeEmpty()
Inherited, see "Attributes" in Mail::Box.
$obj->subfolderExtension()
(no extra notes on this one, it just vibes πΈ)
$obj->type()
Inherited, see "Attributes" in Mail::Box.
π The folder π
Extends "The folder" in Mail::Box::File.
$obj->addMessage($message, %options)
Inherited, see "The folder" in Mail::Box.
$obj->addMessages(@messages)
Inherited, see "The folder" in Mail::Box.
$class->appendMessages(%options)
Inherited, see "The folder" in Mail::Box::File.
$obj->close(%options)
Inherited, see "The folder" in Mail::Box.
$obj->copyTo($folder, %options)
Inherited, see "The folder" in Mail::Box.
$obj->delete(%options)
Inherited, see "The folder" in Mail::Box.
$obj->organization()
Inherited, see "The folder" in Mail::Box.
$obj->size()
Inherited, see "The folder" in Mail::Box.
$obj->update(%options)
Inherited, see "The folder" in Mail::Box.
$obj->url()
Inherited, see "The folder" in Mail::Box.
π Folder flags π
Extends "Folder flags" in Mail::Box::File.
$obj->access()
Inherited, see "Folder flags" in Mail::Box.
$obj->isModified()
Inherited, see "Folder flags" in Mail::Box.
$obj->modified( [BOOLEAN] )
Inherited, see "Folder flags" in Mail::Box.
$obj->writable()
Inherited, see "Folder flags" in Mail::Box.
π The messages π
Extends "The messages" in Mail::Box::File.
$obj->current( [$number|$message|$message_id] )
Inherited, see "The messages" in Mail::Box.
$obj->find($message_id)
Inherited, see "The messages" in Mail::Box.
$obj->findFirstLabeled( $label, [BOOLEAN, [\@msgs]] )
Inherited, see "The messages" in Mail::Box.
$obj->message( $index, [$message] )
Inherited, see "The messages" in Mail::Box.
$obj->messageId( $message_id, [$message] )
Inherited, see "The messages" in Mail::Box.
$obj->messageIds()
Inherited, see "The messages" in Mail::Box.
$obj->messages( <'ALL'|$range|'ACTIVE'|'DELETED'|$label|!$label|$filter> )
Inherited, see "The messages" in Mail::Box.
$obj->nrMessages(%options)
Inherited, see "The messages" in Mail::Box.
$obj->scanForMessages($message, $message_ids, $timespan, $window)
Inherited, see "The messages" in Mail::Box.
π§ Sub-folders π§
Extends "Sub-folders" in Mail::Box::File.
$any->listSubFolders(%options)
Inherited, see "Sub-folders" in Mail::Box.
The option table, in full:
-Option --Defined in --Default
check Mail::Box false
folder Mail::Box <from calling object>
folderdir Mail::Box <from folder>
skip_empty Mail::Box false
subfolder_extension <from object>
check => BOOLEANfolder => $namefolderdir => $dirskip_empty => BOOLsubfolder_extension => STRINGβ when you call this method on an open folder, the extension defined by that folder is what's used to detect sub-folders by default. Otherwise?'.d'gets taken. simple as that π«Ά
$any->nameOfSubFolder( $subname, [$parentname] )
Inherited, see "Sub-folders" in Mail::Box.
$obj->openRelatedFolder(%options)
Inherited, see "Sub-folders" in Mail::Box.
$obj->openSubFolder($subname, %options)
Inherited, see "Sub-folders" in Mail::Box.
$any->topFolderWithMessages()
Inherited, see "Sub-folders" in Mail::Box.
π₯ Internals π₯
Extends "Internals" in Mail::Box::File.
$obj->coerce($message, %options)
Inherited, see "Internals" in Mail::Box.
$any->create($foldername, %options)
Inherited, see "Internals" in Mail::Box.
-Option --Defined in --Default
folderdir Mail::Box undef
subfolder_extension undef
folderdir => $directorysubfolder_extension => STRINGβ if a directory gets found at the location of the folder you're trying to create, this STRING is used to extend that directory name with. That makes the directory get seen as a sub-folder for the created folder. And where does this argument go? Straight tofolderToFilename(). π
$obj->determineBodyType($message, $head)
Inherited, see "Internals" in Mail::Box.
$any->folderToFilename( $foldername, $folderdir, [$extension] )
Okay so this one translates a folder name into a filename, using the $folderdir value to replace a leading "=". If no $extension is specified and this method is called as an instance method, then new(subfolder_extension) is used. Otherwise, the extension defaults to ".d". Improves base, see "Internals" in Mail::Box::File. β¨
$class->foundIn( [$foldername], %options )
If no $foldername is given, then the value of the "folder" option gets taken instead. Now, what even is an mbox folder? It's a file which starts with a separator line β a line with "From " as its first characters. Blank lines that start the file get ignored, which is not acceptable to all MUA's, jsyk π. Improves base, see "Internals" in Mail::Box.
-Option --Defined in --Default
folder undef
folderdir Mail::Box undef
subfolder_extension <from object>
folder => $namefolderdir => $directorysubfolder_extension => STRING
$obj->lineSeparator( [<STRING|'CR'|'LF'|'CRLF'>] )
Inherited, see "Internals" in Mail::Box.
$obj->locker()
Inherited, see "Internals" in Mail::Box.
$obj->messageCreateOptions( [$type, $config] )
Inherited, see "Internals" in Mail::Box::File.
$obj->moveAwaySubFolder($directory, $extension)
Inherited, see "Internals" in Mail::Box::File.
$obj->parser()
Inherited, see "Internals" in Mail::Box::File.
$obj->read(%options)
Inherited, see "Internals" in Mail::Box.
$obj->readMessages(%options)
Inherited, see "Internals" in Mail::Box.
$obj->storeMessage($message)
Inherited, see "Internals" in Mail::Box.
$obj->toBeThreaded($messages)
Inherited, see "Internals" in Mail::Box.
$obj->toBeUnthreaded($messages)
Inherited, see "Internals" in Mail::Box.
$obj->updateMessages(%options)
Inherited, see "Internals" in Mail::Box::File.
$obj->write(%options)
Inherited, see "Internals" in Mail::Box::File.
$obj->writeMessages(%options)
Inherited, see "Internals" in Mail::Box.
πΈ Other methods πΈ
Extends "Other methods" in Mail::Box::File.
$any->timespan2seconds($time)
Inherited, see "Other methods" in Mail::Box.
π Error handling π
Extends "Error handling" in Mail::Box::File.
$obj->AUTOLOAD()
Inherited, see "Error handling" in Mail::Reporter.
$obj->notImplemented()
Inherited, see "Error handling" in Mail::Reporter.
π Cleanup π
Extends "Cleanup" in Mail::Box::File.
$obj->DESTROY()
Inherited, see "Cleanup" in Mail::Box.
πΈ Extends "DETAILS" in Mail::Box::File. πΈ
this part is literally just vibes-inherited from Mail::Box::File β go read that one too, bestie, no cap π
ποΈ Different kinds of folders ποΈ
Extends "Different kinds of folders" in Mail::Box::File.
β¨ Available folder types β¨
Extends "Available folder types" in Mail::Box::File.
π«Ά Folder class implementation π«Ά
Extends "Folder class implementation" in Mail::Box::File.
π File based folders π
Extends "File based folders" in Mail::Box::File.
π How MBOX folders work π
so like. MBOX folders are the β¨one-file-to-rule-them-allβ¨ situation: many messages live in one single file. Every message starts with a line that begins with the string "From ". And if a line inside a message happens to start with From by accident?? then in the file it gets a > stuck in front of it. That sneaky > character gets stripped off the moment the message is read back. π
ngl you also need to know: the format of MBOX files is not strictly defined. Like at all. The exact content of those separator lines is different between Mail User Agents (MUA's). π And on top of that, some MUAs (mutt, I'm looking at you π) straight-up forget to encode the "From " lines within message bodies, which breaks other parsers... yikes. π
πͺ Simulation of sub-folders πͺ
MBOX folders don't actually have a sub-folder concept the way directory based folders do, but this MBOX module is out here doing its best impression of one. π§ In this implementation, a directory like
Mail/subject1/
gets taken as an empty folder Mail/subject1, with all the folders inside that directory acting as its sub-folders. iconic behaviour honestly.
You may also use
Mail/subject1
Mail/subject1.d/
where Mail/subject1 is the folder, and the folders sitting in the Mail/subject1.d directory are used as sub-folders. π
And if your setup looks like the first example and you wanna put messages in that empty folder?? the directory gets automatically (and transparently) renamed so that the second situation is reached. slay, it just handles it for you. β¨
π¨ DIAGNOSTICS π¨
okay bestie, this is the drama section. buckle up. π
Error: cannot append messages to folder file $file: $!Appending messages to a not-opened file-organized folder may fail when the operating system does not allow write access to the file at hand. Cast byappendMessages().Fault: cannot move away sub-folder $dir: $!Cast bymoveAwaySubFolder().Warning: cannot remove folder $name file $filename: $!Writing an empty folder will usually cause that folder to be removed, which fails for the indicated reason.new(remove_when_empty)controls whether the empty folder will removed; setting it to"false"(0) may be needed to avoid this message. Cast bywrite().Fault: cannot replace $to by $from to update folder $name: $!The replace policy wrote a new folder file to update the existing, but was unable to give the final touch: replacing the old version of the folder file for the indicated reason. Cast bywrite().Warning: changes not written to read-only folder $name.You have opened the folder read-only --which is the default set bynew(access)--, made modifications, and now want to close it. Setclose(force)if you want to overrule the access mode, or close the folder withclose(write)set to"NEVER". Cast byclose().Error: class $package does not implement method $method.Fatal error: the specific$package(or one of its superclasses) does not implement this method where it should. This message means that some other related classes do implement this method however the class at hand does not. Probably you should investigate this and probably inform the author of the package. Cast bynotImplemented().Error: copying failed for one message.For some reason, for instance disk full, removed by external process, or read-protection, it is impossible to copy one of the messages. Copying will proceed for the other messages. Cast bycopyTo().Error: destination folder $name is not writable.The folder where the messages are copied to is not opened with write access (seenew(access)). This has no relation with write permission to the folder which is controlled by your operating system. Cast bycopyTo().Warning: different messages with id $msgid.The message id is discovered more than once within the same folder, but the content of the message seems to be different. This should not be possible: each message must be unique. Cast bymessageId().Error: file $name too short to get write message $msgnr ($size < $expect)Mail::Box is lazy: it tries to leave messages in the folders until they are used, which saves time and memory usage. When this message appears, something is terribly wrong: some lazy message are needed for updating the folder, but they cannot be retrieved from the original file anymore. In this case, messages can be lost.
This message does appear regularly on Windows systems when using the 'replace' write policy. Please help to find the cause, probably something to do with Windows incorrectly handling multiple filehandles open in the same file. Cast by write().
Warning: folder $name not deleted: not writable.The folder must be opened with write access vianew(access), otherwise removing it will be refused. So, you may have write-access according to the operating system, but that will not automatically mean that this"delete"method permits you to. The reverse remark is valid as well. Cast bydelete().Error: invalid timespan '$span'.The string does not follow the strict rules of the time span syntax which is permitted as parameter. Cast bytimespan2seconds().Warning: message-id '$msgid' does not contain a domain.According to the RFCs, message-ids need to contain a unique random part, then an"@", and then a domain name. This is made to avoid the creation of two messages with the same id. The warning emerges when the"@"is missing from the string. Cast bymessageId().Error: unable to update folder $name.When a folder is to be written, both replace and inplace write policies are tried, If both fail, the whole update fails. You may see other, related, error messages to indicate the real problem. Cast bywrite().Error: unknown value to folder->close(write => $when).Cast byclose().Error: you cannot add a message which is already part of a folder to a new one. Please use moveTo or copyTo.Cast byaddMessage().
π SEE ALSO π
This module is part of Mail-Box version 4.02, built on April 10, 2026. π
Website: http://perl.overmeer.net/CPAN/
π LICENSE π
For contributors see file ChangeLog.
This software is copyright (c) 2001-2026 by Mark Overmeer.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
okay and that's a wrap on Mail::Box::Mbox(3pm) π huge thanks to perl v5.40.1 for showing up on 2026-05-09 to make this page possible β you ate that, fr fr. now go fix your mbox files bestie, i believe in you πβ¨π¦
π¦ where this page comes from
- ubuntu stonking: libmail-box-perl 4.02-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms