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