1package MIME::QuotedPrint;
2
3# $Id: QuotedPrint.pm,v 3.1 2004/03/29 11:55:49 gisle Exp $
4
5use strict;
6use vars qw(@ISA @EXPORT $VERSION);
7
8require Exporter;
9@ISA = qw(Exporter);
10@EXPORT = qw(encode_qp decode_qp);
11
12$VERSION = "3.01";
13
14use MIME::Base64;  # will load XS version of {en,de}code_qp()
15
16*encode = \&encode_qp;
17*decode = \&decode_qp;
18
191;
20
21__END__
22
23=head1 NAME
24
25MIME::QuotedPrint - Encoding and decoding of quoted-printable strings
26
27=head1 SYNOPSIS
28
29 use MIME::QuotedPrint;
30
31 $encoded = encode_qp($decoded);
32 $decoded = decode_qp($encoded);
33
34=head1 DESCRIPTION
35
36This module provides functions to encode and decode strings into and from the
37quoted-printable encoding specified in RFC 2045 - I<MIME (Multipurpose
38Internet Mail Extensions)>.  The quoted-printable encoding is intended
39to represent data that largely consists of bytes that correspond to
40printable characters in the ASCII character set.  Each non-printable
41character (as defined by English Americans) is represented by a
42triplet consisting of the character "=" followed by two hexadecimal
43digits.
44
45The following functions are provided:
46
47=over 4
48
49=item encode_qp($str)
50
51=item encode_qp($str, $eol)
52
53This function returns an encoded version of the string given as
54argument.
55
56The second argument is the line-ending sequence to use.  It is
57optional and defaults to "\n".  Every occurrence of "\n" is
58replaced with this string, and it is also used for additional
59"soft line breaks" to ensure that no line is longer than 76
60characters.  You might want to pass it as "\015\012" to produce data
61suitable for external consumption.  The string "\r\n" produces the
62same result on many platforms, but not all.
63
64An $eol of "" (the empty string) is special.  In this case, no "soft line breaks" are introduced
65and any literal "\n" in the original data is encoded as well.
66
67=item decode_qp($str);
68
69This function returns the plain text version of the string given
70as argument.  The lines of the result are "\n" terminated, even if
71the $str argument contains "\r\n" terminated lines.
72
73=back
74
75
76If you prefer not to import these routines into your namespace, you can
77call them as:
78
79  use MIME::QuotedPrint ();
80  $encoded = MIME::QuotedPrint::encode($decoded);
81  $decoded = MIME::QuotedPrint::decode($encoded);
82
83Perl v5.6 and better allow extended Unicode characters in strings.
84Such strings cannot be encoded directly, as the quoted-printable
85encoding is only defined for single-byte characters.  The solution is to use the Encode
86module to select the byte encoding you want.  For example:
87
88    use MIME::QuotedPrint qw(encode_qp);
89    use Encode qw(encode);
90
91    $encoded = encode_qp(encode("UTF-8", "\x{FFFF}\n"));
92    print $encoded;
93
94=head1 COPYRIGHT
95
96Copyright 1995-1997,2002-2004 Gisle Aas.
97
98This library is free software; you can redistribute it and/or
99modify it under the same terms as Perl itself.
100
101=head1 SEE ALSO
102
103L<MIME::Base64>
104
105=cut
106