encode_qp#

Encode a string as quoted-printable.

Synopsis#

$encoded = encode_qp($str);
$encoded = encode_qp($str, $eol);
$encoded = encode_qp($str, $eol, $binmode);

What you get back#

A scalar holding the quoted-printable encoding of $str. Printable ASCII bytes (plus \t) pass through unchanged; every other byte, and = itself, becomes a =XX triplet with uppercase hex digits. Lines are kept at most 76 characters by inserting soft breaks: a trailing = followed by the $eol sequence.

$eol defaults to "\n". Pass "\015\012" to produce output suitable for direct transmission over the wire. Pass "" to suppress soft breaks and force binary-mode behavior for \n.

$binmode, when true, encodes \n and \r as =0A / =0D rather than passing them through as line terminators. Use this when the decoded form must match the input byte for byte on every platform.

Examples#

use MIME::QuotedPrint;
print encode_qp("Hello, world!\n");       # Hello, world!\n
print encode_qp("caf\xe9\n");             # caf=E9\n
print encode_qp("\x00\x01\x02", "", 1);   # =00=01=02
print encode_qp("x" x 80 . "\n");         # wraps at col 75 with =\n soft break

Edge cases#

  • Empty $str returns the empty string.

  • $eol of "" disables soft line breaks and encodes every \n.

  • Trailing spaces and tabs on a line are always encoded so they survive transports that strip trailing whitespace.

Differences from upstream#

Fully compatible with upstream MIME::QuotedPrint 3.16.

See also#

  • decode_qp — reverse the encoding.

  • MIME::Base64::encode_base64 — better choice for fully binary data.