Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

invalid byte sequence in UTF-8 (ArgumentError) #340

Closed
mreinsch opened this Issue · 7 comments

7 participants

Michael Reinsch Cyril Mougel Dave Smylie Ryan Bigg Kizashi Nagata Benjamin Fleischer Jeremy Kemper
Michael Reinsch

With rails 3.2.1, mail 2.4.1, trying to process an email coming in in Shift-JIS encoding:

invalid byte sequence in UTF-8 (ArgumentError)
from ruby/1.9.1/gems/mail-2.4.1/lib/mail/core_extensions/string.rb:4:in `to_crlf'  
from ruby/1.9.1/gems/mail-2.4.1/lib/mail/message.rb:1886:in `raw_source='  
from ruby/1.9.1/gems/mail-2.4.1/lib/mail/message.rb:2005:in `init_with_string'  
from ruby/1.9.1/gems/mail-2.4.1/lib/mail/message.rb:125:in `initialize'  
from ruby/1.9.1/gems/mail-2.4.1/lib/mail/mail.rb:50:in `new'  
from ruby/1.9.1/gems/mail-2.4.1/lib/mail/mail.rb:50:in `new'  
from ruby/1.9.1/bundler/gems/rails-1c5bd8a33dd7/actionmailer/lib/action_mailer/base.rb:401:in `block in receive
Michael Reinsch

this seems to avoid the exception:

diff --git a/lib/mail/message.rb b/lib/mail/message.rb
index c6f58a4..1740dfc 100644
--- a/lib/mail/message.rb
+++ b/lib/mail/message.rb
@@ -1884,7 +1884,7 @@ module Mail
     end

     def raw_source=(value)
-      @raw_source = value.to_crlf
+      @raw_source = value.force_encoding("binary").to_crlf
     end

     # see comments to body=. We take data and process it lazily
Cyril Mougel

:+1: It's works fine :) the pull request #347

Dave Smylie

This is still an issue for me in 2.4.4 - the patch from mreinsch works for me

Ryan Bigg

@mikel if #347 is fixed, I think this is fixed now.

Jeremy Kemper jeremy closed this
Kizashi Nagata

Now I am using mail-2.6.1.

Mail.read("shiftjis.eml") is ok.
But the error is still reproducible only when using Mail.new(STDIN.read).

By the way, https://github.com/mikel/mail/blob/master/spec/fixtures/emails/multi_charset/japanese_shiftjis.eml
is NOT Shift-JIS email. It is an ISO-2022-JP (JIS) mail. They are both japanese charset but different charset.

If you want to get a shiftjis email, please let me know.

Benjamin Fleischer
Collaborator
bf4 commented

@kizashi1122 would you open an issue with your ruby version, ruby engine, and a failing test, please?

Kizashi Nagata

I have opened #736

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.