1 package MIME::QuotedPrint;
3 # $Id: QuotedPrint.pm,v 3.0 2004/01/14 11:59:07 gisle Exp $
6 use vars qw(@ISA @EXPORT $VERSION);
10 @EXPORT = qw(encode_qp decode_qp);
14 use MIME::Base64; # will load XS version of {en,de}code_qp()
16 *encode = \&encode_qp;
17 *decode = \&decode_qp;
25 MIME::QuotedPrint - Encoding and decoding of quoted-printable strings
29 use MIME::QuotedPrint;
31 $encoded = encode_qp($decoded);
32 $decoded = decode_qp($encoded);
36 This module provides functions to encode and decode strings into and from the
37 quoted-printable encoding specified in RFC 2045 - I<MIME (Multipurpose
38 Internet Mail Extensions)>. The quoted-printable encoding is intended
39 to represent data that largely consists of bytes that correspond to
40 printable characters in the ASCII character set. Each non-printable
41 character (as defined by English Americans) is represented by a
42 triplet consisting of the character "=" followed by two hexadecimal
45 The following functions are provided:
51 =item encode_qp($str, $eol)
53 This function returns an encoded version of the string given as
56 The second argument is the line-ending sequence to use. It is
57 optional and defaults to "\n". Every occurrence of "\n" is
58 replaced with this string, and it is also used for additional
59 "soft line breaks" to ensure that no line is longer than 76
60 characters. You might want to pass it as "\015\012" to produce data
61 suitable for external consumption. The string "\r\n" produces the
62 same result on many platforms, but not all.
64 An $eol of "" (the empty string) is special. In this case, no "soft line breaks" are introduced
65 and any literal "\n" in the original data is encoded as well.
67 =item decode_qp($str);
69 This function returns the plain text version of the string given
70 as argument. The lines of the result are "\n" terminated, even if
71 the $str argument contains "\r\n" terminated lines.
76 If you prefer not to import these routines into your namespace, you can
79 use MIME::QuotedPrint ();
80 $encoded = MIME::QuotedPrint::encode($decoded);
81 $decoded = MIME::QuotedPrint::decode($encoded);
83 Perl v5.6 and better allow extended Unicode characters in strings.
84 Such strings cannot be encoded directly, as the quoted-printable
85 encoding is only defined for single-byte characters. The solution is to use the Encode
86 module to select the byte encoding you want. For example:
88 use MIME::QuotedPrint qw(encode_qp);
89 use Encode qw(encode);
91 $encoded = encode_qp(encode("UTF-8", "\x{FFFF}\n"));
96 Copyright 1995-1997,2002-2004 Gisle Aas.
98 This library is free software; you can redistribute it and/or
99 modify it under the same terms as Perl itself.