aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionmailer/CHANGELOG2
-rwxr-xr-xactionmailer/lib/action_mailer/vendor/tmail/mail.rb6
-rwxr-xr-xactionmailer/test/mail_service_test.rb14
3 files changed, 21 insertions, 1 deletions
diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG
index eac4caf81a..93995081f0 100644
--- a/actionmailer/CHANGELOG
+++ b/actionmailer/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Normalize line endings in outgoing mail bodies to "\n" #1536 [John Long]
+
* Allow template to be explicitly specified #1448 [tuxie@dekadance.se]
* Allow specific "multipart/xxx" content-type to be set on multipart messages #1412 [Flurin Egger]
diff --git a/actionmailer/lib/action_mailer/vendor/tmail/mail.rb b/actionmailer/lib/action_mailer/vendor/tmail/mail.rb
index 9111a65042..f4a42df19b 100755
--- a/actionmailer/lib/action_mailer/vendor/tmail/mail.rb
+++ b/actionmailer/lib/action_mailer/vendor/tmail/mail.rb
@@ -335,9 +335,13 @@ 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 str }
+ @body_port.wopen {|f| f.write normalize_line_endings(str) }
str
end
diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb
index ce5702db07..f5402c6617 100755
--- a/actionmailer/test/mail_service_test.rb
+++ b/actionmailer/test/mail_service_test.rb
@@ -137,6 +137,14 @@ class TestMailer < ActionMailer::Base
body["recipient"] = recipient
end
+ def various_newlines(recipient)
+ recipients recipient
+ subject "various newlines"
+ from "test@example.com"
+ body "line #1\nline #2\rline #3\r\nline #4\r\r" +
+ "line #5\n\nline#6\r\n\r\nline #7"
+ end
+
class <<self
attr_accessor :received_body
end
@@ -528,6 +536,12 @@ EOF
assert_equal "text/html", mail.content_type
end
+ def test_various_newlines
+ mail = TestMailer.create_various_newlines(@recipient)
+ assert_equal("line #1\nline #2\nline #3\nline #4\n\n" +
+ "line #5\n\nline#6\n\nline #7", mail.body)
+ end
+
def test_headers_removed_on_smtp_delivery
ActionMailer::Base.delivery_method = :smtp
TestMailer.deliver_cc_bcc(@recipient)