Mail::...aildir(3pm)

🌸 Mail::Box::Maildir 🌸

okay bestie, this is a page from the User Contributed Perl Documentation (yes, <italic>perl</italic> docs, iykyk) and it's about Mail::Box::Maildir β€” the thing that deals with Maildir folders. It's part 1 of 2, so buckle up, we are NOT done yet πŸ’…


✨ NAME ✨

Mail::Box::Maildir β€” handle Maildir folders πŸŽ€


🧬 INHERITANCE 🧬

so this class is the whole nepo baby of the Mail::Box universe, look at the family tree:

Mail::Box::Maildir
  is a Mail::Box::Dir
  is a Mail::Box
  is a Mail::Reporter

πŸ¦‹ SYNOPSIS πŸ¦‹

the little taste test, fr fr:

use Mail::Box::Maildir;
my $folder = Mail::Box::Maildir->new(folder => $ENV{MAIL}, ...);

πŸ’– DESCRIPTION πŸ’–

This doc spills all the tea on how Maildir mailboxes work, and everything you can do with the Maildir folder object Mail::Box::Maildir.

⚠️ Maildir is not supported for Windows, because it creates filenames that the Windows system literally will not accept. Not our fault, not their fault, it's just a whole situation 😭

Extends "DESCRIPTION" in Mail::Box::Dir.


πŸŽ€ OVERLOADED πŸŽ€

Extends "OVERLOADED" in Mail::Box::Dir.

  • overload: '""' stringification β€” Inherited, see "OVERLOADED" in Mail::Box
  • overload: '@{}' use as ARRAY β€” Inherited, see "OVERLOADED" in Mail::Box
  • overload: cmp string comparison β€” Inherited, see "OVERLOADED" in Mail::Box

πŸ› οΈ METHODS πŸ› οΈ

Extends "METHODS" in Mail::Box::Dir.

🌟 Constructors 🌟

Extends "Constructors" in Mail::Box::Dir.

$class->new(%options)

Inherited, see "Constructors" in Mail::Box

here's the big menu of everything you can pass, with where it comes from and what it defaults to:

 -Option           --Defined in     --Default
  accept_new                          false
  access             Mail::Box        'r'
  body_delayed_type  Mail::Box        Mail::Message::Body::Delayed
  body_type          Mail::Box        Mail::Message::Body::Lines
  coerce_options     Mail::Box        +[]
  create             Mail::Box        false
  directory          Mail::Box::Dir   <derived from folder name>
  extract            Mail::Box        10240
  field_type         Mail::Box        undef
  fix_headers        Mail::Box        false
  folder             Mail::Box        $ENV{MAIL}
  folderdir          Mail::Box        $ENV{HOME}/.maildir
  head_delayed_type  Mail::Box        Mail::Message::Head::Delayed
  head_type          Mail::Box        Mail::Message::Head::Complete
  keep_dups          Mail::Box        false
  lock_file          Mail::Box        <not used>
  lock_timeout       Mail::Box        <not used>
  lock_type          Mail::Box        'NONE' (constant)
  lock_wait          Mail::Box        <not used>
  locker             Mail::Box        undef
  manager            Mail::Box        undef
  message_type       Mail::Box        <folder-class>::Message
  multipart_type     Mail::Box        Mail::Message::Body::Multipart
  remove_when_empty  Mail::Box        true
  save_on_exit       Mail::Box        true
  trusted            Mail::Box        <depends on folder location>
  • accept_new => BOOLEAN β€” When the folder is open, some messages may be stored in the new sub-directory. By default, these messages are immediately moved to the cur directory when the folder is opened. Otherwise, you have to call acceptMessages() or Mail::Box::Maildir::Message::accept(). 🫢

and the rest of em, keepin it exact:

access => $mode
body_delayed_type => CLASS
body_type => CLASS|CODE
coerce_options => ARRAY
create => BOOLEAN
directory => $directory
extract => INTEGER|CODE|METHOD|'LAZY'|'ALWAYS'
field_type => $class
fix_headers => BOOLEAN
folder => $name
folderdir => $directory
head_delayed_type => $class
head_type => $class
keep_dups => BOOLEAN
lock_file => $file
lock_timeout => $seconds
lock_type => $class|$name|\@names
lock_wait => $seconds
locker => $locker
manager => $manager
message_type => $class
multipart_type => CLASS
remove_when_empty => BOOLEAN
save_on_exit => BOOLEAN
trusted => BOOLEAN

🧚 Attributes 🧚

Extends "Attributes" in Mail::Box::Dir.

  • $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->type() β€” Inherited, see "Attributes" in Mail::Box

πŸ“ The folder πŸ“

Extends "The folder" in Mail::Box::Dir.

  • $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
  • $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->directory() β€” Inherited, see "The folder" in Mail::Box::Dir
  • $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::Dir.

  • $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::Dir.

  • $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::Dir.

  • $any->listSubFolders(%options) β€” Inherited, see "Sub-folders" in Mail::Box
  • $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::Dir.

  • $obj->acceptMessages() β€” Accept all messages which are waiting in the new directory to be moved to the cur directory. This will not rescan the directory for newly arrived messages, because that's a task for update().
  • $class->appendMessage(%options)
  • $obj->coerce($message, %options) β€” Inherited, see "Internals" in Mail::Box

$any->create($foldername, %options)

[4.000] Returns the created directory. Improves base, see "Internals" in Mail::Box

 -Option   --Defined in--Default
  folderdir  Mail::Box   undef
  • folderdir => $directory

$any->createDirs($folderdir)

The $folderdir contains the absolute path of the location where the messages are kept. Maildir folders contain a tmp, new, and cur sub-directory within that folder directory as well. This method will ensure that all directories exist. Returns false on failure. πŸ’€

  • $obj->determineBodyType($message, $head) β€” Inherited, see "Internals" in Mail::Box

$any->folderIsEmpty($folderdir)

Checks whether the folder whose directory is specified as absolute $folderdir is empty or not. A folder is empty when the tmp, new, and cur subdirectories are empty and some files which are left there by application programs. The maildir spec explicitly states: .qmail, bulletintime, bulletinlock and seriallock. If any other files are found, the directory is considered not-empty. wild, i know 🫠

  • $obj->folderToDirectory($foldername, $folderdir) β€” Inherited, see "Internals" in Mail::Box::Dir
  • $class->foundIn( [$foldername], %options ) β€” Inherited, see "Internals" in Mail::Box
  • $obj->lineSeparator( [<STRING|'CR'|'LF'|'CRLF'>] ) β€” Inherited, see "Internals" in Mail::Box
  • $obj->locker() β€” Inherited, see "Internals" in Mail::Box
  • $obj->messageInFile($filename) β€” Inherited, see "Internals" in Mail::Box::Dir
  • $obj->read(%options) β€” Inherited, see "Internals" in Mail::Box
  • $obj->readMessageFilenames($directory) β€” Inherited, see "Internals" in Mail::Box::Dir
  • $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
  • $obj->write(%options) β€” Inherited, see "Internals" in Mail::Box

$obj->writeMessages()

Inherited, see "Internals" in Mail::Box

 -Option  --Defined in--Default
  messages  Mail::Box   <required>
  • messages => ARRAY

πŸ“ Other methods πŸ“

Extends "Other methods" in Mail::Box::Dir.

  • $any->timespan2seconds($time) β€” Inherited, see "Other methods" in Mail::Box

🚨 Error handling 🚨

Extends "Error handling" in Mail::Box::Dir.

  • $obj->AUTOLOAD() β€” Inherited, see "Error handling" in Mail::Reporter
  • $obj->notImplemented() β€” Inherited, see "Error handling" in Mail::Reporter

🧹 Cleanup 🧹

Extends "Cleanup" in Mail::Box::Dir.

  • $obj->DESTROY() β€” Inherited, see "Cleanup" in Mail::Box

πŸ’– DETAILS πŸ’–

okay so the explanation is complicated β€” but for normal use you should bother yourself with all the details, bestie. iykyk. πŸ’…

Extends "DETAILS" in Mail::Box::Dir.

✨ Different kinds of folders ✨

Extends "Different kinds of folders" in Mail::Box::Dir.

✨ Available folder types ✨

Extends "Available folder types" in Mail::Box::Dir.

✨ Folder class implementation ✨

Extends "Folder class implementation" in Mail::Box::Dir.

πŸ’Œ How MAILDIR folders work πŸ’Œ

Maildir-type folders use a directory to store the messages of one folder. each single message is stored in a separate file. and honestly? that seems useful, because changes in a folder change only a few of these small files β€” in contrast with file-based folders where changes in a folder cause rewrites of huge folder-files. no cap, that's the whole glow-up. ✨

However β€” and this is the part that's giving "it depends" energy β€” Maildir based folders perform very bad if you need header information of all messages. for instance, if you want to have full knowledge about all message-threads (see Mail::Box::Thread::Manager) in the folder, it requires reading all header lines in all message files. and usually, reading your messages as threads is desired. 😭 Maildir maintains a tiny amount of info visible in the filename, which may make it perform just a little bit faster than MH. that's it. that's the tradeoff. πŸ’€


🚨 DIAGNOSTICS 🚨

vibe check time β€” here's everything that can go wrong and exactly why. read it, bestie.

  • Error: Cannot append Maildir message in $new to folder $self. β€” the message (or messages) could not be stored in the right directories for the Maildir folder. Cast by appendMessage()
  • Error: Cannot create Maildir message file $new. β€” a message is converted from some other message format into a Maildir format by writing it to a file with a name which contains the status flags of the message. apparently, creating this file failed. Cast by coerce()
  • Fault: Cannot create directory $dir: $! β€” Cast by appendMessage()
  • Error: Folder $name is opened read-only β€” you can not write to this folder unless you have opened the folder to write or append with new(access), or the "force" option is set "true". Cast by write()
  • Fault: cannot create Maildir directory $dir: $! β€” a Maildir folder is represented by a directory, with some sub-directories. the top folder directory could not be created for the reason indicated. Cast by createDirs()
  • Fault: cannot create Maildir subdir $dir: $! β€” each Maildir folder has three sub-directories for administration: "new", "tmp", and "cur". the mentioned directory could not be created for the indicated reason. Cast by createDirs()
  • Fault: cannot create directory $dir: $! β€” Cast by writeMessages()
  • Fault: cannot create file $file: $! β€” Cast by writeMessages()
  • Fault: cannot rename $from to $to: $! β€” Cast by writeMessages()
  • Warning: changes not written to read-only folder $name. β€” you have opened the folder read-only (which is the default set by new(access) 😌), made modifications, and now want to close it. set close(force) if you want to overrule the access mode, or close the folder with close(write) set to "NEVER". Cast by close()
  • 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 by notImplemented()
  • 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 by copyTo()
  • Error: destination folder $name is not writable. β€” the folder where the messages are copied to is not opened with write access (see new(access)). this has no relation with write permission to the folder which is controlled by your operating system. two completely different things, bestie. Cast by copyTo()
  • 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 by messageId()
  • Warning: folder $name not deleted: not writable. β€” the folder must be opened with write access via new(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 by delete()
  • Error: invalid timespan '$span'. β€” the string does not follow the strict rules of the time span syntax which is permitted as parameter. Cast by timespan2seconds()
  • 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 by messageId()
  • Error: no locking possible for maildir folders. β€” Cast by new()
  • Error: unknown value to folder->close(write => $when). β€” Cast by close()
  • Error: you cannot add a message which is already part of a folder to a new one. Please use moveTo or copyTo. β€” Cast by addMessage()

πŸ‘€ 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. slay πŸ’…


okay that's the whole page, bestie, you made it to the end 🫢 this one came from perl v5.40.1, dated 2026-05-09, and it's the Mail::...aildir(3pm) manual β€” go forth and sort your mail, you absolute icon πŸ’–βœ¨

πŸ“¦ where this page comes from