Upgrade to MIME::Base64 3.00.
[p5sagit/p5-mst-13.2.git] / ext / MIME / Base64 / QuotedPrint.pm
CommitLineData
6fba102d 1package MIME::QuotedPrint;
2
0a362e9d 3# $Id: QuotedPrint.pm,v 3.0 2004/01/14 11:59:07 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.00";
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
691d66bd 53This function returns an encoded version of the string given as
8be5f608 54argument.
55
691d66bd 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
8be5f608 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
691d66bd 61suitable for external consumption. The string "\r\n" produces the
8be5f608 62same result on many platforms, but not all.
63
691d66bd 64An $eol of "" (the empty string) is special. In this case, no "soft line breaks" are introduced
8be5f608 65and any literal "\n" in the original data is encoded as well.
6fba102d 66
67=item decode_qp($str);
68
691d66bd 69This function returns the plain text version of the string given
70as argument. The lines of the result are "\n" terminated, even if
8be5f608 71the $str argument contains "\r\n" terminated lines.
6fba102d 72
73=back
74
75
691d66bd 76If you prefer not to import these routines into your namespace, you can
6fba102d 77call them as:
78
79 use MIME::QuotedPrint ();
80 $encoded = MIME::QuotedPrint::encode($decoded);
81 $decoded = MIME::QuotedPrint::decode($encoded);
82
8be5f608 83Perl v5.6 and better allow extended Unicode characters in strings.
691d66bd 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
8be5f608 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
6fba102d 94=head1 COPYRIGHT
95
691d66bd 96Copyright 1995-1997,2002-2004 Gisle Aas.
6fba102d 97
98This library is free software; you can redistribute it and/or
99modify it under the same terms as Perl itself.
100
8be5f608 101=head1 SEE ALSO
102
103L<MIME::Base64>
104
6fba102d 105=cut