utf-8和ActionMailer [英] utf-8 and ActionMailer

查看:81
本文介绍了utf-8和ActionMailer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用UTF-8和ActionMailer时遇到了一些问题。我的应用程序有一个表单(联系人),提交后会向我发送电子邮件。问题是,当有人输入像öäüß这样的字符时,我收到的消息编码为例如

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?=

据我了解,ActionMailer默认情况下是utf-8就绪的。分析来自服务器的日志,提交表单后,参数已经被正确编码(这意味着我可以阅读日志中的äüö)

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)

关于什么的任何想法我应该改变吗?我应该更改我的应用程序以支持ISO-8859-1吗?

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

环境:ruby 1.9和rails 3.1

environment: ruby 1.9 and rails 3.1

推荐答案

使用 quoted-printable 转义的UTF-8字节。

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

ß是 \xC3\x9F-> = C3 = 9F

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

String#unpack('M') 将对其进行解码:

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

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

öä

`

这篇关于utf-8和ActionMailer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆