Commit | Line | Data |
6fba102d |
1 | package MIME::QuotedPrint; |
2 | |
0a362e9d |
3 | # $Id: QuotedPrint.pm,v 3.0 2004/01/14 11:59:07 gisle Exp $ |
4 | |
5 | use strict; |
6 | use vars qw(@ISA @EXPORT $VERSION); |
7 | |
8 | require Exporter; |
9 | @ISA = qw(Exporter); |
10 | @EXPORT = qw(encode_qp decode_qp); |
11 | |
12 | $VERSION = "3.00"; |
13 | |
14 | use MIME::Base64; # will load XS version of {en,de}code_qp() |
15 | |
16 | *encode = \&encode_qp; |
17 | *decode = \&decode_qp; |
18 | |
19 | 1; |
20 | |
21 | __END__ |
22 | |
6fba102d |
23 | =head1 NAME |
24 | |
25 | MIME::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 |
36 | This module provides functions to encode and decode strings into and from the |
37 | quoted-printable encoding specified in RFC 2045 - I<MIME (Multipurpose |
38 | Internet Mail Extensions)>. The quoted-printable encoding is intended |
6fba102d |
39 | to represent data that largely consists of bytes that correspond to |
691d66bd |
40 | printable characters in the ASCII character set. Each non-printable |
41 | character (as defined by English Americans) is represented by a |
6fba102d |
42 | triplet consisting of the character "=" followed by two hexadecimal |
43 | digits. |
44 | |
45 | The 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 |
53 | This function returns an encoded version of the string given as |
8be5f608 |
54 | argument. |
55 | |
691d66bd |
56 | The second argument is the line-ending sequence to use. It is |
57 | optional and defaults to "\n". Every occurrence of "\n" is |
58 | replaced with this string, and it is also used for additional |
8be5f608 |
59 | "soft line breaks" to ensure that no line is longer than 76 |
60 | characters. You might want to pass it as "\015\012" to produce data |
691d66bd |
61 | suitable for external consumption. The string "\r\n" produces the |
8be5f608 |
62 | same result on many platforms, but not all. |
63 | |
691d66bd |
64 | An $eol of "" (the empty string) is special. In this case, no "soft line breaks" are introduced |
8be5f608 |
65 | and any literal "\n" in the original data is encoded as well. |
6fba102d |
66 | |
67 | =item decode_qp($str); |
68 | |
691d66bd |
69 | This function returns the plain text version of the string given |
70 | as argument. The lines of the result are "\n" terminated, even if |
8be5f608 |
71 | the $str argument contains "\r\n" terminated lines. |
6fba102d |
72 | |
73 | =back |
74 | |
75 | |
691d66bd |
76 | If you prefer not to import these routines into your namespace, you can |
6fba102d |
77 | call them as: |
78 | |
79 | use MIME::QuotedPrint (); |
80 | $encoded = MIME::QuotedPrint::encode($decoded); |
81 | $decoded = MIME::QuotedPrint::decode($encoded); |
82 | |
8be5f608 |
83 | Perl v5.6 and better allow extended Unicode characters in strings. |
691d66bd |
84 | Such strings cannot be encoded directly, as the quoted-printable |
85 | encoding is only defined for single-byte characters. The solution is to use the Encode |
8be5f608 |
86 | module 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 |
96 | Copyright 1995-1997,2002-2004 Gisle Aas. |
6fba102d |
97 | |
98 | This library is free software; you can redistribute it and/or |
99 | modify it under the same terms as Perl itself. |
100 | |
8be5f608 |
101 | =head1 SEE ALSO |
102 | |
103 | L<MIME::Base64> |
104 | |
6fba102d |
105 | =cut |