Rails 2 Mailer View Prepending 3D to strings

瘦欲@ 提交于 2020-01-04 04:21:15

问题


I have a very old rails app that is trying to send verification emails for new users but the token can never be found because for some reason the link gets 3D prepended to the string no matter how I generate the link. It also seems to be injecting an = sign into the middle of the token for some reason.

Here's some code with output:

<%= link_to verify_account_url(:host => (ActionMailer::Base.default_url_options[:host] || ''), :t => @token), verify_account_url(:host => (ActionMailer::Base.default_url_options[:host] || ''), :t => @token) %>

<a href=3D"https://localhost:3000/accounts/verify?t=3Dd486da2ac8a6dea8a3d9ce341c7aa6=
b01cca96ea">https://localhost:3000/accounts/verify?t=3Dd486da2ac8a6dea8a3d9ce341c7aa6b0=
1cca96ea</a>

and the token in the database is:

#<AccountToken id: 6317, token: "d486da2ac8a6dea8a3d9ce341c7aa6b01cca96ea", email: "...", client: nil>

I've also tried just hardcoding the URL and interpolating the token in the string output but the same issue is happening, it also appears to happen for normal HTML tags as such:

<p style="margin: 0 0 1em;">If clicking the link doesn't work, copy and paste the link into your browser's address bar.</p>

results in

<p style=3D"margin: 0 0 1em;">If clicking the link doesn't work, copy a=nd paste the link into your browser's address bar.</p>

Anyone have any idea?


回答1:


This is normal. In order for email to travel smoothly through legacy systems that might only support 7bit ascii email bodies are often encoding using various schemes that convert everything to 7bit ascii.

One such scheme is called quoted-printable, in this scheme special characters are encoded using = followed by the hex byte value (basically the same as % encoding in urls). Part of this scheme is that lines have to be no longer than 76 characters - if a line is longer a carriage return is inserted, along with an = so that these can be distinguished from line breaks present in the source document.

When the email is read by a mail client those extra = and line returns won't be there anymore.



来源:https://stackoverflow.com/questions/25689375/rails-2-mailer-view-prepending-3d-to-strings

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