Mail::M...nstruct(3)
π NAME π
Mail::Message::Body::Construct β the page is Mail::M...nstruct(3) if you're squinting at your terminal, and what it does is adds functionality to Mail::Message::Body. That's it, that's the whole vibe. π
β¨ SYNOPSIS β¨
okay so there is literally nothing here. no synopsis. zero lines. the vibes are immaculate and empty π. moving on bestie.
πΈ DESCRIPTION πΈ
So this package adds complex functionality to the Mail::Message::Body class. It's the extra-sparkly stuff π.
Lowkey important though: this functions less often used, so many programs will not compile this package. Which means a bunch of your programs will just never compile it in the first place. Not a bug, it's a lifestyle β¨.
π METHODS π
π¦ Constructing a body π¦
$obj->attach(@messages, %options)β bestie, this makes a multipart containing this body plus the@messagesyou handed it. The%optionsget passed straight on to the constructor of the multi-part body. If you need more control than that, go build the multi-part body yourself, nobody's stopping you. At least take a look atMail::Message::Body::Multipartfirst though, iykyk π.
The message-parts will be coerced into a Mail::Message::Part, so you may attach Mail::Internet or MIME::Entity objects if you want --see Mail::Message::coerce(). What comes back at you is a new body with the attached messages. slay.
Β» example:
my $pgpkey = Mail::Message::Body::File->new(file => 'a.pgp');
my $msg = Mail::Message->buildFromBody($message->decoded->attach($pgpkey));
# The last message of the $multi multiparted body becomes a coerced $entity.
my $entity = MIME::Entity->new;
my $multi = $msg->body->attach($entity);
# Now create a new message
my $msg = Mail::Message->new(head => ..., body => $multi);
$obj->concatenate(@components)β this one concatenates the textual content of a LIST of elements into one shiny new body π«Ά. The resulting body object is based on the callee β and ngl, the callee may itself not be included in the result. So don't assume, okay?
You give it a list of text @components, and each component can be:
- a message (
Mail::Message, and the body of the message is what gets used), - a plain body (
Mail::Message::Body), undef(which will be skipped, we love a flaky friend),- a scalar (which is split into lines), or
- an array of scalars (each one providing a single line).
Β» example:
# all arguments are Mail::Message::Body's.
my $sum = $body->concatenate($preamble, $body, $epilogue, "-- \n" , $sig);
$obj->foreachLine(CODE)β makes a new body by performing an action on each of its lines β¨. If literally none of the lines change, the current body gets returned β no unnecessary copies, we're efficient here π . Otherwise a new body is created, of the same type as the current one.
The CODE is a subroutine that gets called, and inside it $_ contains the body's original line.
DO NOT CHANGE $_!!! π fr fr, hands off.
Whatever the routine returns is taken as the new line. And when the routine returns undef, that line gets skipped entirely.
Β» example:
my $content = $msg->decoded;
my $reply = $content->foreachLine( sub { '> '.$_ } );
my $rev = $content->foreachLine( sub { reverse } );
sub filled() { length $_ > 1 ? $_ : undef }
my $nonempty = $content->foreachLine( \&filled );
my $WRONG = $content->foreachLine( sub { s/a/A/ } );
my $right = $content->foreachLine( sub { s/a/A/r });
$obj->stripSignature(%options)β strips the signature off the body π. Real talk: the body must already be decoded, otherwise the wrong lines may get stripped. That's the messy part, bestie.
What you get back is the stripped version body, and in list context you also get the signature, wrapped up in its own little body object π«Ά. The signature separator is the first line of that returned signature body.
Context: the signature is the thing the sender adds to tell you about him- or herself π. It's superfluous in some situations β like, if you're writing a reply to someone's message, you genuinely do not need to drag their signature along with you.
And if the body had no signature at all? Then the original body object is returned, and undef comes back for the signature body. No drama.
-Option --Default
max_lines 10
pattern qr/^--\s?$/
result_type <same as current>
max_lines => INTEGER|undefβ the maximum number of lines that a signature is allowed to be. Specifyundefto remove the limit entirely. live your truth.pattern => REGEX|STRING|CODEβ which pattern defines the line that acts as the separator between the message and the signature. Here's the breakdown: with aSTRING, it's matched to the beginning of the line, whereas aREGEXis a full regular expression. And withCODE, each line (from last to front) gets passed to your subroutine as the first argument, and the subroutine must return TRUE when the separator is found.result_type => CLASSβ the type of body to be created for the stripped body (and maybe also to contain the stripped signature).
Β» example:
my $start = $message->decoded;
my $start = $body->decoded;
my $stripped = $start->stripSignature;
my ($stripped, $sign) = $start->stripSignature
(max_lines => 5, pattern => '-*-*-');
π DIAGNOSTICS π
- Error: cannot concatenate element
$whichβ cast byconcatenate(). yeah. it happened. π
π SEE ALSO π
This module is part of Mail-Message version 4.04, built on February 04, 2026. Website: http://perl.overmeer.net/CPAN/ β go peek, it's giving main character energy β¨.
π 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. periodt. π
and that's the whole page bestie π«Ά β this one came to you from perl v5.42.0 on 2026-02-05, mwah πβ¨
π¦ 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