my Mail::Message $msg = ...; my $body = $msg->body; my @text = $body->lines; my $text = $body->string; my $file = $body->file; # IO::File $body->print(\*FILE); my $content_type = $body->type; my $transfer_encoding = $body->transferEncoding; my $encoded = $body->encode(mime_type => 'text/html', charset => 'us-ascii', transfer_encoding => 'none');\n"; my $decoded = $body->decoded;
See SYNOPSIS in Mail::Reporter
The encoding and decoding functionality of a Mail::Message::Body is implemented in the Mail::Message::Body::Encode package. That package is automatically loaded when encoding and decoding of messages needs to take place. Methods to simply build an process body objects are implemented in Mail::Message::Body::Construct.
The body of a message (a Mail::Message object) is stored in one of the many body types. The functionality of each body type is equivalent, but there are performance differences. Each body type has its own documentation with details about its implementation.
See DESCRIPTION in Mail::Reporter
A body can be contained in a message, but may also live without a message. In both cases it stores data, and the same questions can be asked: what type of data it is, how many bytes and lines, what encoding is used. Any body can be encoded and decoded, returning a new body object. However, bodies which are part of a message will always be in a shape that they can be written to a file or send to somewhere: they will be encoded if needed.
my $body = Mail::Message::Body::String->new(mime_type => 'image/gif'); $body->print(\*OUT); # this is binary image data... my $encoded = $message->body($body); $encoded->print(\*OUT); # ascii data, encoded image
Now encoded refers to the body of the $message
which is the content of
$body
in a shape that it can be transmitted. Usually base64
encoding
is used.
The body of a message can be stored in many ways. Roughtly, the implementations can be split in two groups: the data collectors and the complex bodies. The primer implement various ways to access data, and are full compatible: they only differ in performance and memory footprint under different circumstances. The latter are created to handle complex multiparts and lazy extraction.
The whole message body is stored in one scalar. Small messages can be contained this way without performance penalties.
Each line of the message body is stored as single scalar. This is a useful representation for a detailed look in the message body, which is usually line-organized.
The message body is stored in an external temporary file. This type of storage is especially useful when the body is large, the total folder is large, or memory is limited.
NOT IMPLEMENTED YET. The message is kept in the folder, and is only taken out when the content is changed.
NOT IMPLEMENTED YET.
The message is kept in a separate file, usually because the message body
is large. The difference with the ::External
object is that this external
storage stays this way between closing and opening of a folder. The
::External
object only uses a file when the folder is open.
The message-body is not yet read, but the exact location of the body is known so the message can be read when needed. This is part of the lazy extraction mechanism. Once extracted, the object can become any simple or complex body.
The message body contains a set of sub-messages (which can contain multipart bodies themselves). Each sub-message is an instance of Mail::Message::Part, which is an extension of Mail::Message.
Nested messages, like message/rfc822
: they contain a message in
the body. For most code, they simply behave like multiparts.