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

Mandrill encoding errors #13

Open
rymohr opened this issue Oct 21, 2015 · 5 comments
Open

Mandrill encoding errors #13

rymohr opened this issue Oct 21, 2015 · 5 comments

Comments

@rymohr
Copy link

rymohr commented Oct 21, 2015

We use Mandrill to deliver our inbound emails and occasionally we'll get an encoding error with one of the email replies (expecting UTF-8 but get ASCII-8BIT).

Originally I thought it was an issue with Mandrill but they claim everything is converted to UTF-8 before being sent to the webhook. If they're converting the content to UTF-8 but leaving the original headers alone, wouldn't that screw up the decoding?

Here's what we're using to grab the body of the email:

def get_body(mail)
  if mail.multipart?
    if mail.text_part
      mail.text_part.decoded
    else
      mail.html_part.decoded
    end
  else
    mail.body.decoded
  end
end

Not sure if this is an issue with the mandrill strategy or just the way we're extracting the body of the message.

@joshuap
Copy link
Member

joshuap commented Oct 22, 2015

We use the raw_msg key to parse each inbound message from their WebHook using ruby's standard Mail library. As long as they are converting their whole JSON payload to UTF-8, I'm not sure why you would get encoding errors. The Mail lib does some of its own encoding/decoding as I recall, though. Do you have an error message/backtrace for the conversion errors you mentioned?

@rymohr
Copy link
Author

rymohr commented Oct 22, 2015

I do have a backtrace but it's not much help here since it doesn't blow up until I run the content through EmailReplyFilter. Just your typical incompatible character encodings: ASCII-8BIT and UTF-8 error.

Still waiting to hear back from Mandrill but I looked into one of the webhooks and it looks like only the event.msg.text field is converted to UTF-8. The content of raw_msg is in the original encoding (though encoded to be UTF-8 friendly I guess?).

We've been running into this error long enough that I finally just dropped incoming yesterday in favor of handling the webhooks directly and grabbing the body from event.msg.text. Seems to be working fine so far.

@joshuap
Copy link
Member

joshuap commented Oct 22, 2015

That sounds about right (event.msg.text). We probably should do something to handle bad encodings in the raw_msg field or switch to use the UTF-8 keys. I used raw_msg because it's a lot simpler to construct a Mail::Message from. It sounds like you have this resolved on your end for now, but I'll leave this open until I can work up a fix. :)

@rymohr
Copy link
Author

rymohr commented Oct 22, 2015

I wish I had saved some of my notes for you. It's a hard one to track down!

@rymohr
Copy link
Author

rymohr commented Oct 22, 2015

This thread was a big help: mikel/mail#431

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

2 participants