Browse files

Unset body @parts, test for quoted-printable html part

  • Loading branch information...
1 parent 032b27b commit e86279937b6e731df121f2fbaa363316c1466c36 @ndbroadbent ndbroadbent committed Jan 7, 2012
Showing with 13 additions and 6 deletions.
  1. +4 −2 lib/action_mailer/inline_css_hook.rb
  2. +9 −4 test/inline_css_hook_test.rb
View
6 lib/action_mailer/inline_css_hook.rb
@@ -16,19 +16,21 @@ def self.delivering_email(message)
:base_url => message.header[:host].to_s)
existing_text_part = message.text_part && message.text_part.body.to_s
existing_attachments = message.attachments
+ msg_charset = message.charset
# Reset the body
message.body = nil
+ message.body.instance_variable_set("@parts", Mail::PartsList.new)
# Add an HTML part with CSS inlined.
message.html_part do
- content_type "text/html; charset=utf-8"
+ content_type "text/plain; charset=#{charset}"
body premailer.to_inline_css
end
# Add a text part with either the pre-existing text part, or one generated with premailer.
message.text_part do
- content_type "text/plain; charset=utf-8"
+ content_type "text/plain; charset=#{charset}"
body existing_text_part || premailer.to_plain_text
end
View
13 test/inline_css_hook_test.rb
@@ -98,15 +98,20 @@ def test_inline_css_hook_with_text_and_html_parts
mail = HelperMailer.use_inline_css_hook_with_text_and_html_parts.deliver
assert_match '<div id="test" style="color: #123456;">Test</div>', mail.html_part.body.encoded
# Test specified text part
- assert_match 'Different Text Part', mail.text_part.body.encoded
+ assert_match 'Different Text Part', mail.text_part.decoded
end
def test_inline_css_hook_with_utf_8_characters
mail = nil
mail = HelperMailer.use_inline_css_hook_with_utf_8.deliver
- assert_match 'ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ', mail.html_part.body.encoded
- assert_match 'Gonçalves', mail.html_part.body.encoded
- assert_match 'ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ', mail.text_part.body.encoded
+
+ assert_match 'ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ', mail.html_part.decoded
+ assert_match 'Gonçalves', mail.html_part.decoded
+ assert_match 'ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ', mail.text_part.decoded
+ assert_match '=E1=9A=A0=E1=9B=87=E1=9A=BB=', mail.html_part.encoded
+
+ assert_equal mail.html_part.content_transfer_encoding, "quoted-printable"
+ assert_equal mail.text_part.content_transfer_encoding, "base64"
end
def test_inline_css_hook_with_base_url

0 comments on commit e862799

Please sign in to comment.