mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Set default charset of MTAs to ISO instead of us-ascii (unless reported otherwise)
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7819 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
d556f46607
commit
19c9c7fafb
2 changed files with 48 additions and 2 deletions
|
@ -8,6 +8,12 @@ module TMail
|
||||||
from_charset = sub_header("content-type", "charset")
|
from_charset = sub_header("content-type", "charset")
|
||||||
case (content_transfer_encoding || "7bit").downcase
|
case (content_transfer_encoding || "7bit").downcase
|
||||||
when "quoted-printable"
|
when "quoted-printable"
|
||||||
|
# the default charset is set to iso-8859-1 instead of 'us-ascii'.
|
||||||
|
# This is needed as many mailer do not set the charset but send in ISO. This is only used if no charset is set.
|
||||||
|
if !from_charset.blank? && from_charset.downcase == 'us-ascii'
|
||||||
|
from_charset = 'iso-8859-1'
|
||||||
|
end
|
||||||
|
|
||||||
Unquoter.unquote_quoted_printable_and_convert_to(quoted_body,
|
Unquoter.unquote_quoted_printable_and_convert_to(quoted_body,
|
||||||
to_charset, from_charset, true)
|
to_charset, from_charset, true)
|
||||||
when "base64"
|
when "base64"
|
||||||
|
|
|
@ -3,6 +3,44 @@ require 'tmail'
|
||||||
require 'tempfile'
|
require 'tempfile'
|
||||||
|
|
||||||
class QuotingTest < Test::Unit::TestCase
|
class QuotingTest < Test::Unit::TestCase
|
||||||
|
|
||||||
|
# Move some tests from TMAIL here
|
||||||
|
def test_unquote_quoted_printable
|
||||||
|
a ="=?ISO-8859-1?Q?[166417]_Bekr=E6ftelse_fra_Rejsefeber?="
|
||||||
|
b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8')
|
||||||
|
assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_unquote_base64
|
||||||
|
a ="=?ISO-8859-1?B?WzE2NjQxN10gQmVrcuZmdGVsc2UgZnJhIFJlanNlZmViZXI=?="
|
||||||
|
b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8')
|
||||||
|
assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_unquote_without_charset
|
||||||
|
a ="[166417]_Bekr=E6ftelse_fra_Rejsefeber"
|
||||||
|
b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8')
|
||||||
|
assert_equal "[166417]_Bekr=E6ftelse_fra_Rejsefeber", b
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_unqoute_multiple
|
||||||
|
a ="=?utf-8?q?Re=3A_=5B12=5D_=23137=3A_Inkonsistente_verwendung_von_=22Hin?==?utf-8?b?enVmw7xnZW4i?="
|
||||||
|
b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8')
|
||||||
|
assert_equal "Re: [12] #137: Inkonsistente verwendung von \"Hinzuf\303\274gen\"", b
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_unqoute_in_the_middle
|
||||||
|
a ="Re: Photos =?ISO-8859-1?Q?Brosch=FCre_Rand?="
|
||||||
|
b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8')
|
||||||
|
assert_equal "Re: Photos Brosch\303\274re Rand", b
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_unqoute_iso
|
||||||
|
a ="=?ISO-8859-1?Q?Brosch=FCre_Rand?="
|
||||||
|
b = TMail::Unquoter.unquote_and_convert_to(a, 'iso-8859-1')
|
||||||
|
assert_equal "Brosch\374re Rand", b
|
||||||
|
end
|
||||||
|
|
||||||
def test_quote_multibyte_chars
|
def test_quote_multibyte_chars
|
||||||
original = "\303\246 \303\270 and \303\245"
|
original = "\303\246 \303\270 and \303\245"
|
||||||
|
|
||||||
|
@ -19,6 +57,7 @@ class QuotingTest < Test::Unit::TestCase
|
||||||
assert_equal unquoted, original
|
assert_equal unquoted, original
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# test an email that has been created using \r\n newlines, instead of
|
# test an email that has been created using \r\n newlines, instead of
|
||||||
# \n newlines.
|
# \n newlines.
|
||||||
def test_email_quoted_with_0d0a
|
def test_email_quoted_with_0d0a
|
||||||
|
@ -91,3 +130,4 @@ class QuotingTest < Test::Unit::TestCase
|
||||||
[ File.read("#{File.dirname(__FILE__)}/fixtures/raw_base64_encoded_string"), File.read("#{File.dirname(__FILE__)}/fixtures/raw_base64_decoded_string") ]
|
[ File.read("#{File.dirname(__FILE__)}/fixtures/raw_base64_encoded_string"), File.read("#{File.dirname(__FILE__)}/fixtures/raw_base64_decoded_string") ]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue