Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid byte sequence in US-ASCII (ArgumentError) #147

Closed
Baysen opened this issue Jul 9, 2014 · 12 comments
Closed

invalid byte sequence in US-ASCII (ArgumentError) #147

Baysen opened this issue Jul 9, 2014 · 12 comments

Comments

@Baysen
Copy link

Baysen commented Jul 9, 2014

Hey there,

before I start, I usually have nothing to do with ruby, so I only have a very crude idea about what's going on here.

I installed mailcatcher onto my development machine which runs Unbuntu Server 12.04 with ruby 2.0.0p247. It runs perfectly, Web interface is visible and a simple test mail from php mail function arrived ok.

Now the problem seems to start when I try to send mails with UTF-8 encoding. PHP error.log giving me the following:

/usr/local/lib/ruby/gems/2.0.0/gems/mail-2.6.1/lib/mail/core_extensions/string.rb:14:in 'gsub': invalid byte sequence in US-ASCII (ArgumentError)
        from /usr/local/lib/ruby/gems/2.0.0/gems/mail-2.6.1/lib/mail/core_extensions/string.rb:14:in 'to_crlf'
        from /usr/local/lib/ruby/gems/2.0.0/gems/mail-2.6.1/lib/mail/message.rb:1983:in 'raw_source='
        from /usr/local/lib/ruby/gems/2.0.0/gems/mail-2.6.1/lib/mail/message.rb:2108:in 'init_with_string'
        from /usr/local/lib/ruby/gems/2.0.0/gems/mail-2.6.1/lib/mail/message.rb:128:in 'initialize'
        from /usr/local/lib/ruby/gems/2.0.0/gems/mail-2.6.1/lib/mail/mail.rb:50:in 'new'
        from /usr/local/lib/ruby/gems/2.0.0/gems/mail-2.6.1/lib/mail/mail.rb:50:in 'new'
        from /usr/local/lib/ruby/gems/2.0.0/gems/mailcatcher-0.5.12/bin/catchmail:48:in '<top (required)>'
        from /usr/local/bin/catchmail:23:in 'load'
        from /usr/local/bin/catchmail:23:in '<main>'

Without the additional header for encoding everything seems to work. Is there maybe an issue with the version of ruby that is installed?

Can somebody point me in the right direction? I really love the tool.

Thank you!

@attachmentgenie
Copy link

you seem to have hit this problem => http://www.sandelman.ca/mcr/blog/2012/07/09/

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
gem install mailcatcher

should do the trick

@Baysen
Copy link
Author

Baysen commented Jul 10, 2014

Thank you for your quick answer :)

Sadly, it doesn't seem to change anything. I've tried en_US.UTF-8, my correct locale de_DE.UTF-8 and a few variations locale -a was giving me, but nothing changed the error.

As I understand the error message, a core extension named mail is failing, do I maybe need to reinstall anything else?

For reference, locale -a output:

C.UTF-8
de_AT.utf8
de_BE.utf8
de_CH.utf8
de_DE.utf8
de_LI.utf8
de_LU.utf8
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IN
en_IN.utf8
en_NG
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZM
en_ZM.utf8
en_ZW.utf8
POSIX

Thanks again!

@joetjen
Copy link

joetjen commented Jul 22, 2014

Looks like I have the same issue. I have a squeeze based vm in which I use RVM multi-user to install mailcatcher. Running catchmail manually and from within a simple PHP script it works all fine, but from within Drupal (which I unfortunately have to deal with) I get the aforementioned error message. I am not sure what Drupal is doing different to result in this error.

@sj26
Copy link
Owner

sj26 commented Jul 30, 2014

You'll need those environment variables set in your PHP process which runs sendmail, or you can edit the catchmail shebang to include a --encoding=utf8.

Please reopen the issue if you have further problems.

@sj26 sj26 closed this as completed Jul 30, 2014
@Baysen
Copy link
Author

Baysen commented Jul 30, 2014

Thank you for your help, this finally fixed the issue for me.

There seems to be a small issue with your answer though, because --encoding=utf8 resulted in an error for me. Using --encoding=utf-8 fixed it for me. I don't know if this may vary from machine to machine, but I think it is worth noting.

@mnapoli
Copy link

mnapoli commented Oct 6, 2014

Same error for me, on Mac OS X. Adding --encoding=utf-8 in the catchmail ruby script fixed it too, but maybe it could be included by default?

@mnapoli
Copy link

mnapoli commented Oct 6, 2014

(FYI I was sending an email in french)

@sj26
Copy link
Owner

sj26 commented Oct 7, 2014

Unfortunately because the versions of ruby vary so greatly in their treatment of encodings and it's rubygems creating the shim, not mailcatcher, there's little we can do from the gem.

@sj26
Copy link
Owner

sj26 commented Oct 7, 2014

Actually, I tell a lie. We could set the external encoding inside the script. I'll add a TODO.

@maxchene
Copy link

Hi, i'm having the same issue. Can someone tell me where to set the encoding to utf8 ? I put --encoding=utf-8 in the first shebang line of catchmail, but nothing..

@ghost
Copy link

ghost commented Oct 19, 2018

Solved for me adding this 2 lines:

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

in this file:
/Users/dam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mailcatcher-0.6.5/bin/catchmail

Like this:

#!/usr/bin/env ruby

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

begin
  require 'mail'
rescue LoadError
  require 'rubygems'
  require 'mail'
end
..............

@sodu-parisev
Copy link

@akimad thanks, helped me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants