Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
git crlf at both ends
  • Loading branch information
rjbs committed Apr 17, 2009
1 parent 91a3cf3 commit cfb5eb2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
17 changes: 11 additions & 6 deletions lib/Email/MIME/Encodings.pm
Expand Up @@ -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");
}
Expand All @@ -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", @_) }
Expand Down
13 changes: 8 additions & 5 deletions 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");

Expand Down

0 comments on commit cfb5eb2

Please sign in to comment.