MIME::QUOTEDPRINT(3perl)

🌸 NAME 🌸

MIME::QuotedPrint β€” encoding and decoding of quoted-printable strings πŸ¦‹

Like, it's the module you pull up when you need to turn regular strings into quoted-printable and back again. That's the whole assignment, bestie.


✨ SYNOPSIS ✨

 use MIME::QuotedPrint;

 $encoded = encode_qp($decoded);
 $decoded = decode_qp($encoded);

πŸ’– DESCRIPTION πŸ’–

okay so real talk: this module hands you the functions that encode and decode strings into and from the quoted-printable encoding β€” the one specified in RFC 2045 - MIME (Multipurpose Internet Mail Extensions). No cap.

Quoted-printable is specifically designed to represent data that's mostly made of bytes corresponding to printable characters in the ASCII character set. And every single non-printable character (as defined by English Americans, iconic of them tbh) gets represented as a triplet made of the character "=" followed by two hexadecimal digits. It's giving escape sequence but make it email-safe. πŸ’€

Here's everything the module serves up:

🌈 encode_qp( $str)

🌈 encode_qp( $str, $eol)

🌈 encode_qp( $str, $eol, $binmode )

This function returns an encoded version of the string ($str) you gave it as an argument. Main character energy, fr fr.

  • $eol β€” the second argument, and it's the line-ending sequence to use. It's optional and defaults to "\n". Every occurrence of "\n" gets replaced with this string, and it's also used for extra "soft line breaks" so that no line ends up longer than 76 characters. Pass it as "\015\012" when you want to produce data suitable for external consumption. The string "\r\n" produces the same result on many platforms β€” but not all, so don't come for me. πŸ™ˆ
  • $binmode β€” the third argument, and it selects binary mode if you pass it as a TRUE value. In binary mode, "\n" gets encoded in the same way as any other non-printable character. Why do you care? Because that ensures a decoder will end up with exactly the same string whatever line ending sequence it uses. In general it is preferable to use the base64 encoding for binary data; see MIME::Base64. (yes that's the vibe check πŸ’…)
An $eol of "" (the empty string) is special, bestie. In this case, no "soft line breaks" are introduced and binary mode is effectively enabled, so that any "\n" in the original data is encoded as well. Special little creature. 🧚

🌈 decode_qp( $str )

This function returns the plain text version of the string you passed as an argument. Heads up though: the lines of the result are "\n" terminated, even if the $str argument contains "\r\n" terminated lines. It normalises. Periodt.


If you prefer not to import these routines into your namespace (respect, honestly), you can call them as:

  use MIME::QuotedPrint ();
  $encoded = MIME::QuotedPrint::encode($decoded);
  $decoded = MIME::QuotedPrint::decode($encoded);

Perl v5.8 and better allow extended Unicode characters in strings. And here's the catch 😭 such strings cannot be encoded directly, because the quoted-printable encoding is only defined for single-byte characters. The solution is to use the Encode module to select the byte encoding you want. For example:

    use MIME::QuotedPrint qw(encode_qp);
    use Encode qw(encode);

    $encoded = encode_qp(encode("UTF-8", "\x{FFFF}\n"));
    print $encoded;

Copyright 1995-1997,2002-2004 Gisle Aas.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


πŸ¦‹ SEE ALSO πŸ¦‹

MIME::Base64


and that's the page!! πŸ’– written for perl v5.44.0, dated 2026-10-17 β€” slay, go encode something gorgeous, ily 🫢✨

πŸ“¦ where this page comes from
  • arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms