如何使用Ruby处理UTF-8电子邮件标题(如主题:)? [英] How to handle UTF-8 email headers (like Subject:) using Ruby?

查看:162
本文介绍了如何使用Ruby处理UTF-8电子邮件标题(如主题:)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个电子邮件n00b,但我正在处理一个发送带有Unicode字符的HTML电子邮件的应用程序(我的朋友指出享受编码地狱)。

I'm an email n00b but I am working on an application that sends HTML email with Unicode characters (as my friend noted "enjoy encoding hell").

主题:头来自用户输入,因此可能包含Unicode字符。有些邮件客户端(如GMail和Outlook 2007)可以这样做,但是从我的阅读看来,正确的方法是使用 MIME编码的Word编码的标题。

The Subject: header comes from user input and therefore may contain Unicode characters. Some mail clients (like GMail and Outlook 2007) are OK with this, but from my reading it seems the right way to do this is to use MIME Encoded-Word encoding for the headers.

我找不到一个Ruby库来做到这一点。是否有一个?

I cannot find a Ruby library to do this. Is there one?

另外,是否有一个标题添加,将显示邮件客户端使用UTF-8显示消息?我们正在发送多部电子邮件,所以我们的内容类型 multipart / mixed 。 Apple Mail.app特别是不使用正确的编码,即使它在各个部分被指定为UTF-8。

Also, is there a header to add that will tell mail clients to use UTF-8 when displaying the message? We are sending multipart email so our Content-Type is multipart/mixed. Apple Mail.app in particular is not using the right encoding, even though it's specified in the individual parts as being UTF-8.

推荐答案

p> AHAH! ActionMailer ::引用有一个 quoted_printable 方法。

Ahah! ActionMailer::Quoting has a quoted_printable method.

所以这就是我所做的:

def my_email(foo)
  ...
  @subject = quoted_printable(foo.some_subject_with_accented_chars, 'utf-8')
  ...
end

这样做可以说服Mail.app使用UTF-8显示剩余的电子邮件。现在来测试休息!

Doing this convinced Mail.app to display the rest of the email using UTF-8. Now to test the rest!

这篇关于如何使用Ruby处理UTF-8电子邮件标题(如主题:)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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