thoughtbot / griddler

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

The post is garbled if the original email is encoded with charset iso-2022-jp #312

Closed RubyLucy closed 5 years ago

RubyLucy commented 5 years ago

I'm using sendgrid+griddler to post the incoming email to my web app. Most of the emails are written in Japanese. If the incoming email is encoded with UTF-8 then the post is normal to display in Japanese, but sometimes the incoming email is encoded with iso-2022-jp (It seems that the charset depends on the mail sender thus I cannot control), then the post is totally garbled. Is there any advice how to fix the issue? Should I specify something in my app or sendgrid should do this or griddler should do? Many thanks.

RubyLucy commented 5 years ago

The post now looks like the following. It is supposed to be displayed in Japanese. image

RubyLucy commented 5 years ago

I did the following change to my app and it seems to work for those iso-2022-jp encoded mails, but if the mails are encoded with utf-8 exception would occur. Is there any way for griddler to distinguish the encoding of the email?

PREVIOUS: my_post_text = @email.raw_html NOW my_post_text = @email.raw_html.force_encoding("iso-2022-jp").encode("utf-8")

RubyLucy commented 5 years ago

For some emails, charset information is written in the raw header, we can fetch the charset via regular expression. But for some other emails, charset information is written between the boundary line and the raw body, it seems that griddler ignores this part of information. Thus, I will close this ticket and open a new one regarding this.