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