开发者

Convert header of email to another encoding in ActionMailer in Ruby

I have a website written on ruby 1.8.5 and rails 1.2.6.

There is a feedback page.

So.

i've got a model class:

class Feedback::Notify < ActionMailer::Base
  def answer_for_managers(question)
    recipients test@test.com
    from       "feedback@test.com"
    subject    "Обратная связь: ответ на вопрос"
    body       "question" => question
    content_type "text/html"    
  end
end

Then i have a controller:

class Feedback::QuestionController < Office::BaseController
  def update
      Feedback::Notify.deliver_answer_for_managers(@question)
  end
end

The problem is when a message is sent its subject looks like: =?utf-8?Q?=d0=9e=d0=b1=d1=80=d0=b0=d1=82=d0=bd=d0=b0=d1=8f_=d1=81=d0=b2=d1=8f=d0=b7=d1=8c=3a_=d0=a1=d0=be=d1=82=d1=80=d1=83=d0=b4=d0=bd=d0=b8=d0=ba_=d0=be=d1=82=d0=b2=d0=b5=d1=82=d0=b8=开发者_如何学Cd0=bb_=d0=bd=d0=b0_=d0=b2=d0=be=d0=bf=d1=80=d0=be=d1=81_=d0=ba=d0=bb=d0=b8=d0=b5=d0=bd=d1=82=d0=b0_=23=35=36_=d0=be=d1=82_=32=36=2e=30=38=2e=32=30=31=31_=31=31=3a=33=33?=

so it's url-encoded.

Is there any way to prevent converting subject text to url-encoding? All files are in UTF8 encoding


If you would put unescaped UTF-8 characters into header fields, you would be violating the respective standards RFC 822 and RFC 5322 which state that header fields can only be composed of (7-bit) ASCII characters.

Thus, ActionMailer does the right thing here and escapes the UTF-8 characters. As nothing in the headers states that another encoding is to be used, the recipient (and all intermediate servers) have no other chance than to follow that standard as they have no other clue which encoding might have been used.

As RFC 822 is rather old (but still authoritative for email), UTF-8 just didn't exist as it was specified. The escaping is a workaround specified by RFC 2047 which exactly specifies what you see in the header. MUAs are expected to unescape the text and display the proper glyphs on rendering.

Note that it is entirely possible to send unicode text inside the message body (most of the time inside a MIME container). There it is possible to specify the actual data encoding and the transport encoding using additional headers. See RFC 2045 ff. for more details.

Please read either the RFCs or have a look at the Wikipedia entry on Unicode and e-mail.


i solve my problem by adding default 'Content-Transfer-Encoding' => '7bit' in my ActionMailer

have a look in the API docs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜