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