As we're not passing over (or copying in) a NUL, don't need that extra
[p5sagit/p5-mst-13.2.git] / ext / MIME / Base64 / QuotedPrint.pm
CommitLineData
6fba102d 1package MIME::QuotedPrint;
2
4e2e3d15 3# $Id: QuotedPrint.pm,v 3.7 2005/11/29 20:49:46 gisle Exp $
0a362e9d 4
5use strict;
6use vars qw(@ISA @EXPORT $VERSION);
7
8require Exporter;
9@ISA = qw(Exporter);
10@EXPORT = qw(encode_qp decode_qp);
11
4e2e3d15 12$VERSION = "3.07";
0a362e9d 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
6fba102d 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
691d66bd 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
6fba102d 39to represent data that largely consists of bytes that correspond to
691d66bd 40printable characters in the ASCII character set. Each non-printable
41character (as defined by English Americans) is represented by a
6fba102d 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
6a63fb82 51=item encode_qp($str, $eol)
6fba102d 52
9e87bee3 53=item encode_qp($str, $eol, $binmode)
8be5f608 54
9e87bee3 55This function returns an encoded version of the string ($str) given as
56argument.
8be5f608 57
9e87bee3 58The second argument ($eol) is the line-ending sequence to use. It is
59optional and defaults to "\n". Every occurrence of "\n" is replaced
60with this string, and it is also used for additional "soft line
61breaks" to ensure that no line end up longer than 76 characters. Pass
62it as "\015\012" to produce data suitable for external consumption.
63The string "\r\n" produces the same result on many platforms, but not
64all.
65
66The third argument ($binmode) will select binary mode if passed as a
67TRUE value. In binary mode "\n" will be encoded in the same way as
68any other non-printable character. This ensures that a decoder will
69end up with exactly the same string whatever line ending sequence it
70uses. In general it is preferable to use the base64 encoding for
71binary data; see L<MIME::Base64>.
72
73An $eol of "" (the empty string) is special. In this case, no "soft
74line breaks" are introduced and binary mode is effectively enabled so
75that any "\n" in the original data is encoded as well.
6fba102d 76
77=item decode_qp($str);
78
691d66bd 79This function returns the plain text version of the string given
80as argument. The lines of the result are "\n" terminated, even if
8be5f608 81the $str argument contains "\r\n" terminated lines.
6fba102d 82
83=back
84
85
691d66bd 86If you prefer not to import these routines into your namespace, you can
6fba102d 87call them as:
88
89 use MIME::QuotedPrint ();
90 $encoded = MIME::QuotedPrint::encode($decoded);
91 $decoded = MIME::QuotedPrint::decode($encoded);
92
e1839706 93Perl v5.8 and better allow extended Unicode characters in strings.
691d66bd 94Such strings cannot be encoded directly, as the quoted-printable
e1839706 95encoding is only defined for single-byte characters. The solution is
96to use the Encode module to select the byte encoding you want. For
97example:
8be5f608 98
99 use MIME::QuotedPrint qw(encode_qp);
100 use Encode qw(encode);
101
102 $encoded = encode_qp(encode("UTF-8", "\x{FFFF}\n"));
103 print $encoded;
104
6fba102d 105=head1 COPYRIGHT
106
691d66bd 107Copyright 1995-1997,2002-2004 Gisle Aas.
6fba102d 108
109This library is free software; you can redistribute it and/or
110modify it under the same terms as Perl itself.
111
8be5f608 112=head1 SEE ALSO
113
114L<MIME::Base64>
115
6fba102d 116=cut