source: for-distributions/trunk/bin/windows/perl/lib/MIME/QuotedPrint.pm@ 14489

Last change on this file since 14489 was 14489, checked in by oranfry, 17 years ago

upgrading to perl 5.8

File size: 3.3 KB
Line 
1package MIME::QuotedPrint;
2
3# $Id: QuotedPrint.pm,v 3.7 2005/11/29 20:49:46 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.07";
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
53=item encode_qp($str, $eol, $binmode)
54
55This function returns an encoded version of the string ($str) given as
56argument.
57
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.
76
77=item decode_qp($str);
78
79This function returns the plain text version of the string given
80as argument. The lines of the result are "\n" terminated, even if
81the $str argument contains "\r\n" terminated lines.
82
83=back
84
85
86If you prefer not to import these routines into your namespace, you can
87call them as:
88
89 use MIME::QuotedPrint ();
90 $encoded = MIME::QuotedPrint::encode($decoded);
91 $decoded = MIME::QuotedPrint::decode($encoded);
92
93Perl v5.8 and better allow extended Unicode characters in strings.
94Such strings cannot be encoded directly, as the quoted-printable
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:
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
105=head1 COPYRIGHT
106
107Copyright 1995-1997,2002-2004 Gisle Aas.
108
109This library is free software; you can redistribute it and/or
110modify it under the same terms as Perl itself.
111
112=head1 SEE ALSO
113
114L<MIME::Base64>
115
116=cut
Note: See TracBrowser for help on using the repository browser.