Mail::M...ltipart(3)
Mail::Message::Body::Multipart(3) π
okay so bestie, we're doing the Mail::Message::Body::Multipart manual page, and it's a whole situation β it's long, so this is part 1 of 2. buckle up π
β¨ NAME β¨
Mail::Message::Body::Multipart β the body of a message when it's got attachments, aka the part where your email is secretly a whole little zip file of vibes π¦
πΈ INHERITANCE πΈ
Mail::Message::Body::Multipart
is a Mail::Message::Body
is a Mail::Reporter
Mail::Message::Body also extends Mail::Reporter
is a Mail::Reporter
so it's a Mail::Message::Body, which is itself a Mail::Reporter, and Mail::Message::Body also extends Mail::Reporter and is a Mail::Reporter. yes, the family tree loops. it's giving big extended-family-holiday energy, we don't ask questions π
π«Ά SYNOPSIS π«Ά
See Mail::Message::Body
if($body->isMultipart) {
my @attachments = $body->parts;
my $attachment3 = $body->part(2);
my $before = $body->preamble;
my $after = $body->epilogue;
$body->part(1)->delete;
}
like, first you vibe check it with isMultipart, then you go grab parts, part(2), preamble, epilogue, and if a part is doing too much you just $body->part(1)->delete it. no cap. β¨
π DESCRIPTION π
The body (content) of a message can be stored in various ways. In this manual-page you find the description of extra functionality you have when a message contains attachments (parts). π
The number of multipart alternatives is growing. A full list is maintained by IANA at https://www.iana.org/assignments/media-types/media-types.xhtml#multipart π₯
multipart/mixedmultipart/alternativemultipart/relatedmultipart/report, RFC6522multipart/signed, RFC1847multipart/encryptedmultipart/multilingual, RFC8255 (unused)
Extends "DESCRIPTION" in Mail::Message::Body.
ngl that last one being marked (unused) is so iconic of it. it's just out here living its truth, unbothered π
π OVERLOADED π
Extends "OVERLOADED" in Mail::Message::Body.
- overload:
'""'stringification β inherited, see "OVERLOADED" inMail::Message::Body - overload:
'=='numerical comparison β inherited, see "OVERLOADED" inMail::Message::Body - overload:
'@{}'addressed as array β inherited, see "OVERLOADED" inMail::Message::Body - overload: bool true/false β inherited, see "OVERLOADED" in
Mail::Message::Body
all inherited bestie, this class isn't reinventing the wheel, she's just borrowing it π
β METHODS β
Extends "METHODS" in Mail::Message::Body.
π Constructors π
Extends "Constructors" in Mail::Message::Body.
$obj->clone()β inherited, see "Constructors" inMail::Message::Body$class->new(%options)β inherited, see "Constructors" inMail::Message::Body
here's the whole option menu, defaults and all, no gatekeeping:
-Option --Defined in --Default
based_on Mail::Message::Body undef
boundary undef
charset Mail::Message::Body 'PERL'
checked Mail::Message::Body false
content_id Mail::Message::Body undef
data Mail::Message::Body undef
description Mail::Message::Body undef
disposition Mail::Message::Body undef
eol Mail::Message::Body 'NATIVE'
epilogue ''
file Mail::Message::Body undef
filename Mail::Message::Body undef
language Mail::Message::Body undef
message Mail::Message::Body undef
mime_type Mail::Message::Body 'multipart/mixed'
modified Mail::Message::Body false
parts undef
preamble undef
transfer_encoding Mail::Message::Body 'none'
and now the tea on each one β
based_on=> $bodyboundary=> $separator β the $separator string to be used between parts of the message. This separator must be unique in case the message contains nested multiparts (which are not unusual, lowkey they're everywhere). Ifundef, a nice unique boundary will be generated for you π«Άcharset=> $charset|'PERL'|<undef>checked=> BOOLEANcontent_id=> STRINGdata=> @lines|$textdescription=> STRING|$fielddisposition=> STRING|$fieldeol=>'CR'|'LF'|'CRLF'|'NATIVE'epilogue=> $body|$text β the text which is included in the main body after the final boundary. This is usually empty, and has no meaning. π€·βοΈ Provide a $body object or plain $text (which will automatically translated into atext/plainbody).file=> $file|$handle|$iofilename=> $filelanguage=> STRING|@lang|$fieldmessage=> $messagemime_type=> STRING|$field|$mimemodified=> BOOLEANparts=> [$message, $body, ...] β specifies an initial list of parts in this body. These may be full $message objects, or $body objects which will be transformed into messages before use. Each message is coerced into aMail::Message::Partobject. π«MIME::EntityandMail::Internetobjects are acceptable in the list, because they are coercible intoMail::Message::Part's. Values ofundefwill be skipped silently.preamble=> $body|$text β the $text which is included in the body before the first part. It is common use to include a text to warn the user that the message is a multipart. However, this was useful in earlier days: most mail agents are very capable in warning the user themselves. so like, it's giving legacy behaviour, but do you boo π Provide a $body object or plain $text (which will automatically translated into atext/plainbody).transfer_encoding=> STRING|$field
Β» example:
my $intro = Mail::Message::Body->new(data => ['part one']);
my $pgp = Mail::Message::Body->new(data => ['part three']);
my $body = Mail::Message::Body::Multipart->new(
boundary => time . '--it-s-mine',
preamble => "This is a multi-part message in MIME format.\n\n",
parts => [ $intro, $folder->message(3)->decoded, $pgp ],
);
look at that boundary. time . '--it-s-mine'. iconic. no notes. π
π§ Attributes π§
Extends "Attributes" in Mail::Message::Body.
$obj->charsetDetectAlgorithm( [CODE|undef|METHOD] )β inherited, see "Attributes" inMail::Message::Body::Encode
πΈ Constructing a body πΈ
Extends "Constructing a body" in Mail::Message::Body.
$obj->attach($messages|$bodies)β attach a list of $messages to this multipart. A new body is returned. When you specify $bodies, they will first be translated into real messages.MIME::EntityandMail::Internetobjects may be specified too. In any case, the parts will be coerced intoMail::Message::Part's. Improves base, see "Constructing a body" inMail::Message::Body::Construct$obj->charsetDetect(%options)β inherited, see "Constructing a body" inMail::Message::Body::Encode$obj->check()β inherited, see "Constructing a body" inMail::Message::Body::Encode$obj->concatenate(@components)β inherited, see "Constructing a body" inMail::Message::Body::Construct$obj->decoded(%options)β inherited, see "Constructing a body" inMail::Message::Body$obj->encode(%options)β inherited, see "Constructing a body" inMail::Message::Body::Encode$obj->encoded(%options)β inherited, see "Constructing a body" inMail::Message::Body::Encode$obj->eol( ['CR'|'LF'|'CRLF'|'NATIVE'] )β inherited, see "Constructing a body" inMail::Message::Body::Encode$obj->foreachComponent(CODE)β execute theCODEfor each component of the message: the preamble, the epilogue, and each of the parts. π Each component is a body and is passed as second argument to theCODE. The first argument is a reference to this multi-parted body. TheCODEreturns a body object. When any of the returned bodies differs from the body which was passed, then a new multi-part body will be returned. Reference to the not-changed bodies and the changed bodies will be included in that new multi-part.
Β» example:
my $checked = $multi->foreachComponent(sub {$_[1]->check});
$obj->foreachLine((CODE))β it is NOT possible to call some code for each line of a multipart, because that would not only inflict damage to the body of each message part, but also to the headers and the part separators. π«π Improves base, see "Constructing a body" inMail::Message::Body::Construct$obj->stripSignature(%options)β removes all parts which contains data usually defined as being signature. TheMIME::Typemodule provides this knowledge. A new multipart is returned, containing the remaining parts. No %options are defined yet, although some may be specified, because this method overrules thestripSignaturemethod for normal bodies. Improves base, see "Constructing a body" inMail::Message::Body::Construct
-Option --Defined in --Default
max_lines Mail::Message::Body::Construct 10
pattern Mail::Message::Body::Construct qr/^--\s?$/
result_type Mail::Message::Body::Construct <same as current>
max_lines=> INTEGER|undefpattern=> REGEX|STRING|CODEresult_type=> CLASS
$obj->unify($body)β inherited, see "Constructing a body" inMail::Message::Body::Encode
π¦ The body π¦
Extends "The body" in Mail::Message::Body.
$obj->isDelayed()β inherited, see "The body" inMail::Message::Body$obj->isMultipart()β inherited, see "The body" inMail::Message::Body$obj->isNested()β inherited, see "The body" inMail::Message::Body$obj->message( [$message] )β inherited, see "The body" inMail::Message::Body$obj->partNumberOf($part)β inherited, see "The body" inMail::Message::Body
π About the payload π
Extends "About the payload" in Mail::Message::Body.
$obj->charset()β inherited, see "About the payload" inMail::Message::Body$obj->checked( [BOOLEAN] )β inherited, see "About the payload" inMail::Message::Body$obj->contentId( [STRING|$field] )β inherited, see "About the payload" inMail::Message::Body$obj->description( [STRING|$field] )β inherited, see "About the payload" inMail::Message::Body$obj->disposition( [STRING|$field] )β inherited, see "About the payload" inMail::Message::Body$obj->dispositionFilename( [$directory] )β inherited, see "About the payload" inMail::Message::Body::Encode$obj->isBinary()β inherited, see "About the payload" inMail::Message::Body::Encode$obj->isText()β inherited, see "About the payload" inMail::Message::Body::Encode$obj->language( [@langs|\@langs|$langs|$field] )β inherited, see "About the payload" inMail::Message::Body$obj->mimeType()β inherited, see "About the payload" inMail::Message::Body$obj->nrLines()β inherited, see "About the payload" inMail::Message::Body$obj->size()β inherited, see "About the payload" inMail::Message::Body$obj->transferEncoding( [STRING|$field] )β inherited, see "About the payload" inMail::Message::Body$obj->type( [STRING|$field] )β inherited, see "About the payload" inMail::Message::Body
π Access to the payload π
Extends "Access to the payload" in Mail::Message::Body.
okay so that's where part 1 wraps β the payload access section is just getting started and there is so much more coming in part 2, don't go anywhere bestie π«Άβ¨
$obj->boundary( [STRING] )β bestie this hands you the boundary, aka the lil string that keeps the parts from kissing each other π. If none was read from file, one gets assigned for you, no stress. PassSTRINGand you're explicitly setting the boundary to be used, periodt.$obj->endsOnNewline()β inherited, go look at "Access to the payload" inMail::Message::Body.$obj->epilogue()β this is the epilogue, the text after the last message part (so, after the last real attachment π). It's stored in aBODYobject, and its encoding is taken from the general multipart header. iykyk.$obj->file()β inherited, see "Access to the payload" inMail::Message::Body.$obj->lines()β inherited, see "Access to the payload" inMail::Message::Body.$obj->part($index)β gimme just the one part at$index. You can lowkey use a negative value here and it counts from the back of the list π¦. Heads up: parts which are flagged to be deleted are still included in the count, so don't come for me when the math is mathing.
Β» example:
$message->body->part(2)->print;
$body->part(1)->delete;
$obj->parts( [<'ALL'|'ACTIVE'|'DELETED'|'RECURSE'|$filter>] )β returns all parts by default, or whenALLis specified.ACTIVEreturns the parts which are not flagged for deletion, as opposite toDELETED.RECURSEdescents into all nested multiparts to collect all parts β she goes deep π .
You may also specify a code reference which is called for each nested part. The first argument will be the message part. When the code returns true, the part is incorporated in the return list. Cute, right?
Β» example:
print "Number of attachments: ",
scalar $message->body->parts('ACTIVE');
foreach my $part ($message->body->parts) {
print "Type: ", $part->get('Content-Type');
}
$obj->preamble()β the preamble, bestie! That's the text before the first message part (before the first real attachment πΈ). It's stored in aBODYobject, and its encoding is taken from the multipart header.$obj->print( [$fh] )β inherited, see "Access to the payload" inMail::Message::Body.$obj->printEscapedFrom($fh)β inherited, see "Access to the payload" inMail::Message::Body.$obj->string()β inherited, see "Access to the payload" inMail::Message::Body.$obj->stripTrailingNewline()β inherited, see "Access to the payload" inMail::Message::Body.$obj->write(%options)β inherited, see "Access to the payload" inMail::Message::Body.
π οΈ Internals π οΈ
Extends "Internals" in Mail::Message::Body. The backstage pass, the green room, the lore π.
$any->addTransferEncHandler( $name, <$class|$object> )β inherited, see "Internals" inMail::Message::Body::Encode.$obj->contentInfoFrom($head)β inherited, see "Internals" inMail::Message::Body.$obj->contentInfoTo($head)β inherited, see "Internals" inMail::Message::Body.$obj->fileLocation( [$begin, $end] )β inherited, see "Internals" inMail::Message::Body.$obj->getTransferEncHandler($type)β inherited, see "Internals" inMail::Message::Body::Encode.$obj->isModified()β inherited, see "Internals" inMail::Message::Body.$obj->load()β inherited, see "Internals" inMail::Message::Body.$obj->modified( [BOOLEAN] )β inherited, see "Internals" inMail::Message::Body.$obj->moveLocation( [$distance] )β inherited, see "Internals" inMail::Message::Body.$obj->read( $parser, $head, $bodytype, [$chars, [$lines]] )β inherited, see "Internals" inMail::Message::Body.
π Error handling π
Extends "Error handling" in Mail::Message::Body. Yes we're in our feelings era.
$obj->AUTOLOAD()β inherited, see "Error handling" inMail::Message::Body.$obj->notImplemented()β inherited, see "Error handling" inMail::Reporter.$obj->notImplemented()β inherited, see "Error handling" inMail::Reporter.
Not a typo bestie β notImplemented() is listed twice right here in the original, back to back, same description. The manpage said it twice and I am not about to gaslight the manpage. π
π§Ό Cleanup π§Ό
Extends "Cleanup" in Mail::Message::Body. Tidy up, hydrate, slay.
$obj->DESTROY()β inherited, see "Cleanup" inMail::Reporter.$obj->DESTROY()β inherited, see "Cleanup" inMail::Reporter.
And yes, DESTROY() is listed twice too. The original did that. We keep it. Periodt. π
β¨ DETAILS β¨
Extends "DETAILS" in Mail::Message::Body. That's genuinely the whole section, no notes, she's minimal π
.
π¨ DIAGNOSTICS π¨
Every warning, every error, every little fault, all of it. Read carefully, these are the vibes when things go sideways.
- Warning:
Content-Transfer-Encoding '$te' requires explicit charset, defaulted to utf-8.β Cast byencode(). - Error:
You cannot use foreachLine on a multipart.βforeachLine()should be used on decoded message bodies only, because it would attempt to modify part-headers and separators as well, which is clearly not acceptable. Cast byforeachLine(). Like... it literally cannot, bestie π. - Error:
cannot concatenate element $whichβ Cast byconcatenate(). - Fault:
cannot open $file to write body: $!β Cast bywrite(). - Warning:
charset '$name' is not known.β The encoding or decoding of a message body encounters a character set which is not understood by Perl's Encode module. Cast byencode(). - 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:
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().
Yep β that exact same error is in the original twice. Identical. Both copies live here now, side by side, matching. π«Ά
- Error:
data not convertible to a message (type is $type)β An object which is not coercable into aMail::Message::Partobject was passed to the initiation. Cast bynew(). - Fault:
error closing $file after write body: $!β Cast bywrite(). - Warning:
no decoder defined for transfer encoding '$encoding'.β The data (message body) is encoded in a way which is not currently understood, therefore no decoding (or recoding) can take place. Cast byencode(). - Warning:
no encoder defined for transfer encoding '$encoding'.β The data (message body) has been decoded, but the required encoding is unknown. The decoded data is returned. Cast byencode(). - Error:
no filename parameter for write() body.β Cast bywrite(). - Error:
part number needs multi-part or nested.β Cast bypartNumberOf(). - Error:
unknown criterium $what to select parts.β Valid choices for part selections areALL,ACTIVE,DELETED,RECURSEor a code reference. However, some other argument was passed. Cast byparts(). - Error:
unknown line terminator '$eol'.β Cast byeol().
π 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.
okay bestie that's the whole page, you ate that π this was written with perl v5.42.0, dated 2026-02-05, and filed under Mail::M...ltipart(3) β go forth and parse some multiparts, you absolute icon ππ¦β¨
π¦ 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