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"inMail::Message$class->new(%options)β inherited, so go peep"Constructors"inMail::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 inMail::Message, defaultundefbody_typeβ defined inMail::Box::Message, defaultMail::Message::Body::Linescache_bodyβ defaultfalsecache_headβ defaultfalsecache_labelsβ defaultfalsedeletedβ defined inMail::Message, defaultfalsefield_typeβ defined inMail::Message, defaultundeffolderβ defined inMail::Box::Message, default<required>(yes bestie, it's mandatory, you cannot skip it)headβ defined inMail::Message, defaultundefhead_typeβ defined inMail::Message, defaultMail::Message::Head::Completelabelsβ defined inMail::Message, default+{}messageIdβ defined inMail::Message, defaultundefmodifiedβ defined inMail::Message, defaultfalsesizeβ defined inMail::Box::Message, defaultundeftrustedβ defined inMail::Message, defaultfalseuniqueβ defined inMail::Box::Net::Message, default<unique string>write_labelsβ defaulttrue
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 ofCODE) 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, usinglabel(), 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"inMail::Box::Message$obj->seqnr( [$integer] )β inherited, see"Attributes"inMail::Box::Message$obj->unique( [STRING|undef] )β inherited, see"Attributes"inMail::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"inMail::Message::Construct::Bounce$class->build( [$message|$part|$body], @fields, %options )β inherited, see"Constructing a message"inMail::Message::Construct::Build$class->buildFromBody($body, [$head], $headers)β inherited, see"Constructing a message"inMail::Message::Construct::Build$obj->forward(%options)β inherited, see"Constructing a message"inMail::Message::Construct::Forward$obj->forwardAttach(%options)β inherited, see"Constructing a message"inMail::Message::Construct::Forward$obj->forwardEncapsulate(%options)β inherited, see"Constructing a message"inMail::Message::Construct::Forward$obj->forwardInline(%options)β inherited, see"Constructing a message"inMail::Message::Construct::Forward$obj->forwardNo(%options)β inherited, see"Constructing a message"inMail::Message::Construct::Forward$obj->forwardPostlude()β inherited, see"Constructing a message"inMail::Message::Construct::Forward$obj->forwardPrelude()β inherited, see"Constructing a message"inMail::Message::Construct::Forward$obj->forwardSubject(STRING)β inherited, see"Constructing a message"inMail::Message::Construct::Forward$class->read($fh|$text|\$text|\@lines, %options)β inherited, see"Constructing a message"inMail::Message::Construct::Read$obj->rebuild(%options)β inherited, see"Constructing a message"inMail::Message::Construct::Rebuild$obj->reply(%options)β inherited, see"Constructing a message"inMail::Message::Construct::Reply$obj->replyPrelude( [STRING|$field|$address|\@addrs|\@fields] )β inherited, see"Constructing a message"inMail::Message::Construct::Reply$any->replySubject(STRING)β inherited, see"Constructing a message"inMail::Message::Construct::Reply
π The message π
Extends "The message" in Mail::Box::Net::Message.
$obj->container()β inherited, see"The message"inMail::Message$obj->copyTo($folder, %options)β inherited, see"The message"inMail::Box::Message$obj->endsOnNewline()β inherited, see"The message"inMail::Message$obj->isDummy()β inherited, see"The message"inMail::Message$obj->isPart()β inherited, see"The message"inMail::Message$obj->messageId()β inherited, see"The message"inMail::Message$obj->moveTo($folder, %options)β inherited, see"The message"inMail::Box::Message$obj->partNumber()β inherited, see"The message"inMail::Message$obj->print( [$fh] )β inherited, see"The message"inMail::Message$obj->send( [$mailer], %options )β inherited, see"The message"inMail::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"inMail::Message$obj->toplevel()β inherited, see"The message"inMail::Message$obj->write( [$fh] )β inherited, see"The message"inMail::Message
πΈ The header πΈ
Extends "The header" in Mail::Box::Net::Message.
$obj->bcc()β inherited, see"The header"inMail::Message$obj->cc()β inherited, see"The header"inMail::Message$obj->date()β inherited, see"The header"inMail::Message$obj->destinations()β inherited, see"The header"inMail::Message$obj->from()β inherited, see"The header"inMail::Message$obj->get($fieldname)β inherited, see"The header"inMail::Message$obj->guessTimestamp()β inherited, see"The header"inMail::Message$obj->head( [$head] )β inherited, see"The header"inMail::Message$obj->nrLines()β inherited, see"The header"inMail::Message$obj->sender()β inherited, see"The header"inMail::Message$obj->study($fieldname)β inherited, see"The header"inMail::Message$obj->subject()β inherited, see"The header"inMail::Message$obj->timestamp()β inherited, see"The header"inMail::Message$obj->to()β inherited, see"The header"inMail::Message
π¦ The body π¦
Extends "The body" in Mail::Box::Net::Message.
$obj->body( [$body] )β inherited, see"The body"inMail::Message$obj->contentType()β inherited, see"The body"inMail::Message$obj->decoded(%options)β inherited, see"The body"inMail::Message$obj->encode(%options)β inherited, see"The body"inMail::Message$obj->isMultipart()β inherited, see"The body"inMail::Message$obj->isNested()β inherited, see"The body"inMail::Message$obj->parts( [<'ALL'|'ACTIVE'|'DELETED'|'RECURSE'|$filter>] )β inherited, see"The body"inMail::Message
β Flags β
Extends "Flags" in Mail::Box::Net::Message.
$obj->delete()β inherited, see"Flags"inMail::Message$obj->deleted( [BOOLEAN] )β inherited, see"Flags"inMail::Message$obj->isDeleted()β inherited, see"Flags"inMail::Message$obj->isModified()β inherited, see"Flags"inMail::Message$obj->label($label|PAIRS)β with only one argument, the value related to$labelgets 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 withnew(write_labels). Some labels are translated to the corresponding IMAP system labels. Improves base, see"Flags"inMail::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. Seelabels()to set values. Improves base, see"Flags"inMail::Message$obj->labelsToStatus()β inherited, see"Flags"inMail::Message$obj->modified( [BOOLEAN] )β inherited, see"Flags"inMail::Message$obj->statusToLabels()β inherited, see"Flags"inMail::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"inMail::Message::Construct::Text$obj->lines()β inherited, see"The whole message as text"inMail::Message::Construct::Text$obj->printStructure( [$fh|undef],[$indent] )β inherited, see"The whole message as text"inMail::Message::Construct::Text$obj->string()β inherited, see"The whole message as text"inMail::Message::Construct::Text
π§ Internals π§
Extends "Internals" in Mail::Box::Net::Message.
$obj->clonedFrom()β inherited, see"Internals"inMail::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" inMail::Messagefor the tea β$obj->diskDelete()β inherited, see "Internals" inMail::Box::Message$obj->fetch( [$info, ...] )β bestie, this one hits the IMAP server with theUID FETCH IMAPcommand to pull data about this message. The$inforequest gets handed off toMail::Box::IMAP4::fetch(). Hand it no$infoat all and it grabsALLthe info and hands it back to you as aHASH. π$obj->isDelayed()β inherited, see "Internals" inMail::Message$obj->loadBody()β inherited, see "Internals" inMail::Box::Net::Message$obj->readBody( $parser, $head, [$bodytype] )β inherited, see "Internals" inMail::Box::Message$obj->readFromParser( $parser, [$bodytype] )β inherited, see "Internals" inMail::Message$obj->readHead( $parser, [$class] )β inherited, see "Internals" inMail::Message$obj->recursiveRebuildPart($part, %options)β inherited, see "Internals" inMail::Message::Construct::Rebuild$obj->storeBody($body)β inherited, see "Internals" inMail::Message$obj->takeMessageId( [STRING] )β inherited, see "Internals" inMail::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 β aMail::Box::write()orMail::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" inMail::Message::Construct$obj->notImplemented()β inherited, see "Error handling" inMail::Reporter$any->shortSize( [$value] )β inherited, see "Error handling" inMail::Message$obj->shortString()β inherited, see "Error handling" inMail::Message
π§Ή Cleanup π§Ή
Extends "Cleanup" in Mail::Box::Net::Message.
$obj->DESTROY()β inherited, see "Cleanup" inMail::Reporter$obj->destruct()β inherited, see "Cleanup" inMail::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 byforward()Error: No default mailer found to send message.β The messagesend()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 bysend()Error: cannot coerce a $type object into a $me object.β Cast bycoerce()Error: cannot include reply source as $kind.β Unknown alternative for the"include"option ofreply(). Valid choices are"NO","INLINE", and"ATTACH". Cast byreply()Error: cannot read message from a $source}.β Cast byread()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: coercion starts with some object, not '$type'.β Cast bycoerce()Error: method bounce requires To, Cc, or Bcc.β The messagebounce()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 forreply(). When you wish to modify the content, useforward(). Cast bybounce()Error: method forwardAttach requires a preamble.β Cast byforwardAttach()Error: method forwardEncapsulate requires a preamble.β Cast byforwardEncapsulate()Error: method forwardNo requires a To.β Cast byforwardNo()Error: method forwardNo requires a body.β Cast byforwardNo()Error: no rebuild rule $name defined.β Cast byrebuild()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 normalMail::Message, and then add it to the folder. During thisMail::Box::addMessage()process, the message will getcoerce()-d into the right message type, adding storage information and the like. Cast bybuild()Error: please install Email::Simple.β Cast bycoerce()Error: please install MIME::Entity.β Cast bycoerce()Error: please install Mail::Internet.β Cast bycoerce()Error: select parts via '$what'?β Cast byparts()Warning: skipped unknown key '$key' in build.β Cast bybuild()Error: unable to read delayed body for $msgid.β Cast byloadBody()Error: unable to read delayed head for $msgid.β Cast byloadBody()
π 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
- ubuntu resolute: libmail-box-imap4-perl 4.01-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmail-box-imap4-perl 4.01-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