Permalink
Browse files

Collapse adjacent =??B? words losslessly

Before this change the code assumed you could concatenate two Base64
strings, which is not true.

This fix relies on non-standard behaviour of our parser: RFC 2047 says
that encoded-words MUST be separated by at least a space, but we happily
parse two unseparated encoded-words.

Fixes: #560
Fixes: #561
Broken-since: 2.5.4 (cb81621)
  • Loading branch information...
1 parent 9f01ba9 commit b832faf6d05f85422dd921d3b97ed842436f22a8 @ConradIrwin ConradIrwin committed Jun 10, 2013
Showing with 6 additions and 1 deletion.
  1. +0 −1 lib/mail/encodings.rb
  2. +6 −0 spec/mail/encodings_spec.rb
View
@@ -292,7 +292,6 @@ def Encodings.collapse_adjacent_encodings(str)
if encoding == previous_encoding
line = results.pop + line
- line.gsub!(/\?\=\=\?.+?\?[QqBb]\?/m, '')
end
previous_encoding = encoding
@@ -154,6 +154,12 @@
Mail::Encodings.value_decode(string).should == string
end
+ it "should collapse adjacent words" do
+ string = "=?utf-8?B?0L3QvtCy0YvQuSDRgdC+0YLRgNGD0LTQvdC40Log4oCUINC00L7RgNC+0YQ=?=\n =?utf-8?B?0LXQtdCy?="
+ result = "новый сотрудник — дорофеев"
+ Mail::Encodings.value_decode(string).should == result
+ end
+
if '1.9'.respond_to?(:force_encoding)
it "should decode 8bit encoded string" do
string = "=?8bit?Q?ALPH=C3=89E?="

0 comments on commit b832faf

Please sign in to comment.