my Mail::Message $msg = ...; my $decoded = $msg->decoded; my $encoded = $msg->encode(transfer => 'base64');
See SYNOPSIS in Mail::Message::TransferEnc
Encode or decode message bodies with base64. The e-mail protocol and user agents can not handle binary data. Therefore, binary data -but even sometimes non-binary data- is encoded into ASCII, this is transportable.
Base64 re-groups the bits of bytes, and maps them on characters. The
data contains bytes of 8 bits (an octet). These are repacked into
groups of 6 bits, pointing in an array of characters containing
[A-Za-z0-9+/]
. This way, three data bytes become 4 base64 bytes.
The encoded data will be trailed by '='
characters to align on
four bytes.