-
Notifications
You must be signed in to change notification settings - Fork 935
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Mail | ||
module Encodings | ||
module UnixToUnix | ||
NAME = "x-uuencode" | ||
|
||
def self.decode(str) | ||
str.sub(/\Abegin \d+ [^\n]*\n/, '').unpack('u').first | ||
end | ||
|
||
def self.encode(str) | ||
[str].pack("u") | ||
end | ||
|
||
Encodings.register(NAME, self) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# encoding: utf-8 | ||
require 'spec_helper' | ||
|
||
describe Mail::Encodings::UnixToUnix do | ||
def decode(str) | ||
Mail::Encodings::UnixToUnix.decode(str) | ||
end | ||
|
||
def encode(str) | ||
Mail::Encodings::UnixToUnix.encode(str) | ||
end | ||
|
||
it "decodes" do | ||
text = strip_heredoc(<<-TEXT) | ||
begin 644 Happy.txt | ||
M2&%P<'D@=&]D87D@9F]R('1O(&)E(&]N92!O9B!P96%C92!A;F0@<V5R96YE | ||
'('1I;64N"@`` | ||
` | ||
end | ||
TEXT | ||
expect(decode(text)).to eq "Happy today for to be one of peace and serene time.\n" | ||
end | ||
|
||
it "encodes" do | ||
expect(encode("Happy today")).to eq "+2&%P<'D@=&]D87D`\n" | ||
end | ||
|
||
if RUBY_VERSION > "1.9" | ||
it "encodes / decodes non-ascii" do | ||
expect(encode("Happy ああr")).to eq "-2&%P<'D@XX&\"XX&\"<@``\n" | ||
expected = (RUBY_ENGINE == "jruby" ? "Happy ああr" : "Happy ああr".force_encoding("binary")) | ||
expect(decode("-2&%P<'D@XX&\"XX&\"<@``\n")).to eq expected | ||
end | ||
end | ||
|
||
it "can read itself" do | ||
expect(decode(encode("Happy today"))).to eq "Happy today" | ||
expect(encode(decode("+2&%P<'D@=&]D87D`\n"))).to eq "+2&%P<'D@=&]D87D`\n" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters