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 @messages you handed it. The %options get 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 at Mail::Message::Body::Multipart first 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. Specify undef to 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 a STRING, it's matched to the beginning of the line, whereas a REGEX is a full regular expression. And with CODE, 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 by concatenate(). 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