aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test/quoting_test.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-04-01 05:32:11 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-04-01 05:32:11 +0000
commit767be30e6107b2e8c258366da63fb26153cd0472 (patch)
treececa09a883469b60f40e4b7d1336db6cd2c2b036 /actionmailer/test/quoting_test.rb
parent25eeea719768e1c1ce47742057f0fb042a139edc (diff)
downloadrails-767be30e6107b2e8c258366da63fb26153cd0472.tar.gz
rails-767be30e6107b2e8c258366da63fb26153cd0472.tar.bz2
rails-767be30e6107b2e8c258366da63fb26153cd0472.zip
force_encoding to ascii-8bit instead of nil
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9184 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer/test/quoting_test.rb')
-rw-r--r--actionmailer/test/quoting_test.rb38
1 files changed, 18 insertions, 20 deletions
diff --git a/actionmailer/test/quoting_test.rb b/actionmailer/test/quoting_test.rb
index 6d4c891b78..7e300942cb 100644
--- a/actionmailer/test/quoting_test.rb
+++ b/actionmailer/test/quoting_test.rb
@@ -4,10 +4,9 @@ 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?="
+ 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
@@ -19,34 +18,34 @@ class QuotingTest < Test::Unit::TestCase
end
def test_unquote_without_charset
- a ="[166417]_Bekr=E6ftelse_fra_Rejsefeber"
+ 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
-
+ end
+
def test_unqoute_multiple
- a ="=?utf-8?q?Re=3A_=5B12=5D_=23137=3A_Inkonsistente_verwendung_von_=22Hin?==?utf-8?b?enVmw7xnZW4i?="
+ 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?="
+ 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?="
+ a ="=?ISO-8859-1?Q?Brosch=FCre_Rand?="
b = TMail::Unquoter.unquote_and_convert_to(a, 'iso-8859-1')
expected = "Brosch\374re Rand"
expected.force_encoding 'iso-8859-1' if expected.respond_to?(:force_encoding)
assert_equal expected, b
end
-
+
def test_quote_multibyte_chars
original = "\303\246 \303\270 and \303\245"
- original.force_encoding nil if original.respond_to?(:force_encoding)
+ original.force_encoding('ASCII-8BIT') if original.respond_to?(:force_encoding)
result = execute_in_sandbox(<<-CODE)
$:.unshift(File.dirname(__FILE__) + "/../lib/")
@@ -60,8 +59,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
@@ -73,19 +72,19 @@ class QuotingTest < Test::Unit::TestCase
mail = TMail::Mail.parse(IO.read("#{File.dirname(__FILE__)}/fixtures/raw_email_with_partially_quoted_subject"))
assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject
end
-
+
def test_decode
encoded, decoded = expected_base64_strings
assert_equal decoded, TMail::Base64.decode(encoded)
end
-
+
def test_encode
encoded, decoded = expected_base64_strings
assert_equal encoded.length, TMail::Base64.encode(decoded).length
end
-
+
private
-
+
# This whole thing *could* be much simpler, but I don't think Tempfile,
# popen and others exist on all platforms (like Windows).
def execute_in_sandbox(code)
@@ -107,9 +106,8 @@ class QuotingTest < Test::Unit::TestCase
File.delete(test_name) rescue nil
File.delete(res_name) rescue nil
end
-
+
def expected_base64_strings
[ File.read("#{File.dirname(__FILE__)}/fixtures/raw_base64_encoded_string"), File.read("#{File.dirname(__FILE__)}/fixtures/raw_base64_decoded_string") ]
end
end
-