(stringification) Returns the body as string --which will trigger
completion-- unless called to produce a string for Carp
. The latter
to avoid deep recursions.
print $msg->body; # implicit by print my $body = $msg->body; my $x = "$body"; # explicit by interpolation
(numeric comparison) compares if two references point to the same message. This only produces correct results is both arguments are message references within the same folder.
my $skip = $folder->message(3); foreach my $msg (@$folder) { next if $msg == $skip; $msg->send; }
Always returns a true value, which is needed to have overloaded
objects to be used as in if($body)
. Otherwise, if(defined $body)
would be needed to avoid a runtime error.
See METHODS in Mail::Reporter
Return a copy of this body, usually to be included in a cloned message. Use Mail::Message::clone() for a whole message.
BE WARNED that, what you specify here are encodings and such which are already in place. The options will not trigger conversions. When you need conversions, first create a body with options which tell what you've got, and then call encode() for what you need.
Option | Defined in | Default |
---|---|---|
based_on | undef | |
charset |
| |
checked | <false> | |
content_id | undef | |
data | undef | |
description | undef | |
disposition | undef | |
eol |
| |
file | undef | |
log | Mail::Reporter |
|
message | undef | |
mime_type |
| |
modified | <false> | |
trace | Mail::Reporter |
|
transfer_encoding |
|
my $body = Mail::Message::Body::String->new(file => \*IN, mime_type => 'text/html; charset="ISO-8859-1"'); my $body = Mail::Message::Body::Lines->new(data => ['first', $second], charset => 'ISO-10646', transfer_encoding => 'none'); my $body = Mail::Message::Body::Lines->new(data => \@lines, transfer_encoding => 'base64'); my $body = Mail::Message::Body::Lines->new(file => 'picture.gif', mime_type => 'image/gif', content_id => '<12345@example.com>', disposition => 'inline');
Returns a body, an object which is (a sub-)class of a Mail::Message::Body, which contains a simplified representation of textual data. The returned object may be the object where this is called on, but may also be a new body of any type.
my $dec = $body->decoded;is equivalent with
my $dec = $body->encode ( mime_type => 'text/plain' , transfer_encoding => 'none' , charset => 'PERL' );
The $dec
which is returned is a body. Ask with the mimeType() method
what is produced. This $dec
body is not related to a header.
Option | Default |
---|---|
result_type | <same as current> |
Returns the character (or characters) which are used to separate lines within this body. When a kind of separator is specified, the body is translated to contain the specified line endings.
my $body = $msg->decoded->eol('NATIVE'); my $char = $msg->decoded->eol;
Returns a true or false value, depending on whether the body of this message has been read from file. This can only false for a Mail::Message::Body::Delayed.
Returns whether this message-body contains parts which are messages by themselves.
Only true for a message body which contains exactly one sub-message:
the Mail::Message::Body::Nested
body type.
Returns the message (or message part) where this body belongs to,
optionally setting it to a new MESSAGE first. If undef
is passed,
the body will be disconnected from the message.
Returns a string for multiparts and nested, otherwise an error. It is used in Mail::Message::partNumber().
Returns the character set which is used in the text body as string. This
is part of the result of what the type
method returns.
Returns whether the body encoding has been checked or not (optionally after setting the flag to a new value).
Returns (optionally after setting) the id (unique reference) of a
message part. The related header field is Content-ID
.
A Mail::Message::Field object is returned (which stringifies into
the field content). The field content will be none
if no disposition
was specified.
The argument can be a STRING (which is converted into a field), or a fully prepared header FIELD.
Returns (optionally after setting) the informal description of the body
content. The related header field is Content-Description
.
A Mail::Message::Field object is returned (which stringifies into
the field content). The field content will be none
if no disposition
was specified.
The argument can be a STRING (which is converted into a field), or a fully prepared header field.
Returns (optionally after setting) how the message can be disposed
(unpacked). The related header field is Content-Disposition
.
A Mail::Message::Field object is returned (which stringifies into
the field content). The field content will be none
if no disposition
was specified.
The argument can be a STRING (which is converted into a field), or a fully prepared header field.
Returns a MIME::Type object which is related to this body's type. This
differs from the type
method, which results in a Mail::Message::Field.
if($body->mimeType eq 'text/html') {...} print $body->mimeType->simplified;
Returns the number of lines in the message body. For multi-part messages, this includes the header lines and boundaries of all the parts.
The total number of bytes in the message body. The size of the body is computed in the shape it is in. For example, if this is a base64 encoded message, the size of the encoded data is returned; you may want to call Mail::Message::decoded() first.
Returns the transfer-encoding of the data within this body as
Mail::Message::Field (which stringifies to its content). If it
needs to be changed, call the encode() or decoded() method.
When no encoding is present, the field contains the text none
.
The optional STRING or FIELD enforces a new encoding to be set, without the actual required translations.
my $transfer = $msg->decoded->transferEncoding; $transfer->print; # --> Content-Encoding: base64 print $transfer; # --> base64 if($msg->body->transferEncoding eq 'none') {...}
Returns the type of information the body contains as
Mail::Message::Field object. The type is taken from the header
field Content-Type
. If the header did not contain that field,
then you will get a default field containing text/plain
.
You usually can better use mimeType(), because that will return a clever object with type information.
my $msg = $folder->message(6); $msg->get('Content-Type')->print; # --> Content-Type: text/plain; charset="us-ascii" my $content = $msg->decoded; my $type = $content->type; print "This is a $type message\n"; # --> This is a text/plain; charset="us-ascii" message print "This is a ", $type->body, "message\n"; # --> This is a text/plain message print "Comment: ", $type->comment, "\n"; # --> Comment: charset="us-ascii"
Returns whether the last line of the body is terminated by a new-line (in transport it will become a CRLF). An empty body will return true as well: the newline comes from the line before it.
Return the content of the body as a file handle. The returned stream may be a real file, or a simulated file in any form that Perl supports. While you may not be able to write to the file handle, you can read from it.
WARNING: Even if the file handle supports writing, do not write to the file handle. If you do, some of the internal values of the Mail::Message::Body may not be updated.
Return the content of the body as a list of lines (in LIST context) or a reference to an array of lines (in SCALAR context). In scalar context the array of lines is cached to avoid needless copying and therefore provide much faster access for large messages.
To just get the number of lines in the body, use the nrLines() method, which is usually much more efficient.
BE WARNED: For some types of bodies the reference will refer to the original data. You must not change the referenced data! If you do, some of the essential internal variables of the Mail::Message::Body may not be updated.
my @lines = $body->lines; # copies lines my $line3 = ($body->lines)[3] # only one copy print $lines[0]; my $linesref = $body->lines; # reference to originals my $line3 = $body->lines->[3] # only one copy (faster) print $linesref->[0]; print $body->[0]; # by overloading
Print the body to the specified FILEHANDLE (defaults to the selected handle).
The handle may be a GLOB, an IO::File object, or... any object with a
print()
method will do. Nothing useful is returned.
Print the body to the specified FILEHANDLE but all lines which start with 'From ' (optionally already preceded by >'s) will habe an > added in front. Nothing useful is returned.
Remove the newline from the last line, or the last line if it does not contain anything else than a newline.
Write the content of the body to a file. Be warned that you may want to decode the body before writing it!
Option | Default |
---|---|
filename | <required> |
use File::Temp; my $fn = tempfile; $message->decoded->write(filename => $fn) or die "Couldn't write to $fn: $!\n";
use File::Temp; my $dir = tempdir; mkdir $dir or die; my $fn = $message->body->dispositionFilename($dir); $message->decoded->write(filename => $fn) or die "Couldn't write to $fn: $!\n";
Transfer the body related info from the header into this body.
Copy the content information (the Content-*
fields) into the specified
HEAD. The body was created from raw data without the required information,
which must be added. See also contentInfoFrom().
The location of the body in the file. Returned a list containing begin and end. The begin is the offsets of the first byte if the folder used for this body. The end is the offset of the first byte of the next message.
Returns whether the body has changed.
Be sure that the body is loaded. This returns the loaded body.
Change the body modification flag. This will force a re-write of the body to a folder file when it is closed. It is quite dangerous to change the body: the same body may be shared between messages within your program.
Especially be warned that you have to change the message-id when you change the body of the message: no two messages should have the same id.
Without value, the current setting is returned, although you can better use isModified().
Move the registration of the message to a new location over DISTANCE. This is called when the message is written to a new version of the same folder-file.
Read the body with the PARSER from file. The implementation of this method will differ between types of bodies. The BODYTYPE argument is a class name or a code reference of a routine which can produce a class name, and is used in multipart bodies to determine the type of the body for each part.
The CHARS argument is the estimated number of bytes in the body, or
undef
when this is not known. This data can sometimes be derived from
the header (the Content-Length
line) or file-size.
The second argument is the estimated number of LINES of the body. It is less
useful than the CHARS but may be of help determining whether the message
separator is trustworthy. This value may be found in the Lines
field
of the header.
When an unknown method is called on a message body object, this may not be problematic. For performance reasons, some methods are implemented in separate files, and only demand-loaded. If this delayed compilation of additional modules does not help, an error will be produced.