Rails - 邮件主题是hotmail中的乱码 [英] Rails - email subject is gibberish in hotmail
问题描述
发送电子邮件对于所有主要电子邮件客户端都是完美的,除了hotmail(和其他一些),它显示为:
Sending emails works perfectly for all major email clients, except for hotmail (and some other), it shows as:
=?windows -1255 Q + Z33 = 30_1 = F9 = 22 = E7 = 20 = F2 = E1 = E5 = F8_ = F9 = E5 = E1 = F8 = 20 = E1 = F9 = E5 = E5 = E9 = 20 = 36 = 30_ = F9 = 22 = E7 = 20 = EC = 22 = EE = F8 = E2 = E5 = E6 = E4 = 22 = 2C_ = E1 = E9 = FA_ = F7 = F4 = E4 = 20 = E5 = EE = E0 = F4 = E9 = E9 = E4_ = EE = F9 = F4 = E7 = FA = E9 = FA = 2C = 20 = E1 = EE = FA = E7 = ED = 20 = F9 = E5 = F7 = 20 = E4 = F4 = F9 = F4 =
如果是utf8,不要。看起来Hotmail不能读长引用的主题,因为较短的对象可以显示出来。
Dosn't matter if it's utf8 or not. It seems like hotmail can't read long quoted subjects, because for shorter ones it shows up ok.
AFAIK的例子是将主题分割成多个, 64(或某事)chars long ...
但我无法弄清楚如何在rails(2.3.8)。
Rails默认编码主题,引用表单,找不到如何覆盖,所以我可以自己拆分...
AFAIK what gmail does for example is to split the subject to pieces, 64 (or something) chars long... But I can't figure out how to do that in rails (2.3.8). Rails encodes the subject by default, in quoted form, can't find how to override that so I could split it by myself...
谢谢。
推荐答案
这对我有用:
module ActionMailer
module Quoting
def quoted_printable(text, charset)
require 'base64'
#text.scan_utf8(/.{1,64}/m).map{|text| "=?#{charset}?B?#{Base64.b64encode(text)}?="}.join("\n")
"=?#{charset}?B?#{Base64.b64encode(text).gsub(/\n/, '')}?="
end
end
end
module TMail
class SubjectHeaderField < UnstructuredHeader
def parse
#Do nothing
end
end
class HeaderField
FNAME_TO_CLASS = FNAME_TO_CLASS.merge('subject' => SubjectHeaderField)
end
end
这篇关于Rails - 邮件主题是hotmail中的乱码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!