Mail::...Message(3pm)

πŸ’– Mail::Box::IMAP4::Message πŸ’–

(that's the Mail::...Message(3pm) page bestie, we're in User Contributed Perl Documentation territory and it's giving Perl-core royalty)

✨ NAME ✨

Mail::Box::IMAP4::Message β€” one single message chilling on an IMAP4 server. Just one. One (1) message. That's the whole job. πŸ’…


🌸 INHERITANCE 🌸

Okay so this class is a nepo baby and I mean that lovingly, look at this family tree:

Mail::Box::IMAP4::Message
  is a Mail::Box::Net::Message
  is a Mail::Box::Message
  is a Mail::Message
  is a Mail::Reporter

Every single one of those ancestors is that girl and Mail::Box::IMAP4::Message is inheriting the whole wardrobe. πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

The vibe is literally just:

my $folder = new Mail::Box::IMAP4 ...
my $message = $folder->message(10);

You make a folder, you grab message number 10, and boom β€” you have yourself a Mail::Box::IMAP4::Message. No notes. πŸ¦‹


πŸ’œ DESCRIPTION πŸ’œ

A Mail::Box::IMAP4::Message represents exactly one message on a IMAP4 server, and it's maintained by a Mail::Box::IMAP4 folder. Each message lives as its own separate entity on the server, and maybe it's also hanging out temporarily inside your program too, depending on how nosy you're being. πŸ‘€

Extends "DESCRIPTION" in Mail::Box::Net::Message.


πŸ”₯ METHODS πŸ”₯

Extends "METHODS" in Mail::Box::Net::Message.

🧸 Constructors 🧸

Extends "Constructors" in Mail::Box::Net::Message.

  • $obj->clone(%options) β€” inherited, so go peep "Constructors" in Mail::Message
  • $class->new(%options) β€” inherited, so go peep "Constructors" in Mail::Reporter

So new takes a whole wardrobe of options, and here's the full list with where each one comes from and what it defaults to (don't skip the middle, bestie, the defaults matter):

  • body β€” defined in Mail::Message, default undef
  • body_type β€” defined in Mail::Box::Message, default Mail::Message::Body::Lines
  • cache_body β€” default false
  • cache_head β€” default false
  • cache_labels β€” default false
  • deleted β€” defined in Mail::Message, default false
  • field_type β€” defined in Mail::Message, default undef
  • folder β€” defined in Mail::Box::Message, default <required> (yes bestie, it's mandatory, you cannot skip it)
  • head β€” defined in Mail::Message, default undef
  • head_type β€” defined in Mail::Message, default Mail::Message::Head::Complete
  • labels β€” defined in Mail::Message, default +{}
  • messageId β€” defined in Mail::Message, default undef
  • modified β€” defined in Mail::Message, default false
  • size β€” defined in Mail::Box::Message, default undef
  • trusted β€” defined in Mail::Message, default false
  • unique β€” defined in Mail::Box::Net::Message, default <unique string>
  • write_labels β€” default true

Now the breakdown, one by one, no skipping:

  • body => $object β€” hand over the body object directly, periodt.
  • body_type => CODE|$class β€” the class (or a bit of CODE) that gets used to build the body.
  • cache_body => BOOLEAN β€” cache the body, yay or nay.
  • cache_head => BOOLEAN β€” cache the head, yay or nay.
  • cache_labels => BOOLEAN β€” okay so all standard IMAP labels can be cached on the local server to make things go faster. πŸƒβ€β™€οΈπŸ’¨ But heads up: this carries the exact same dangers as setting "write_labels" to "false". The caching kicks in when the first label of the message gets read.
  • deleted => BOOLEAN β€” is it deleted or not.
  • field_type => $class β€” which class handles fields.
  • folder => $folder β€” the folder it belongs to. Required, no exceptions. 🫢
  • head => $object β€” hand over the head object directly.
  • head_type => $class β€” which class the head should be.
  • labels => \@pairs|\%settings β€” labels as a list of pairs or a hash of settings.
  • messageId => $id β€” the message id.
  • modified => BOOLEAN β€” has it been touched or not.
  • size => $bytes β€” the size, in bytes.
  • trusted => BOOLEAN β€” do we trust it.
  • unique => STRING β€” the unique string identifier.
  • write_labels => BOOLEAN β€” so here's the tea β˜•: when a label is changed, or its value is read, using label(), that info should get sent to the IMAP server. But β€” and this is the drama β€” the action could be superfluous, like if the label was already set or clear, and communication is expensive, okay?? On the other hand: someone else might be using IMAP to make changes in the same folder, and then they'll get the updates too late, or *never*… 😭

🌈 Attributes 🌈

Extends "Attributes" in Mail::Box::Net::Message.

  • $obj->folder( [$folder] ) β€” inherited, see "Attributes" in Mail::Box::Message
  • $obj->seqnr( [$integer] ) β€” inherited, see "Attributes" in Mail::Box::Message
  • $obj->unique( [STRING|undef] ) β€” inherited, see "Attributes" in Mail::Box::Net::Message

πŸŽ€ Constructing a message πŸŽ€

Extends "Constructing a message" in Mail::Box::Net::Message.

  • $obj->bounce( [<$rg_object|%options>] ) β€” inherited, see "Constructing a message" in Mail::Message::Construct::Bounce
  • $class->build( [$message|$part|$body], @fields, %options ) β€” inherited, see "Constructing a message" in Mail::Message::Construct::Build
  • $class->buildFromBody($body, [$head], $headers) β€” inherited, see "Constructing a message" in Mail::Message::Construct::Build
  • $obj->forward(%options) β€” inherited, see "Constructing a message" in Mail::Message::Construct::Forward
  • $obj->forwardAttach(%options) β€” inherited, see "Constructing a message" in Mail::Message::Construct::Forward
  • $obj->forwardEncapsulate(%options) β€” inherited, see "Constructing a message" in Mail::Message::Construct::Forward
  • $obj->forwardInline(%options) β€” inherited, see "Constructing a message" in Mail::Message::Construct::Forward
  • $obj->forwardNo(%options) β€” inherited, see "Constructing a message" in Mail::Message::Construct::Forward
  • $obj->forwardPostlude() β€” inherited, see "Constructing a message" in Mail::Message::Construct::Forward
  • $obj->forwardPrelude() β€” inherited, see "Constructing a message" in Mail::Message::Construct::Forward
  • $obj->forwardSubject(STRING) β€” inherited, see "Constructing a message" in Mail::Message::Construct::Forward
  • $class->read($fh|$text|\$text|\@lines, %options) β€” inherited, see "Constructing a message" in Mail::Message::Construct::Read
  • $obj->rebuild(%options) β€” inherited, see "Constructing a message" in Mail::Message::Construct::Rebuild
  • $obj->reply(%options) β€” inherited, see "Constructing a message" in Mail::Message::Construct::Reply
  • $obj->replyPrelude( [STRING|$field|$address|\@addrs|\@fields] ) β€” inherited, see "Constructing a message" in Mail::Message::Construct::Reply
  • $any->replySubject(STRING) β€” inherited, see "Constructing a message" in Mail::Message::Construct::Reply

πŸ’Œ The message πŸ’Œ

Extends "The message" in Mail::Box::Net::Message.

  • $obj->container() β€” inherited, see "The message" in Mail::Message
  • $obj->copyTo($folder, %options) β€” inherited, see "The message" in Mail::Box::Message
  • $obj->endsOnNewline() β€” inherited, see "The message" in Mail::Message
  • $obj->isDummy() β€” inherited, see "The message" in Mail::Message
  • $obj->isPart() β€” inherited, see "The message" in Mail::Message
  • $obj->messageId() β€” inherited, see "The message" in Mail::Message
  • $obj->moveTo($folder, %options) β€” inherited, see "The message" in Mail::Box::Message
  • $obj->partNumber() β€” inherited, see "The message" in Mail::Message
  • $obj->print( [$fh] ) β€” inherited, see "The message" in Mail::Message
  • $obj->send( [$mailer], %options ) β€” inherited, see "The message" in Mail::Message
  • $obj->size() β€” returns the size of this message. If the message is still on the remote server, IMAP gets used to ask for the size. But when the message is already loaded onto the local system, the size of the parsed message is taken instead. Ngl these two sizes can differ, because of the difference in line-ending representation. πŸ‘€ Improves base, see "The message" in Mail::Message
  • $obj->toplevel() β€” inherited, see "The message" in Mail::Message
  • $obj->write( [$fh] ) β€” inherited, see "The message" in Mail::Message

🌸 The header 🌸

Extends "The header" in Mail::Box::Net::Message.

  • $obj->bcc() β€” inherited, see "The header" in Mail::Message
  • $obj->cc() β€” inherited, see "The header" in Mail::Message
  • $obj->date() β€” inherited, see "The header" in Mail::Message
  • $obj->destinations() β€” inherited, see "The header" in Mail::Message
  • $obj->from() β€” inherited, see "The header" in Mail::Message
  • $obj->get($fieldname) β€” inherited, see "The header" in Mail::Message
  • $obj->guessTimestamp() β€” inherited, see "The header" in Mail::Message
  • $obj->head( [$head] ) β€” inherited, see "The header" in Mail::Message
  • $obj->nrLines() β€” inherited, see "The header" in Mail::Message
  • $obj->sender() β€” inherited, see "The header" in Mail::Message
  • $obj->study($fieldname) β€” inherited, see "The header" in Mail::Message
  • $obj->subject() β€” inherited, see "The header" in Mail::Message
  • $obj->timestamp() β€” inherited, see "The header" in Mail::Message
  • $obj->to() β€” inherited, see "The header" in Mail::Message

πŸ¦‹ The body πŸ¦‹

Extends "The body" in Mail::Box::Net::Message.

  • $obj->body( [$body] ) β€” inherited, see "The body" in Mail::Message
  • $obj->contentType() β€” inherited, see "The body" in Mail::Message
  • $obj->decoded(%options) β€” inherited, see "The body" in Mail::Message
  • $obj->encode(%options) β€” inherited, see "The body" in Mail::Message
  • $obj->isMultipart() β€” inherited, see "The body" in Mail::Message
  • $obj->isNested() β€” inherited, see "The body" in Mail::Message
  • $obj->parts( [<'ALL'|'ACTIVE'|'DELETED'|'RECURSE'|$filter>] ) β€” inherited, see "The body" in Mail::Message

⭐ Flags ⭐

Extends "Flags" in Mail::Box::Net::Message.

  • $obj->delete() β€” inherited, see "Flags" in Mail::Message
  • $obj->deleted( [BOOLEAN] ) β€” inherited, see "Flags" in Mail::Message
  • $obj->isDeleted() β€” inherited, see "Flags" in Mail::Message
  • $obj->isModified() β€” inherited, see "Flags" in Mail::Message
  • $obj->label($label|PAIRS) β€” with only one argument, the value related to $label gets returned. With more than one argument, the list gets interpreted as a label-value "PAIRS" to be set. The IMAP protocol defines its own names for the labels, which must be set immediately to inform other IMAP clients which may have the same folder open. But that can be changed with new(write_labels). Some labels are translated to the corresponding IMAP system labels. Improves base, see "Flags" in Mail::Message
  • $obj->labels() β€” gets the names of all labels (LIST context, and ngl that's not efficient in IMAP4), or a reference to a hash with labels. You should only use the returned hash to read the labels, because changes made to it will not be passed to the remote server. See labels() to set values. Improves base, see "Flags" in Mail::Message
  • $obj->labelsToStatus() β€” inherited, see "Flags" in Mail::Message
  • $obj->modified( [BOOLEAN] ) β€” inherited, see "Flags" in Mail::Message
  • $obj->statusToLabels() β€” inherited, see "Flags" in Mail::Message

πŸ’œ The whole message as text πŸ’œ

Extends "The whole message as text" in Mail::Box::Net::Message.

  • $obj->file() β€” inherited, see "The whole message as text" in Mail::Message::Construct::Text
  • $obj->lines() β€” inherited, see "The whole message as text" in Mail::Message::Construct::Text
  • $obj->printStructure( [$fh|undef],[$indent] ) β€” inherited, see "The whole message as text" in Mail::Message::Construct::Text
  • $obj->string() β€” inherited, see "The whole message as text" in Mail::Message::Construct::Text

🧚 Internals 🧚

Extends "Internals" in Mail::Box::Net::Message.

  • $obj->clonedFrom() β€” inherited, see "Internals" in Mail::Message

okay bestie that's the whole rest of the page so far… and there's more coming πŸ‘€βœ¨

  • $class->coerce($message, %options) β€” inherited, so peek at "Internals" in Mail::Message for the tea β˜•
  • $obj->diskDelete() β€” inherited, see "Internals" in Mail::Box::Message
  • $obj->fetch( [$info, ...] ) β€” bestie, this one hits the IMAP server with the UID FETCH IMAP command to pull data about this message. The $info request gets handed off to Mail::Box::IMAP4::fetch(). Hand it no $info at all and it grabs ALL the info and hands it back to you as a HASH. πŸ’…
  • $obj->isDelayed() β€” inherited, see "Internals" in Mail::Message
  • $obj->loadBody() β€” inherited, see "Internals" in Mail::Box::Net::Message
  • $obj->readBody( $parser, $head, [$bodytype] ) β€” inherited, see "Internals" in Mail::Box::Message
  • $obj->readFromParser( $parser, [$bodytype] ) β€” inherited, see "Internals" in Mail::Message
  • $obj->readHead( $parser, [$class] ) β€” inherited, see "Internals" in Mail::Message
  • $obj->recursiveRebuildPart($part, %options) β€” inherited, see "Internals" in Mail::Message::Construct::Rebuild
  • $obj->storeBody($body) β€” inherited, see "Internals" in Mail::Message
  • $obj->takeMessageId( [STRING] ) β€” inherited, see "Internals" in Mail::Message
  • $obj->writeDelayed($imap) β€” this is the one that pushes all the delayed info (label changes and all that) up to the server. It happens under force, so it'll go through even for folders that were opened without write-access. You don't usually call this yourself β€” a Mail::Box::write() or Mail::Box::close() calls it behind the scenes. 🌸

The $imap argument is a Mail::IMAPClient that already has the right folder selected. πŸ”₯

Writing changes back to the remote folder? Not exactly a smooth ride, ngl: IMAP4 (or is it just that Mail::IMAPClient doesn't support replacing a header or body). So when either of those changes, the whole message gets rewritten to the server (which is supported), and the original gets flagged for deletion. 😭

πŸ’– Error handling πŸ’–

Extends "Error handling" in Mail::Box::Net::Message.

  • $obj->AUTOLOAD() β€” inherited, see "METHODS" in Mail::Message::Construct
  • $obj->notImplemented() β€” inherited, see "Error handling" in Mail::Reporter
  • $any->shortSize( [$value] ) β€” inherited, see "Error handling" in Mail::Message
  • $obj->shortString() β€” inherited, see "Error handling" in Mail::Message

🧹 Cleanup 🧹

Extends "Cleanup" in Mail::Box::Net::Message.

  • $obj->DESTROY() β€” inherited, see "Cleanup" in Mail::Reporter
  • $obj->destruct() β€” inherited, see "Cleanup" in Mail::Box::Message

✨ DETAILS ✨

Extends "DETAILS" in Mail::Box::Net::Message.

🌈 Structure of a Message 🌈

Extends "Structure of a Message" in Mail::Box::Net::Message.

🌈 Message object implementation 🌈

Extends "Message object implementation" in Mail::Box::Net::Message.

🌈 Message class implementation 🌈

Extends "Message class implementation" in Mail::Box::Net::Message.

🏷️ Labels 🏷️

Extends "Labels" in Mail::Box::Net::Message.

⭐ Predefined labels ⭐

Extends "Predefined labels" in Mail::Box::Net::Message.

⭐ Status and X-Status fields ⭐

Extends "Status and X-Status fields" in Mail::Box::Net::Message.

⭐ IMAP protocol flags ⭐

Okay so labels (aka flags) are a thing in every folder format β€” they just get stored differently. Some folder types tuck them into message header lines, others keep them in a whole separate file. The IMAP protocol doesn't say anything about how labels are stored on the server, but it does say how they're named. πŸ’…

So the label names the IMAP protocol defines get standardized into the MailBox standard, which hides all those folder-format differences from you. These translations always happen, every time:

\Seen     => seen
\Answered => replied
\Flagged  => flagged
\Deleted  => deleted
\Draft    => draft
\Recent   => NOT old

Β» Example: of label translations πŸ‘‘

$imap->message(3)->label(replied => 1, draft => 0);

will result in a IMAP protocol statements like

A003 STORE 4 +FLAGS (\Answered)
A003 STORE 4 -FLAGS (\Draft)

⭐ Other labels ⭐

Obviously your program might need more labels than the protocol hands you, bestie. You can absolutely still use them: they stay locally (and yeah, they're gone the moment the folder is closed 🫠). Some IMAP4 extensions allow more labels than the basic RFC, but that is not yet supported by this implementation.

⭐ Caching labels ⭐

If you're asking for one or more flags of a message more than once, you can boost overall performance by setting new(cache_labels) to "YES". ⚑ But heads up β€” this may cause inconsistencies when multiple clients use the same folder on the IMAP server. πŸ’€

You can also delay the label updates to the server until the folder is closed (or for ever when read-only is required). When Mail::Box::write() or Mail::Box::close() is called, it is decided whether to throw all changes away or write after all.


🚨 DIAGNOSTICS 🚨

  • Error: Cannot include forward source as $kind. β€” Unknown alternative for the forward(include). Valid choices are "NO", "INLINE", "ATTACH", and "ENCAPSULATE". Cast by forward()
  • Error: No default mailer found to send message. β€” The message send() mechanism had not enough information to automatically find a mail transfer agent to sent this message. Specify a mailer explicitly using the "via" options. Cast by send()
  • Error: cannot coerce a $type object into a $me object. β€” Cast by coerce()
  • Error: cannot include reply source as $kind. β€” Unknown alternative for the "include" option of reply(). Valid choices are "NO", "INLINE", and "ATTACH". Cast by reply()
  • Error: cannot read message from a $source}. β€” Cast by read()
  • 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: coercion starts with some object, not '$type'. β€” Cast by coerce()
  • Error: method bounce requires To, Cc, or Bcc. β€” The message bounce() method forwards a received message off to someone else without modification; you must specified it's new destination. If you have the urge not to specify any destination, you probably are looking for reply(). When you wish to modify the content, use forward(). Cast by bounce()
  • Error: method forwardAttach requires a preamble. β€” Cast by forwardAttach()
  • Error: method forwardEncapsulate requires a preamble. β€” Cast by forwardEncapsulate()
  • Error: method forwardNo requires a To. β€” Cast by forwardNo()
  • Error: method forwardNo requires a body. β€” Cast by forwardNo()
  • Error: no rebuild rule $name defined. β€” Cast by rebuild()
  • Error: only build() Mail::Message's; they are not in a folder yet. β€” You may wish to construct a message to be stored in a some kind of folder, but you need to do that in two steps. First, create a normal Mail::Message, and then add it to the folder. During this Mail::Box::addMessage() process, the message will get coerce()-d into the right message type, adding storage information and the like. Cast by build()
  • Error: please install Email::Simple. β€” Cast by coerce()
  • Error: please install MIME::Entity. β€” Cast by coerce()
  • Error: please install Mail::Internet. β€” Cast by coerce()
  • Error: select parts via '$what'? β€” Cast by parts()
  • Warning: skipped unknown key '$key' in build. β€” Cast by build()
  • Error: unable to read delayed body for $msgid. β€” Cast by loadBody()
  • Error: unable to read delayed head for $msgid. β€” Cast by loadBody()

πŸ‘€ SEE ALSO πŸ‘€

This module is part of Mail-Box-IMAP4 version 4.01, built on December 13, 2025. Website: http://perl.overmeer.net/CPAN/ 🌐


πŸ“œ LICENSE πŸ“œ

For contributors see file ChangeLog.

This software is copyright (c) 2001-2025 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 bestie that's literally the whole page, you ate it πŸ’…βœ¨ no notes. this was perl v5.40.1, stamped 2026-01-21, and it's the Mail::...Message(3pm) page β€” go write some mail code, you've got this πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from