summaryrefslogtreecommitdiff
path: root/ext/MIME/Base64/QuotedPrint.pm
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-10-15 09:19:02 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-10-15 09:19:02 +0000
commit8be5f608f6696ee966fa295d23ecd0c1c2220447 (patch)
tree7ee42dd60ccc2fe510f47a06e71145d7544cafcf /ext/MIME/Base64/QuotedPrint.pm
parent7513c55b67d9e188cba73297143ae84a4902129b (diff)
downloadperl-8be5f608f6696ee966fa295d23ecd0c1c2220447.tar.gz
Update MIME::Base64 and Digest::MD5 from the CPAN version.
p4raw-id: //depot/perl@21451
Diffstat (limited to 'ext/MIME/Base64/QuotedPrint.pm')
-rw-r--r--ext/MIME/Base64/QuotedPrint.pm50
1 files changed, 40 insertions, 10 deletions
diff --git a/ext/MIME/Base64/QuotedPrint.pm b/ext/MIME/Base64/QuotedPrint.pm
index 663031fdbb..6988a8da27 100644
--- a/ext/MIME/Base64/QuotedPrint.pm
+++ b/ext/MIME/Base64/QuotedPrint.pm
@@ -1,5 +1,5 @@
#
-# $Id: QuotedPrint.pm,v 2.13 2003/05/13 18:22:09 gisle Exp $
+# $Id: QuotedPrint.pm,v 2.17 2003/10/09 19:04:29 gisle Exp $
package MIME::QuotedPrint;
@@ -34,13 +34,24 @@ The following functions are provided:
=item encode_qp($str, $eol)
This function will return an encoded version of the string given as
-argument. The second argument is the line ending sequence to use (it
-is optional and defaults to C<"\n">).
+argument.
+
+The second argument is the line ending sequence to use. It is
+optional and defaults to "\n". Every occurence of "\n" will be
+replaced with this string and it will also be used for additional
+"soft line breaks" to ensure that no line is longer than 76
+characters. You might want to pass it as "\015\012" to produce data
+suitable external consumption. The string "\r\n" will produce the
+same result on many platforms, but not all.
+
+An $eol of "" special. If passed no "soft line breaks" are introduced
+and any literal "\n" in the original data is encoded as well.
=item decode_qp($str);
This function will return the plain text version of the string given
-as argument. Lines with be "\n" terminated.
+as argument. The lines of the result will be "\n" terminated even it
+the $str argument contains "\r\n" terminated lines.
=back
@@ -52,6 +63,17 @@ call them as:
$encoded = MIME::QuotedPrint::encode($decoded);
$decoded = MIME::QuotedPrint::decode($encoded);
+Perl v5.6 and better allow extended Unicode characters in strings.
+Such strings cannot be encoded directly as the quoted-printable
+encoding is only defined for bytes. The solution is to use the Encode
+module to select the byte encoding you want. For example:
+
+ use MIME::QuotedPrint qw(encode_qp);
+ use Encode qw(encode);
+
+ $encoded = encode_qp(encode("UTF-8", "\x{FFFF}\n"));
+ print $encoded;
+
=head1 COPYRIGHT
Copyright 1995-1997,2002-2003 Gisle Aas.
@@ -59,6 +81,10 @@ Copyright 1995-1997,2002-2003 Gisle Aas.
This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
+=head1 SEE ALSO
+
+L<MIME::Base64>
+
=cut
use strict;
@@ -71,9 +97,7 @@ require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(encode_qp decode_qp);
-use Carp qw(croak);
-
-$VERSION = "2.20";
+$VERSION = "2.21";
use MIME::Base64; # try to load XS version of encode_qp
unless (defined &encode_qp) {
@@ -87,13 +111,15 @@ sub old_encode_qp ($;$)
if ($] >= 5.006) {
require bytes;
if (bytes::length($res) > length($res) ||
- ($] >= 5.008 && $res =~ /[^\0-\xFF]/)) {
- croak("The Quoted-Printable encoding is only defined for bytes");
+ ($] >= 5.008 && $res =~ /[^\0-\xFF]/))
+ {
+ require Carp;
+ Carp::croak("The Quoted-Printable encoding is only defined for bytes");
}
}
my $eol = shift;
- $eol = "\n" unless defined($eol) || length($eol);
+ $eol = "\n" unless defined $eol;
# Do not mention ranges such as $res =~ s/([^ \t\n!-<>-~])/sprintf("=%02X", ord($1))/eg;
# since that will not even compile on an EBCDIC machine (where ord('!') > ord('<')).
@@ -122,12 +148,15 @@ sub old_encode_qp ($;$)
}
else { # ASCII style machine
$res =~ s/([^ \t\n!"#\$%&'()*+,\-.\/0-9:;<>?\@A-Z[\\\]^_`a-z{|}~])/sprintf("=%02X", ord($1))/eg; # rule #2,#3
+ $res =~ s/\n/=0A/g unless length($eol);
$res =~ s/([ \t]+)$/
join('', map { sprintf("=%02X", ord($_)) }
split('', $1)
)/egm; # rule #3 (encode whitespace at eol)
}
+ return $res unless length($eol);
+
# rule #5 (lines must be shorter than 76 chars, but we are not allowed
# to break =XX escapes. This makes things complicated :-( )
my $brokenlines = "";
@@ -137,6 +166,7 @@ sub old_encode_qp ($;$)
|[^=\n] (?! [^=\n]{0,2} $) # 74 not followed by .?.?\n
| (?! [^=\n]{0,3} $) # 73 not followed by .?.?.?\n
))//xsm;
+ $res =~ s/\n\z/$eol/;
"$brokenlines$res";
}