diff options
author | Jamis Buck <jamis@37signals.com> | 2005-07-06 09:53:34 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2005-07-06 09:53:34 +0000 |
commit | bde3df2bec99103eeb91c4caaf0483aacadccd92 (patch) | |
tree | ca066ea3db87908f122675b3481a3f5c25ee2665 /actionmailer | |
parent | 853ea556749809658c0a5c0c8b61263ec022fba1 (diff) | |
download | rails-bde3df2bec99103eeb91c4caaf0483aacadccd92.tar.gz rails-bde3df2bec99103eeb91c4caaf0483aacadccd92.tar.bz2 rails-bde3df2bec99103eeb91c4caaf0483aacadccd92.zip |
Correctly normalize newlines in outgoing emails before encoding the body [John Long]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1732 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 5 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/part.rb | 3 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/utils.rb | 8 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail/mail.rb | 6 | ||||
-rwxr-xr-x | actionmailer/test/mail_service_test.rb | 15 |
5 files changed, 29 insertions, 8 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 61bc74a81c..89c202fd01 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,6 +1,7 @@ require 'action_mailer/adv_attr_accessor' require 'action_mailer/part' require 'action_mailer/part_container' +require 'action_mailer/utils' require 'tmail/net' module ActionMailer #:nodoc: @@ -293,11 +294,11 @@ module ActionMailer #:nodoc: if @parts.empty? m.set_content_type content_type, nil, { "charset" => charset } - m.body = body + m.body = Utils.normalize_new_lines(body) else if String === body part = TMail::Mail.new - part.body = body + part.body = Utils.normalize_new_lines(body) part.set_content_type content_type, nil, { "charset" => charset } part.set_content_disposition "inline" m.parts << part diff --git a/actionmailer/lib/action_mailer/part.rb b/actionmailer/lib/action_mailer/part.rb index 60cbe0d3fe..d4b8e3b9d9 100644 --- a/actionmailer/lib/action_mailer/part.rb +++ b/actionmailer/lib/action_mailer/part.rb @@ -1,5 +1,6 @@ require 'action_mailer/adv_attr_accessor' require 'action_mailer/part_container' +require 'action_mailer/utils' module ActionMailer class Part #:nodoc: @@ -29,7 +30,7 @@ module ActionMailer when "base64" then part.body = TMail::Base64.folding_encode(body) when "quoted-printable" - part.body = [body].pack("M*") + part.body = [Utils.normalize_new_lines(body)].pack("M*") else part.body = body end diff --git a/actionmailer/lib/action_mailer/utils.rb b/actionmailer/lib/action_mailer/utils.rb new file mode 100644 index 0000000000..552f695a92 --- /dev/null +++ b/actionmailer/lib/action_mailer/utils.rb @@ -0,0 +1,8 @@ +module ActionMailer + module Utils #:nodoc: + def normalize_new_lines(text) + text.to_s.gsub(/\r\n?/, "\n") + end + module_function :normalize_new_lines + end +end diff --git a/actionmailer/lib/action_mailer/vendor/tmail/mail.rb b/actionmailer/lib/action_mailer/vendor/tmail/mail.rb index f4a42df19b..9111a65042 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail/mail.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail/mail.rb @@ -335,13 +335,9 @@ module TMail } end - def normalize_line_endings(text) - text.to_s.gsub(/\r\n?/, "\n") - end - def body=( str ) parse_body - @body_port.wopen {|f| f.write normalize_line_endings(str) } + @body_port.wopen {|f| f.write str } str end diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index accb18fa25..cd8c9539ca 100755 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -146,6 +146,15 @@ class TestMailer < ActionMailer::Base "line #5\n\nline#6\r\n\r\nline #7" end + def various_newlines_multipart(recipient) + recipients recipient + subject "various newlines multipart" + from "test@example.com" + content_type "multipart/alternative" + part :content_type => "text/plain", :body => "line #1\nline #2\rline #3\r\nline #4\r\r" + part :content_type => "text/html", :body => "<p>line #1</p>\n<p>line #2</p>\r<p>line #3</p>\r\n<p>line #4</p>\r\r" + end + def nested_multipart(recipient) recipients recipient subject "nested multipart" @@ -597,6 +606,12 @@ EOF "line #5\n\nline#6\n\nline #7", mail.body) end + def test_various_newlines_multipart + mail = TestMailer.create_various_newlines_multipart(@recipient) + assert_equal "line #1\nline #2\nline #3\nline #4\n\n", mail.parts[0].body + assert_equal "<p>line #1</p>\n<p>line #2</p>\n<p>line #3</p>\n<p>line #4</p>\n\n", mail.parts[1].body + end + def test_headers_removed_on_smtp_delivery ActionMailer::Base.delivery_method = :smtp TestMailer.deliver_cc_bcc(@recipient) |