{
    "mode": "perldoc",
    "parameter": "Mail::Message::Body::Multipart",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3AMessage%3A%3ABody%3A%3AMultipart/json",
    "generated": "2026-06-13T06:55:10Z",
    "synopsis": "See Mail::Message::Body\nif($body->isMultipart) {\nmy @attachments = $body->parts;\nmy $attachment3 = $body->part(2);\nmy $before      = $body->preamble;\nmy $after       = $body->epilogue;\n$body->part(1)->delete;\n}",
    "sections": {
        "NAME": {
            "content": "Mail::Message::Body::Multipart - body of a message with attachments\n",
            "subsections": []
        },
        "INHERITANCE": {
            "content": "Mail::Message::Body::Multipart\nis a Mail::Message::Body\nis a Mail::Reporter\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "See Mail::Message::Body\n\nif($body->isMultipart) {\nmy @attachments = $body->parts;\nmy $attachment3 = $body->part(2);\nmy $before      = $body->preamble;\nmy $after       = $body->epilogue;\n$body->part(1)->delete;\n}\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The body (content) of a message can be stored in various ways. In this manual-page you find the\ndescription of extra functionality you have when a message contains attachments (parts).\n\nExtends \"DESCRIPTION\" in Mail::Message::Body.\n",
            "subsections": []
        },
        "OVERLOADED": {
            "content": "Extends \"OVERLOADED\" in Mail::Message::Body.\n\noverload: \"\"\nInherited, see \"OVERLOADED\" in Mail::Message::Body\n\noverload: '==' and '!='\nInherited, see \"OVERLOADED\" in Mail::Message::Body\n\noverload: @{}\nInherited, see \"OVERLOADED\" in Mail::Message::Body\n\noverload: bool\nInherited, see \"OVERLOADED\" in Mail::Message::Body\n",
            "subsections": []
        },
        "METHODS": {
            "content": "Extends \"METHODS\" in Mail::Message::Body.\n",
            "subsections": [
                {
                    "name": "Constructors",
                    "content": "Extends \"Constructors\" in Mail::Message::Body.\n\n$obj->clone()\nInherited, see \"Constructors\" in Mail::Message::Body\n\nMail::Message::Body::Multipart->new(%options)\n-Option           --Defined in         --Default\nbasedon           Mail::Message::Body  undef\nboundary                                undef\ncharset            Mail::Message::Body  'PERL' or <undef>\nchecked            Mail::Message::Body  <false>\ncontentid         Mail::Message::Body  undef\ndata               Mail::Message::Body  undef\ndescription        Mail::Message::Body  undef\ndisposition        Mail::Message::Body  undef\neol                Mail::Message::Body  'NATIVE'\nepilogue                                ''\nfile               Mail::Message::Body  undef\nfilename           Mail::Message::Body  undef\nlog                Mail::Reporter       'WARNINGS'\nmessage            Mail::Message::Body  undef\nmimetype          Mail::Message::Body  'multipart/mixed'\nmodified           Mail::Message::Body  <false>\nparts                                   undef\npreamble                                undef\ntrace              Mail::Reporter       'WARNINGS'\ntransferencoding  Mail::Message::Body  'none'\n\nbasedon => BODY\nboundary => STRING\nSeparator to be used between parts of the message. This separator must be unique in case\nthe message contains nested multiparts (which are not unusual). If \"undef\", a nice unique\nboundary will be generated.\n\ncharset => CHARSET|'PERL'\nchecked => BOOLEAN\ncontentid => STRING\ndata => ARRAY-OF-LINES | STRING\ndescription => STRING|FIELD\ndisposition => STRING|FIELD\neol => 'CR'|'LF'|'CRLF'|'NATIVE'\nepilogue => BODY|STRING\nThe text which is included in the main body after the final boundary. This is usually\nempty, and has no meaning.\n\nProvide a BODY object or a STRING which will automatically translated into a \"text/plain\"\nbody.\n\nfile => FILENAME|FILEHANDLE|IOHANDLE\nfilename => FILENAME\nlog => LEVEL\nmessage => MESSAGE\nmimetype => STRING|FIELD|MIME\nmodified => BOOLEAN\nparts => ARRAY-OF-(MESSAGES|BODIES)\nSpecifies an initial list of parts in this body. These may be full MESSAGES, or BODIES\nwhich transformed into messages before use. Each message is coerced into a\nMail::Message::Part object.\n\nMIME::Entity and Mail::Internet objects are acceptable in the list, because they are\ncoercible into Mail::Message::Part's. Values of \"undef\" will be skipped silently.\n\npreamble => BODY|STRING\nThe text which is included in the body before the first part. It is common use to include\na text to warn the user that the message is a multipart. However, this was useful in\nearlier days: most mail agents are very capable in warning the user themselves.\n\nProvide a BODY object or a STRING which will automatically translated into a text/plain\nbody.\n\ntrace => LEVEL\ntransferencoding => STRING|FIELD\n\nexample:\n\nmy $intro = Mail::Message::Body->new(data => ['part one']);\nmy $pgp   = Mail::Message::Body->new(data => ['part three']);\n\nmy $body  = Mail::Message::Body::Multipart->new\n( boundary => time . '--it-s-mine'\n, preamble => \"This is a multi-part message in MIME format.\\n\\n\"\n, parts    => [ $intro, $folder->message(3)->decoded, $pgp ]\n);\n"
                },
                {
                    "name": "Constructing a body",
                    "content": "Extends \"Constructing a body\" in Mail::Message::Body.\n\n$obj->attach($messages|$bodies)\nAttach a list of $messages to this multipart. A new body is returned. When you specify\n$bodies, they will first be translated into real messages. MIME::Entity and Mail::Internet\nobjects may be specified too. In any case, the parts will be coerced into\nMail::Message::Part's.\n\n$obj->check()\nInherited, see \"Constructing a body\" in Mail::Message::Body::Encode\n\n$obj->concatenate($components)\nInherited, see \"Constructing a body\" in Mail::Message::Body::Construct\n\n$obj->decoded(%options)\nInherited, see \"Constructing a body\" in Mail::Message::Body\n\n$obj->encode(%options)\nInherited, see \"Constructing a body\" in Mail::Message::Body::Encode\n\n$obj->encoded()\nInherited, see \"Constructing a body\" in Mail::Message::Body::Encode\n\n$obj->eol( ['CR'|'LF'|'CRLF'|'NATIVE'] )\nInherited, see \"Constructing a body\" in Mail::Message::Body\n\n$obj->foreachComponent(CODE)\nExecute the CODE for each component of the message: the preamble, the epilogue, and each of\nthe parts.\n\nEach component is a body and is passed as second argument to the CODE. The first argument is\na reference to this multi-parted body. The CODE returns a body object. When any of the\nreturned bodies differs from the body which was passed, then a new multi-part body will be\nreturned. Reference to the not-changed bodies and the changed bodies will be included in\nthat new multi-part.\n\nexample:\n\nmy $checked = $multi->foreachComponent(sub {$[1]->check});\n\n$obj->foreachLine((CODE))\nIt is NOT possible to call some code for each line of a multipart, because that would not\nonly inflict damage to the body of each message part, but also to the headers and the part\nseparators.\n\n$obj->stripSignature(%options)\nRemoves all parts which contains data usually defined as being signature. The MIME::Type\nmodule provides this knowledge. A new multipart is returned, containing the remaining parts.\nNo %options are defined yet, although some may be specified, because this method overrules\nthe \"stripSignature\" method for normal bodies.\n\n-Option     --Defined in                    --Default\nmaxlines    Mail::Message::Body::Construct  10\npattern      Mail::Message::Body::Construct  qr/^--\\s?$/\nresulttype  Mail::Message::Body::Construct  <same as current>\n\nmaxlines => INTEGER|undef\npattern => REGEX|STRING|CODE\nresulttype => CLASS\n\n$obj->unify($body)\nInherited, see \"Constructing a body\" in Mail::Message::Body::Encode\n"
                },
                {
                    "name": "The body",
                    "content": "Extends \"The body\" in Mail::Message::Body.\n\n$obj->isDelayed()\nInherited, see \"The body\" in Mail::Message::Body\n\n$obj->isMultipart()\nInherited, see \"The body\" in Mail::Message::Body\n\n$obj->isNested()\nInherited, see \"The body\" in Mail::Message::Body\n\n$obj->message( [$message] )\nInherited, see \"The body\" in Mail::Message::Body\n\n$obj->partNumberOf($part)\nInherited, see \"The body\" in Mail::Message::Body\n"
                },
                {
                    "name": "About the payload",
                    "content": "Extends \"About the payload\" in Mail::Message::Body.\n\n$obj->charset()\nInherited, see \"About the payload\" in Mail::Message::Body\n\n$obj->checked( [BOOLEAN] )\nInherited, see \"About the payload\" in Mail::Message::Body\n\n$obj->contentId( [STRING|$field] )\nInherited, see \"About the payload\" in Mail::Message::Body\n\n$obj->description( [STRING|$field] )\nInherited, see \"About the payload\" in Mail::Message::Body\n\n$obj->disposition( [STRING|$field] )\nInherited, see \"About the payload\" in Mail::Message::Body\n\n$obj->dispositionFilename( [$directory] )\nInherited, see \"About the payload\" in Mail::Message::Body::Encode\n\n$obj->isBinary()\nInherited, see \"About the payload\" in Mail::Message::Body::Encode\n\n$obj->isText()\nInherited, see \"About the payload\" in Mail::Message::Body::Encode\n\n$obj->mimeType()\nInherited, see \"About the payload\" in Mail::Message::Body\n\n$obj->nrLines()\nInherited, see \"About the payload\" in Mail::Message::Body\n\n$obj->size()\nInherited, see \"About the payload\" in Mail::Message::Body\n\n$obj->transferEncoding( [STRING|$field] )\nInherited, see \"About the payload\" in Mail::Message::Body\n\n$obj->type( [STRING|$field] )\nInherited, see \"About the payload\" in Mail::Message::Body\n"
                },
                {
                    "name": "Access to the payload",
                    "content": "Extends \"Access to the payload\" in Mail::Message::Body.\n\n$obj->boundary( [STRING] )\nReturns the boundary which is used to separate the parts in this body. If none was read from\nfile, then one will be assigned. With STRING you explicitly set the boundary to be used.\n\n$obj->endsOnNewline()\nInherited, see \"Access to the payload\" in Mail::Message::Body\n\n$obj->epilogue()\nReturns the epilogue; the text after the last message part (after the last real attachment).\nThe epilogue is stored in a BODY object, and its encoding is taken from the general\nmultipart header.\n\n$obj->file()\nInherited, see \"Access to the payload\" in Mail::Message::Body\n\n$obj->lines()\nInherited, see \"Access to the payload\" in Mail::Message::Body\n\n$obj->part($index)\nReturns only the part with the specified $index. You may use a negative value here, which\ncounts from the back in the list. Parts which are flagged to be deleted are included in the\ncount.\n\nexample:\n\n$message->body->part(2)->print;\n$body->part(1)->delete;\n\n$obj->parts( [<'ALL'|'ACTIVE'|'DELETED'|'RECURSE'|$filter>] )\nReturn all parts by default, or when ALL is specified. \"ACTIVE\" returns the parts which are\nnot flagged for deletion, as opposite to \"DELETED\". \"RECURSE\" descents into all nested\nmultiparts to collect all parts.\n\nYou may also specify a code reference which is called for each nested part. The first\nargument will be the message part. When the code returns true, the part is incorporated in\nthe return list.\n\nexample:\n\nprint \"Number of attachments: \",\nscalar $message->body->parts('ACTIVE');\n\nforeach my $part ($message->body->parts) {\nprint \"Type: \", $part->get('Content-Type');\n}\n\n$obj->preamble()\nReturns the preamble; the text before the first message part (before the first real\nattachment). The preamble is stored in a BODY object, and its encoding is taken from the\nmultipart header.\n\n$obj->print( [$fh] )\nInherited, see \"Access to the payload\" in Mail::Message::Body\n\n$obj->printEscapedFrom($fh)\nInherited, see \"Access to the payload\" in Mail::Message::Body\n\n$obj->string()\nInherited, see \"Access to the payload\" in Mail::Message::Body\n\n$obj->stripTrailingNewline()\nInherited, see \"Access to the payload\" in Mail::Message::Body\n\n$obj->write(%options)\nInherited, see \"Access to the payload\" in Mail::Message::Body\n"
                },
                {
                    "name": "Internals",
                    "content": "Extends \"Internals\" in Mail::Message::Body.\n\n$obj->addTransferEncHandler( $name, <$class|$object> )\nMail::Message::Body::Multipart->addTransferEncHandler( $name, <$class|$object> )\nInherited, see \"Internals\" in Mail::Message::Body::Encode\n\n$obj->contentInfoFrom($head)\nInherited, see \"Internals\" in Mail::Message::Body\n\n$obj->contentInfoTo($head)\nInherited, see \"Internals\" in Mail::Message::Body\n\n$obj->fileLocation( [$begin, $end] )\nInherited, see \"Internals\" in Mail::Message::Body\n\n$obj->getTransferEncHandler($type)\nInherited, see \"Internals\" in Mail::Message::Body::Encode\n\n$obj->isModified()\nInherited, see \"Internals\" in Mail::Message::Body\n\n$obj->load()\nInherited, see \"Internals\" in Mail::Message::Body\n\n$obj->modified( [BOOLEAN] )\nInherited, see \"Internals\" in Mail::Message::Body\n\n$obj->moveLocation( [$distance] )\nInherited, see \"Internals\" in Mail::Message::Body\n\n$obj->read( $parser, $head, $bodytype, [$chars, [$lines]] )\nInherited, see \"Internals\" in Mail::Message::Body\n"
                },
                {
                    "name": "Error handling",
                    "content": "Extends \"Error handling\" in Mail::Message::Body.\n\n$obj->AUTOLOAD()\nInherited, see \"Error handling\" in Mail::Message::Body\n\n$obj->addReport($object)\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->defaultTrace( [$level]|[$loglevel, $tracelevel]|[$level, $callback] )\nMail::Message::Body::Multipart->defaultTrace( [$level]|[$loglevel, $tracelevel]|[$level,\n$callback] )\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->errors()\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->log( [$level, [$strings]] )\nMail::Message::Body::Multipart->log( [$level, [$strings]] )\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->logPriority($level)\nMail::Message::Body::Multipart->logPriority($level)\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->logSettings()\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->notImplemented()\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->report( [$level] )\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->reportAll( [$level] )\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->trace( [$level] )\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->warnings()\nInherited, see \"Error handling\" in Mail::Reporter\n"
                },
                {
                    "name": "Cleanup",
                    "content": "Extends \"Cleanup\" in Mail::Message::Body.\n\n$obj->DESTROY()\nInherited, see \"Cleanup\" in Mail::Reporter\n"
                }
            ]
        },
        "DETAILS": {
            "content": "Extends \"DETAILS\" in Mail::Message::Body.\n",
            "subsections": []
        },
        "DIAGNOSTICS": {
            "content": "Warning: Charset $name is not known\nThe encoding or decoding of a message body encounters a character set which is not\nunderstood by Perl's Encode module.\n\nError: Data not convertible to a message (type is $type)\nAn object which is not coercable into a Mail::Message::Part object was passed to the\ninitiation. The data is ignored.\n\nWarning: No decoder defined for transfer encoding $name.\nThe data (message body) is encoded in a way which is not currently understood, therefore no\ndecoding (or recoding) can take place.\n\nWarning: No encoder defined for transfer encoding $name.\nThe data (message body) has been decoded, but the required encoding is unknown. The decoded\ndata is returned.\n\nError: Package $package does not implement $method.\nFatal error: the specific package (or one of its superclasses) does not implement this\nmethod where it should. This message means that some other related classes do implement this\nmethod however the class at hand does not. Probably you should investigate this and probably\ninform the author of the package.\n\nError: Unknown criterium $what to select parts.\nValid choices fdr part selections are \"ALL\", \"ACTIVE\", \"DELETED\", \"RECURSE\" or a code\nreference. However, some other argument was passed.\n\nWarning: Unknown line terminator $eol ignored\nError: You cannot use foreachLine on a multipart\nforeachLine() should be used on decoded message bodies only, because it would attempt to\nmodify part-headers and separators as well, which is clearly not acceptable.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "This module is part of Mail-Message distribution version 3.012, built on February 11, 2022.\nWebsite: http://perl.overmeer.net/CPAN/\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "Copyrights 2001-2022 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself. See http://dev.perl.org/licenses/\n",
            "subsections": []
        }
    },
    "summary": "Mail::Message::Body::Multipart - body of a message with attachments",
    "flags": [],
    "examples": [],
    "see_also": []
}