Mail::M...ge::Part(3)
Mail::M...ge::Part π
okay so you're reading the perl docs for Mail::M...ge::Part, part of the User Contributed Perl Documentation, and bestie. this one is so good. buckle up π
β¨ NAME β¨
Mail::Message::Part β a part of a message, but a message by itself π
πΈ INHERITANCE πΈ
the family tree goes like this, no cap:
Mail::Message::Part
is a Mail::Message
is a Mail::Reporter
π SYNOPSIS π
here's the vibe, in code:
my Mail::Message $message = ...;
if($message->isMultipart) {
my Mail::Message::Part $part;
foreach $part ($message->body->parts) {
$part->print(\*OUT);
my $attached_head = $part->head;
my $attached_body = $part->body; # encoded as read
my $attached_body = $part->decoded; # transfer-encoding removed
}
}
like, you grab a multipart message, loop over $message->body->parts, print each one, and peek at both the head and the body β and notice you can get the body either as it was encoded as read or as the decoded version with the transfer-encoding removed. the way that's literally two different things you can ask for?? iconic π¦
π«Ά DESCRIPTION π«Ά
so a Mail::Message::Part object holds a message that's tucked inside the body of another message. attachments? yeah, those are parts. that's the whole thing π
real talk though: READ Mail::Message FIRST. π¨ a part is a special little message β it has a reference back to its parent message, and it usually will not get sub-classed into mail-folder-specific variants. so like, don't go expecting folder-flavored versions of parts, that's not the move.
extends "DESCRIPTION" in Mail::Message π
and that's just part one, bestie, there's more coming β¨
β¨ METHODS β¨
Extends "METHODS" in Mail::Message. So basically everything Mail::Message can do, this lil guy can do too π
π Constructors π
Extends "Constructors" in Mail::Message.
$obj->clone(%options)β inherited, so go peek at "Constructors" in Mail::Message bestie π«Ά$class->new(%options)β makes a whole new message part. It improves on the base version, so also check "Constructors" in Mail::Reporter πΈ
Here's the option menu, with the column showing which class each one comes from and what it defaults to:
-Option --Defined in --Default
body Mail::Message undef
body_type Mail::Message Mail::Message::Body::Lines
container <required>
deleted Mail::Message false
field_type Mail::Message undef
head Mail::Message <empty header>
head_type Mail::Message Mail::Message::Head::Complete
labels Mail::Message +{}
messageId Mail::Message undef
modified Mail::Message false
trusted Mail::Message false
And now the breakdown of each one, one by one, no skipping π
body => $objectbody_type => $classcontainer => BODYβ this is a reference to the parental Mail::Message::Body object that this part is a member of. That parent could be a Mail::Message::Body::Multipart or a Mail::Message::Body::Nested. So yeah, you must have a container, it's literally required, no container no part πdeleted => BOOLEANfield_type => $classhead => $objecthead_type => $classlabels => \@pairs|\%settingsmessageId => $idmodified => BOOLEANtrusted => BOOLEAN
π Attributes π
Extends "Attributes" in Mail::Message.
π¦ Constructing a message π¦
Extends "Constructing a message" in Mail::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, $container, $headers)β this one wraps a message part around a$body. The body already carries info about its own content inside it, and that info gets used to build a header for the message. On top of that you can hand over even more$headers. Heads up tho: no headers are obligatory, and no extra headers get fabricated automatically β it does not just invent stuff for you. Improves base, see "Constructing a message" in Mail::Message::Construct::Build. Example time, bestie:
my $multi = Mail::Message::Body::Multipart->new;
my $part = Mail::Message::Part->buildFromBody($body, $multi);
$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::Message.
$obj->container()β inherited, see "The message" in Mail::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->partNumber()β inherited, see "The message" in Mail::Message$obj->print( [$fh] )β inherited, see "The message" in Mail::Message$obj->printEscapedFrom($fh)β prints the message part, except every line that starts with'From 'gets a leading>stuck in front of it. See Mail::Message::Body::printEscapedFrom() for the deets β¨$obj->send( [$mailer], %options )β inherited, see "The message" in Mail::Message$obj->size()β inherited, 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::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::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::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)β inherited, see "Flags" in Mail::Message$obj->labels()β inherited, 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::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::Message.
$obj->clonedFrom()β inherited, see "Internals" in Mail::Message$class->coerce( <$body|$message>, $multipart, @headers )β this transforms a$bodyor a$messageinto a real, actual message part. The$multipartis a reference to the parental body.
When you hand it a $body, you can also pass extra @headers along. Bodies get coerced into message parts by calling buildFromBody(). And if you give it a $message that lives in a folder, that message will automatically be cloned for you β no cap. Improves base, see "Internals" in Mail::Message π
$obj->isDelayed()β inherited, see "Internals" in Mail::Message$obj->readBody( $parser, $head, [$bodytype] )β inherited, see "Internals" in Mail::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
π Error handling π
Extends "Error handling" in Mail::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::Message.
$obj->DESTROY()β inherited, see "Cleanup" in Mail::Reporter$obj->destruct()β okay so real talk: message parts can NOT be destructed part-by-part. Only whole messages can be forcefully freed from memory. That's just how it is, bestie π Of course you candelete()separate parts, but just know that only sets a flag so the part won't get written again. And on top of that, you might wanna considerrebuild()to get rid of deleted parts. Improves base, see "Cleanup" in Mail::Message
πΈ DETAILS πΈ
Extends "DETAILS" in Mail::Message.
π DIAGNOSTICS π
okay bestie, this is the part where the module yells at you. every one of these is the module being like "girl. no." β but it's all fixable, i promise. π«Ά
Error: Cannot include forward source as $kind.you gaveforward(include)an option it does not know. the valid choices are"NO","INLINE","ATTACH", and"ENCAPSULATE". cast byforward()Error: No default mailer found to send message.thesend()mechanism literally did not have enough info to go find a mail transfer agent to send this message for you. so tell it one! specify a mailer explicitly using the"via"options. cast bysend()Error: cannot include reply source as $kind.same vibe as above but 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.okay this one is fatal, so listen up. it means the specific$package(or one of its superclasses) does not implement this method where it should. the tea is: some other related classes do implement this method, but the class in your hand does not. probably you should investigate this, and probably you should inform the author of the package. cast bynotImplemented()Error: method bounce requires To, Cc, or Bcc.the messagebounce()method forwards a received message off to someone else without modification, so yeah β you must specify its new destination. if you're feeling the urge to not specify any destination, you're probably looking forreply()instead. and 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 container specified for part.cast bynew()Error: no rebuild rule $name defined.cast byrebuild()Error: only build() Mail::Message's; they are not in a folder yet.so maybe you wanna construct a message that's gonna live in some kind of folder β valid! but you have 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: select parts via '$what'?cast byparts()Warning: skipped unknown key '$key' in build.cast bybuild()Error: you cannot destruct message parts, only whole messages.nope, message parts can not be destructed per part β only whole messages can be forcefully freed from memory. considerdelete()orrebuild()instead. cast bydestruct()
π SEE ALSO π
this module is part of Mail-Message version 4.04, built on February 04, 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.
and that's a wrap on the whole page, bestie!! π tysm for reading all three parts, you ate fr fr π
this was perl v5.42.0, dated 2026-02-05, and it's the Mail::M...ge::Part(3) page β now go forth and slay your message parts β¨π¦π
π¦ where this page comes from
- fedora 44: perl-Mail-Message 4.04-1.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms