aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Lütke <tobias.luetke@gmail.com>2007-10-09 13:34:51 +0000
committerTobias Lütke <tobias.luetke@gmail.com>2007-10-09 13:34:51 +0000
commit19c9c7fafbc7c808c080317a1326c4fbc6068bea (patch)
tree7244a25cc5c1cb33ef2c0986e6f1da26a47acc69
parentd556f466079d329ee678afe0c11db914894cb4b0 (diff)
downloadrails-19c9c7fafbc7c808c080317a1326c4fbc6068bea.tar.gz
rails-19c9c7fafbc7c808c080317a1326c4fbc6068bea.tar.bz2
rails-19c9c7fafbc7c808c080317a1326c4fbc6068bea.zip
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
-rw-r--r--actionmailer/lib/action_mailer/vendor/tmail/quoting.rb6
-rw-r--r--actionmailer/test/quoting_test.rb44
2 files changed, 48 insertions, 2 deletions
diff --git a/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb b/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb
index a7e5c44710..f27234fcfe 100644
--- a/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb
+++ b/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb
@@ -8,6 +8,12 @@ module TMail
from_charset = sub_header("content-type", "charset")
case (content_transfer_encoding || "7bit").downcase
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,
to_charset, from_charset, true)
when "base64"
diff --git a/actionmailer/test/quoting_test.rb b/actionmailer/test/quoting_test.rb
index 243c982fc9..4af9014e43 100644
--- a/actionmailer/test/quoting_test.rb
+++ b/actionmailer/test/quoting_test.rb
@@ -3,6 +3,44 @@ require 'tmail'
require 'tempfile'
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
original = "\303\246 \303\270 and \303\245"
@@ -18,7 +56,8 @@ class QuotingTest < Test::Unit::TestCase
unquoted = TMail::Unquoter.unquote_and_convert_to(result, nil)
assert_equal unquoted, original
end
-
+
+
# test an email that has been created using \r\n newlines, instead of
# \n newlines.
def test_email_quoted_with_0d0a
@@ -62,7 +101,7 @@ class QuotingTest < Test::Unit::TestCase
# No .so
end
end
-
+
private
# This whole thing *could* be much simpler, but I don't think Tempfile,
@@ -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") ]
end
end
+