jhk753 / gmail-ruby-api

Ruby interface for Gmail API
Other
26 stars 20 forks source link

Gem doesn't play nicely with certain types of multipart emails #20

Open Carpela opened 9 years ago

Carpela commented 9 years ago

When dealing with mails of certain multipart structures, the gem can think that attachments are the text part of the email.

IF you consider an email of the following types: Content-type: multipart/alternative; Content-Type: text/plain … here is the text Content-Type: text/html … here is the html

Works fine, but another one:

Content-Type: multipart/mixed
  Content-type: text/plain (or any other)
    … attachment data here
  Content-type: multipart/alternative;
    Content-Type: text/plain
        … here is the text
    Content-Type: text/html
        … here is the html

Ends up with a

undefined method `tr' for nil:NilClass

It's to do with this code that just assumes the first text it comes across is the right one. Mail gem assigns a content type of text to anything it doesn't recognise, thus exascerbating the problem.

 if payload.parts
      text_part=@values.payload.find_all_object_containing("mimeType", "text/plain").first
      if text_part
        @values.text = urlsafe_decode64(text_part.body.data)
      end
      html_part=@values.payload.find_all_object_containing("mimeType", "text/html").first
      if html_part
        @values.html = urlsafe_decode64(html_part.body.data)
      end
    end
    if payload.body.data
      @values.body = urlsafe_decode64(@values.payload.body.data)
    end
jhk753 commented 8 years ago

Do you want to make a pull request for this ?

Carpela commented 8 years ago

I did...

Carpela commented 8 years ago

I think this one should have been solved by my pull request which you merged.