utf-8 and ActionMailer

时光毁灭记忆、已成空白 提交于 2020-01-24 10:16:48

问题


I'm facing some problems with UTF-8 and ActionMailer. My application has a form (contact) that when it is submitted, it sends an email to me. The problem is that when somebody enters some chars like öäüß, I receive the message encoded like for example

 =?UTF-8?Q?funktioniert_oder_nicht.=0D=0A=0D=0Ameine_Stra=C3=9Fe_ist_die?=
 =?UTF-8?Q?_Bratwurststra=C3=9Fe=0D=0A=0D=0A=C3=B6=C3=A4?=

As I understand, ActionMailer per default is utf-8 ready. Analyzing the log from my server, when the form is submitted, the params are already well encoded (it means I can read the äüö in my log)

Any idea about what should I change? should I change my application to support ISO-8859-1?

environment: ruby 1.9 and rails 3.1


回答1:


You are getting the UTF-8 bytes escaped with quoted-printable.

ß is "\xC3\x9F" -> "=C3=9F"

String#unpack('M') will decode it:

$ ruby -e 'puts "Bratwurststra=C3=9Fe=0D=0A=0D=0A=C3=B6=C3=A4".unpack "M"'
Bratwurststraße

öä

`



来源:https://stackoverflow.com/questions/8430940/utf-8-and-actionmailer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!