Browse files

git crlf at both ends

  • Loading branch information...
1 parent 91a3cf3 commit cfb5eb2b4095d413f0fa6c8576a7b628851863e9 @rjbs committed Apr 17, 2009
Showing with 19 additions and 11 deletions.
  1. +11 −6 lib/Email/MIME/Encodings.pm
  2. +8 −5 t/basic.t
View
17 lib/Email/MIME/Encodings.pm
@@ -18,8 +18,9 @@ sub codec {
my ($which, $how, $what) = @_;
$how = lc $how;
$how = "qp" if $how eq "quotedprint" or $how eq "quoted-printable";
- my $sub = $which."_".$how;
- if (not defined &$sub) {
+ my $sub = __PACKAGE__->can("$which\_$how");
+
+ unless ($sub) {
require Carp;
Carp::croak("Don't know how to $which $how");
}
@@ -40,11 +41,15 @@ sub codec {
# that the encoder should end lines with CRLF (since that's the email
# standard).
# -- rjbs and mkanat, 2009-04-16
- my $eol = "\015\012";
- if ($how eq 'qp') {
- $what =~ s/$eol/\012/sg;
+ my $eol = "\x0d\x0a";
+ if ($which eq 'encode') {
+ $what =~ s/$eol/\x0a/sg if $how eq 'qp';
+ return $sub->($what, $eol);
+ } else {
+ my $txt = $sub->($what);
+ $txt =~ s/\x0a/$eol/sg if $how eq 'qp';
+ return $txt;
}
- $sub->($what, $eol);
}
sub decode { return codec("decode", @_) }
View
13 t/basic.t
@@ -1,17 +1,20 @@
use Test::More tests => 12;
use_ok("Email::MIME::Encodings");
-my $x = "This is a test\nof various MIME=stuff.";
+my $CRLF = "\x0d\x0a";
+my $x = "This is a test${CRLF}of various MIME=stuff.";
for (qw(binary 7bit 8bit)) {
is(Email::MIME::Encodings::encode($_, $x), $x, "enc $_");
is(Email::MIME::Encodings::decode($_, $x), $x, "dec $_");
}
-$y= "This is a test\nof various MIME=3Dstuff.=\n";
-is(Email::MIME::Encodings::encode(quotedprint => $x), $y, "enc qp");
-is(Email::MIME::Encodings::decode(quotedprint => $y), $x, "dec qp");
+$y = "This is a test${CRLF}of various MIME=3Dstuff.=${CRLF}";
+is_binary(Email::MIME::Encodings::encode(quotedprint => $x), $y, "enc qp");
+is_binary(Email::MIME::Encodings::decode(quotedprint => $y), $x, "dec qp");
-$z="VGhpcyBpcyBhIHRlc3QKb2YgdmFyaW91cyBNSU1FPXN0dWZmLg==\n";
+use Test::BinaryData;
+
+$z = "VGhpcyBpcyBhIHRlc3QNCm9mIHZhcmlvdXMgTUlNRT1zdHVmZi4=${CRLF}";
is(Email::MIME::Encodings::encode(base64 => $x), $z, "enc 64");
is(Email::MIME::Encodings::decode(base64 => $z), $x, "dec 64");

0 comments on commit cfb5eb2

Please sign in to comment.