MIME::QuotedPrint#
Quoted-printable encoding and decoding as specified by RFC 2045.
Quoted-printable is the encoding of choice for mail bodies that are mostly ASCII with the occasional non-ASCII byte - long passages of plain text stay readable, and only the unsafe bytes turn into =XX hex triplets. For content that is truly binary, prefer base64 via MIME::Base64.
The encoder keeps lines at most 76 characters long by inserting soft line breaks (= at end of line, then the $eol sequence). Pass a $binmode flag when you want \n itself to be encoded - useful when the decoded output must be byte-for-byte identical regardless of the receiver’s line-ending conventions. An $eol of "" disables both soft breaks and \n rewriting.
The decoder always produces \n-terminated output, even when the input used \r\n line endings.
This is MIME::QuotedPrint from MIME-Base64 3.16_01; MIME/QuotedPrint.pm is upstream’s. encode_qp and decode_qp are exported by default.
Synopsis#
use MIME::QuotedPrint;
my $qp = encode_qp("caf\xe9 = coffee\n");
print $qp; # caf=E9 =3D coffee
print decode_qp($qp) eq "caf\xe9 = coffee\n" ? "round trip\n" : "";
print encode_qp('x' x 80); # 75 x's and "=", then "xxxxx=":
# text without a final newline ends in a soft break
Differences from upstream#
None: upstream’s tests pass unchanged (t/81-xs-native/MIME-Base64/230-upstream-quoted-print.t), and t/81-xs-native/MIME-QuotedPrint checks the rest against perl 5.44.
Functions#
Encoding and decoding#
encode_qp#
Encode a string as quoted-printable.
decode_qp#
Decode a quoted-printable string back to plain bytes.