Skip to content

Commit

Permalink
fixed an issue with long strings getting wrapped when using base64 en…
Browse files Browse the repository at this point in the history
…coding and thus causing issues with several mail clients
  • Loading branch information
Michael Reinsch committed Feb 8, 2012
1 parent 47e288e commit e33d949
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 1 addition & 3 deletions lib/mail/encodings.rb
Expand Up @@ -215,9 +215,7 @@ def Encodings.encode_non_usascii(address, charset)
def Encodings.b_value_encode(encoded_str, encoding = nil)
return encoded_str if encoded_str.to_s.ascii_only?
string, encoding = RubyVer.b_value_encode(encoded_str, encoding)
map_lines(string) do |str|
"=?#{encoding}?B?#{str.chomp}?="
end.join(" ")
"=?#{encoding}?B?#{map_lines(string) {|str| str.chomp }.join}?="
end

# Encode a string with Quoted-Printable Encoding and returns it ready to be inserted
Expand Down
11 changes: 6 additions & 5 deletions spec/mail/encodings_spec.rb
Expand Up @@ -111,15 +111,16 @@
end
end

it "should split the string up into bite sized chunks that can be wrapped easily" do
it "should not split the string up into bite sized chunks" do
string = "This is あ really long string This is あ really long string This is あ really long string This is あ really long string This is あ really long string"
expected = '=?UTF-8?B?VGhpcyBpcyDjgYIgcmVhbGx5IGxvbmcgc3RyaW5nIFRoaXMgaXMg44GCIHJlYWxseSBsb25nIHN0cmluZyBUaGlzIGlzIOOBgiByZWFsbHkgbG9uZyBzdHJpbmcgVGhpcyBpcyDjgYIgcmVhbGx5IGxvbmcgc3RyaW5nIFRoaXMgaXMg44GCIHJlYWxseSBsb25nIHN0cmluZw==?='

if RUBY_VERSION >= "1.9.1"
string = "This is あ really long string This is あ really long string This is あ really long string This is あ really long string This is あ really long string"
string = string.force_encoding('UTF-8')
Mail::Encodings.b_value_encode(string).should eq '=?UTF-8?B?VGhpcyBpcyDjgYIgcmVhbGx5IGxvbmcgc3RyaW5nIFRoaXMgaXMg44GCIHJl?= =?UTF-8?B?YWxseSBsb25nIHN0cmluZyBUaGlzIGlzIOOBgiByZWFsbHkgbG9uZyBzdHJp?= =?UTF-8?B?bmcgVGhpcyBpcyDjgYIgcmVhbGx5IGxvbmcgc3RyaW5nIFRoaXMgaXMg44GC?= =?UTF-8?B?IHJlYWxseSBsb25nIHN0cmluZw==?='
Mail::Encodings.b_value_encode(string).should eq expected
else
string = "This is あ really long string This is あ really long string This is あ really long string This is あ really long string This is あ really long string"
encoding = 'UTF-8'
Mail::Encodings.b_value_encode(string, encoding).should eq '=?UTF-8?B?VGhpcyBpcyDjgYIgcmVhbGx5IGxvbmcgc3RyaW5nIFRoaXMgaXMg44GCIHJl?= =?UTF-8?B?YWxseSBsb25nIHN0cmluZyBUaGlzIGlzIOOBgiByZWFsbHkgbG9uZyBzdHJp?= =?UTF-8?B?bmcgVGhpcyBpcyDjgYIgcmVhbGx5IGxvbmcgc3RyaW5nIFRoaXMgaXMg44GC?= =?UTF-8?B?IHJlYWxseSBsb25nIHN0cmluZw==?='
Mail::Encodings.b_value_encode(string, encoding).should expected
end
end

Expand Down

0 comments on commit e33d949

Please sign in to comment.