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 => $object
  • body_type => $class
  • container => 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 => BOOLEAN
  • field_type => $class
  • head => $object
  • head_type => $class
  • labels => \@pairs|\%settings
  • messageId => $id
  • modified => BOOLEAN
  • trusted => 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 $body or a $message into a real, actual message part. The $multipart is 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 can delete() 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 consider rebuild() 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 gave forward(include) an option it does not know. the valid choices are "NO", "INLINE", "ATTACH", and "ENCAPSULATE". cast by forward()
  • Error: No default mailer found to send message. the send() 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 by send()
  • Error: cannot include reply source as $kind. same vibe as above but 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. 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 by notImplemented()
  • Error: method bounce requires To, Cc, or Bcc. the message bounce() 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 for reply() instead. and 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 container specified for part. cast by new()
  • Error: no rebuild rule $name defined. cast by rebuild()
  • 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 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: select parts via '$what'? cast by parts()
  • Warning: skipped unknown key '$key' in build. cast by build()
  • 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. consider delete() or rebuild() instead. cast by destruct()

🌈 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