Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fix for invalid byte sequence in UTF-8 (ArgumentError) #341

Closed
wants to merge 5 commits into from
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -1,5 +1,4 @@
.bundle
-Gemfile.lock
coverage
gems
/mail-*.gem
View
34 Gemfile.lock
@@ -0,0 +1,34 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activesupport (3.2.1)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ diff-lcs (1.1.3)
+ i18n (0.6.0)
+ mime-types (1.17.2)
+ multi_json (1.0.4)
+ polyglot (0.3.3)
+ rake (0.9.2.2)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.8.0)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ rake (> 0.8.7)
+ rspec (~> 2.8.0)
+ treetop (~> 1.4.10)
View
4 lib/mail/encodings.rb
@@ -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
View
1  lib/mail/message.rb
@@ -1884,6 +1884,7 @@ def parse_message
end
def raw_source=(value)
+ value.force_encoding("binary") if RUBY_VERSION >= "1.9.1"
@raw_source = value.to_crlf
end
View
10 spec/fixtures/emails/multi_charset/japanese_shiftjis.eml
@@ -0,0 +1,10 @@
+MIME-Version: 1.0
+Subject: =?UTF-8?B?44G+44G/44KA44KB44KC?=
+From: Mikel Lindsaar <raasdnil@gmail.com>
+To: =?UTF-8?B?44G/44GR44KL?= <raasdnil@gmail.com>
+Content-Type: text/plain;
+ charset=iso-2022-jp
+Content-Transfer-Encoding: 7bit
+
+$B$9$_$^$;$s!#(B
+
View
11 spec/mail/encodings_spec.rb
@@ -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
View
6 spec/mail/message_spec.rb
@@ -292,6 +292,12 @@ def basic_email
mail.to.should eq ["tester2@test.com"]
end
+ it "should parse non-UTF8 sources" do
+ mail = Mail::Message.new(File.read(fixture('emails', 'multi_charset', 'japanese_shiftjis.eml')))
+ mail.to.should eq ["raasdnil@gmail.com"]
+ body_text = mail.body.decoded.force_encoding("iso-2022-jp").encode("UTF-8")
+ body_text.should eq "すみません。"
+ end
end
describe "directly setting values of a message" do
Something went wrong with that request. Please try again.