sj26 / mailcatcher

Catches mail and serves it through a dream.
http://mailcatcher.me
MIT License
6.3k stars 575 forks source link

Mailcatcher 0.8.x crashing when receiving email #486

Closed bbpennel closed 2 years ago

bbpennel commented 3 years ago

I am experiencing an issue with v0.8.1 and v0.8.0 in centos 7 using ruby 2.6.7. When my application sends an email, I get the following error and mailcatcher exits (whether or not it is running as a daemon):

mailcatcher --http-ip 0.0.0.0 --smtp-ip localhost --smtp-port 1025 -f
Starting MailCatcher v0.8.1
==> smtp://localhost:1025
==> http://0.0.0.0:1080
/home/vagrant/.gem/ruby/gems/mailcatcher-0.8.1/lib/mail_catcher/smtp.rb:48:in `receive_data_chunk': undefined method `+@' for "":String (NoMethodError)
    from /home/vagrant/.gem/ruby/gems/eventmachine-1.0.9.1/lib/em/protocols/smtpserver.rb:545:in `process_data_line'
    from /home/vagrant/.gem/ruby/gems/eventmachine-1.0.9.1/lib/em/protocols/smtpserver.rb:196:in `receive_line'
    from /home/vagrant/.gem/ruby/gems/eventmachine-1.0.9.1/lib/em/protocols/linetext2.rb:66:in `receive_data'
    from /home/vagrant/.gem/ruby/gems/eventmachine-1.0.9.1/lib/eventmachine.rb:193:in `run_machine'
    from /home/vagrant/.gem/ruby/gems/eventmachine-1.0.9.1/lib/eventmachine.rb:193:in `run'
    from /home/vagrant/.gem/ruby/gems/mailcatcher-0.8.1/lib/mail_catcher.rb:180:in `run!'
    from /home/vagrant/.gem/ruby/gems/mailcatcher-0.8.1/bin/mailcatcher:6:in `<top (required)>'
    from /home/vagrant/bin/mailcatcher:23:in `load'
    from /home/vagrant/bin/mailcatcher:23:in `<main>'

Version 0.7.1 does not have this issue, so I am using it for the time being. Is there a minimum ruby requirement for 0.8.x?

The application sending the email is a java application which is using a basic JavaMailSenderImpl.

ueshiy commented 2 years ago

I'm getting same problem on RHEL 7.

/usr/local/share/gems/gems/mailcatcher-0.8.1/lib/mail_catcher/smtp.rb:48:in `receive_data_chunk': undefined method `+@' for "":String (NoMethodError)
    from /usr/local/share/gems/gems/eventmachine-1.0.9.1/lib/em/protocols/smtpserver.rb:545:in `process_data_line'
    from /usr/local/share/gems/gems/eventmachine-1.0.9.1/lib/em/protocols/smtpserver.rb:196:in `receive_line'
    from /usr/local/share/gems/gems/eventmachine-1.0.9.1/lib/em/protocols/linetext2.rb:66:in `receive_data'
    from /usr/local/share/gems/gems/eventmachine-1.0.9.1/lib/eventmachine.rb:193:in `run_machine'
    from /usr/local/share/gems/gems/eventmachine-1.0.9.1/lib/eventmachine.rb:193:in `run'
    from /usr/local/share/gems/gems/mailcatcher-0.8.1/lib/mail_catcher.rb:180:in `run!'
    from /usr/local/share/gems/gems/mailcatcher-0.8.1/bin/mailcatcher:6:in `<top (required)>'
    from /usr/local/bin/mailcatcher:23:in `load'
    from /usr/local/bin/mailcatcher:23:in `<main>'
ilsuky commented 2 years ago

Hi, i´m getting the same error on CentOs 7. Mailcatcher Version v0.8.1

jamesadney commented 2 years ago

It looks like you're getting this exception because you're using a Ruby version that doesn't support String#+@. I believe it was added in Ruby 2.3.

After tagging version 0.8.1, the maintainer updated the gemspec to say that they only support Ruby 2.6 and later, so I doubt they'll fix this issue even though technically 0.8.1 was marked as supporting Ruby 2.0.

You might run into other problems with mailcatcher on your old Ruby version, but you should be able to work around this exception by forking the gem and changing line 48 in lib/mail_catcher/smtp.rb from current_message[:source] ||= +"" to current_message[:source] ||= String.new.

sj26 commented 2 years ago

Apologies, I should have raised the ruby version requirement in v0.8.0.

I've made a compatibility release in v0.8.2 which lowers the ruby version restriction again and reverts usage of +"". Future versions will be restricted to 2.6.0+ again.

I am puzzled that String#+@ isn't available in your ruby 2.6.7 environment, however. That version definitely has the unary plus operator on string:

https://github.com/ruby/ruby/blob/v2_6_7/string.c#L2641-L2658

Are you sure you're using the version of ruby you expect?

sj26 commented 2 years ago

Other folks, please try installing mailcatcher again. It should find 0.8.2 which has backwards compatibility as much as is possible. If it still doesn't work then you may need to continue installing with a version requirement, like:

gem install mailcatcher -v "< 0.8"

Sadly I think new releases which restrict to later ruby versions will cause gem install mailcatcher on older rubies to simply fail with a ruby version requirement error. I don't think rubygems version negotiation is smart enough to handle it.