Mail::Message::Body::Encode
organize general message encodings
- Provided by: libmail-message-perl (Version: 4.03-1)
- Report a bug
organize general message encodings
my Mail::Message $msg = ...;
my $decoded = $msg->decoded;
my $encoded = $msg->encode(mime_type => 'image/gif',
transfer_encoding => 'base64');
my $body = $msg->body;
my $decoded = $body->decoded;
my $encoded = $body->encode(transfer_encoding => '7bit');
Manages the message's body encodings and decodings on request of the main program. This package adds functionality to the Mail::Message::Body class when the decoded() or encode() method is called.
Four types of encodings are handled (in the right order)
Various operating systems have different ideas about how to encode the line termination. UNIX uses a LF character, MacOS uses a CR, and Windows uses a CR/LF combination. Messages which are transported over Internet will always use the CRLF separator.
Messages transmitted over Internet have to be plain ASCII. Complicated characters and binary files (like images and archives) must be encoded during transmission to an ASCII representation.
The implementation of the required encoders and decoders is found in the Mail::Message::TransferEnc set of packages. The related manual page lists the transfer encodings which are supported.
NOT IMPLEMENTED YET
When you call this method with an explicit "undef", you reset the default. (Without parameter) the current algorithm ("CODE" or method name) is returned.
-Option --Default
external <C<false>>
A body is returned which is checked. This may be the body where this method is called upon, but also a new object, when serious changes had to be made. If the check could not be made, because the decoder is not defined, then "undef" is returned.
-Option --Default
charset PERL
charset_detect <built-in>
mime_type undef
result_type <same as source>
transfer_encoding undef
If the CHARSET is explicitly specified (for instance "iso-8859-10", then the data is being interpreted as raw bytes (blob), not as text. However, in case of "PERL", it is considered to be an internal representation of characters (either latin1 or Perl's utf8 --not the same as utf-8--, you should not want to know).
This setting overrules the charset attribute in the mime_type FIELD.
When you want to be smarter than the default charset detector, you can provide your own function for this parameter. The function will get the transfer-decoded version of this body. You can change the default globally via charsetDetectAlgorithm().
The FIELD may contain attributes. Usually, it has a "charset" attribute, which explains the CHARSET of the content after content transfer decoding. The "charset" option will update/add this attribute. Otherwise (hopefully in rare cases) the CHARSET will be auto-detected when the body gets decoded.
-Option --Default
charset_detect <the default>
» example:
my $body = $msg->decoded->eol('NATIVE');
my $char = $msg->decoded->eol;
Examples:
my $bodytype = Mail::Message::Body::Lines;
my $html = $bodytype->new(mime_type=>'text/html', data => []);
my $plain = $bodytype->new(mime_type=>'text/plain', ...);
my $unified = $html->unify($plain);
# $unified is the data of plain translated to html (if possible).
When a $directory is given, a filename is composed. For security reasons, only the basename of the found name gets used and many potentially dangerous characters removed. If no name was found, or when the found name is already in use, then an unique name is generated.
Don't forget to read RFC6266 section 4.3 for the security aspects in your email application.
The $class or $object must extend Mail::Message::TransferEnc. It will replace existing class and object for this $name.
Why aren't you contributing this class to MailBox?
This module is part of Mail-Message version 4.03, built on January 26, 2026. Website: http://perl.overmeer.net/CPAN/
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.