thoughtbot / griddler

Simplify receiving email in Rails (deprecated)
http://griddler.io/
MIT License
1.38k stars 199 forks source link

Undefined method error when email body is empty #28

Closed simonb83 closed 11 years ago

simonb83 commented 11 years ago

I have successfully integrated Griddler into my app, and it works perfectly as long as the email body has some text in it.

However when I test with an email with an empty body, I keep on getting the following error from the email_parser (which looks to be because the body is empty):

NoMethodError (undefined methodsplit' for nil:NilClass): griddler (0.3.1) lib/griddler/email_parser.rb:26:in extract_reply_body' griddler (0.3.1) lib/griddler/email.rb:63:inextract_body' griddler (0.3.1) lib/griddler/email.rb:12:in initialize' griddler (0.3.1) app/controllers/griddler/emails_controller.rb:3:innew' griddler (0.3.1) app/controllers/griddler/emails_controller.rb:3:in create'

--Edit--

After some investigating, this appears to be happening because of the way the format is set in the params in the incoming email. Specifically, when the email body has content, in the params the format is set as "text"=>"String\n", however when the body is empty, this becomes "text"=>"".

This would seem to be the root cause, because in my rspec tests, post :create, to: "email-token", from: "user@email.com", text: "some string" passes, but post :create, to: "email-token", from: "user@email.com", text: "" fails.

theycallmeswift commented 11 years ago

Thanks for your pull, this is not expected behavior. Fix is imminent.

simonb83 commented 11 years ago

Thanks! I don't know if this helps, but I narrowed this down to line 26 in email_parser.rb body.split(delimeter).first which returns nil when body is empty.

In my testing changing the method to def self.extract_reply_body(body) if body && !body.empty? works pretty nicely.

Thanks again.