Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fix mail reading: don't raise invalid byte sequence in UTF-8 when reading non-UTF-8 emails #347

Merged
merged 1 commit into from

8 participants

@mreinsch

recreated the pull request I did in #341 to fix #340. This version should also be fine with ruby 1.8.7 - if not, please adjust.

@bogdan

+1 for this.

Other mail clients(not based on ruby mail) like gmail displays such letters without telling that something is wrong. We should do the same.

@shingara

:+1: to merge it.

@sickill

+1

@tenderlove

bump?

@davesmylie

+1 to merge please =)

@mikel
Owner

Thanks, looks good. Merged.

@mikel mikel merged commit c7818a9 into mikel:master
@jeremy jeremy commented on the diff
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"
@jeremy Collaborator
jeremy added a note

This changes the encoding of its argument unexpectedly. Compare with value = value.dup.force_encoding('binary') or value = value.encode('binary')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 8, 2012
  1. @mreinsch
This page is out of date. Refresh to see the latest.
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"
@jeremy Collaborator
jeremy added a note

This changes the encoding of its argument unexpectedly. Compare with value = value.dup.force_encoding('binary') or value = value.encode('binary')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@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
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.