1 package MIME::QuotedPrint;
4 use vars qw(@ISA @EXPORT $VERSION);
8 @EXPORT = qw(encode_qp decode_qp);
12 use MIME::Base64; # will load XS version of {en,de}code_qp()
14 *encode = \&encode_qp;
15 *decode = \&decode_qp;
23 MIME::QuotedPrint - Encoding and decoding of quoted-printable strings
27 use MIME::QuotedPrint;
29 $encoded = encode_qp($decoded);
30 $decoded = decode_qp($encoded);
34 This module provides functions to encode and decode strings into and from the
35 quoted-printable encoding specified in RFC 2045 - I<MIME (Multipurpose
36 Internet Mail Extensions)>. The quoted-printable encoding is intended
37 to represent data that largely consists of bytes that correspond to
38 printable characters in the ASCII character set. Each non-printable
39 character (as defined by English Americans) is represented by a
40 triplet consisting of the character "=" followed by two hexadecimal
43 The following functions are provided:
49 =item encode_qp($str, $eol)
51 =item encode_qp($str, $eol, $binmode)
53 This function returns an encoded version of the string ($str) given as
56 The second argument ($eol) is the line-ending sequence to use. It is
57 optional and defaults to "\n". Every occurrence of "\n" is replaced
58 with this string, and it is also used for additional "soft line
59 breaks" to ensure that no line end up longer than 76 characters. Pass
60 it as "\015\012" to produce data suitable for external consumption.
61 The string "\r\n" produces the same result on many platforms, but not
64 The third argument ($binmode) will select binary mode if passed as a
65 TRUE value. In binary mode "\n" will be encoded in the same way as
66 any other non-printable character. This ensures that a decoder will
67 end up with exactly the same string whatever line ending sequence it
68 uses. In general it is preferable to use the base64 encoding for
69 binary data; see L<MIME::Base64>.
71 An $eol of "" (the empty string) is special. In this case, no "soft
72 line breaks" are introduced and binary mode is effectively enabled so
73 that any "\n" in the original data is encoded as well.
75 =item decode_qp($str);
77 This function returns the plain text version of the string given
78 as argument. The lines of the result are "\n" terminated, even if
79 the $str argument contains "\r\n" terminated lines.
84 If you prefer not to import these routines into your namespace, you can
87 use MIME::QuotedPrint ();
88 $encoded = MIME::QuotedPrint::encode($decoded);
89 $decoded = MIME::QuotedPrint::decode($encoded);
91 Perl v5.8 and better allow extended Unicode characters in strings.
92 Such strings cannot be encoded directly, as the quoted-printable
93 encoding is only defined for single-byte characters. The solution is
94 to use the Encode module to select the byte encoding you want. For
97 use MIME::QuotedPrint qw(encode_qp);
98 use Encode qw(encode);
100 $encoded = encode_qp(encode("UTF-8", "\x{FFFF}\n"));
105 Copyright 1995-1997,2002-2004 Gisle Aas.
107 This library is free software; you can redistribute it and/or
108 modify it under the same terms as Perl itself.