Permalink
Browse files

Fix that declaring an html_part but no text_part would use multipart/…

…alternative anyway.
  • Loading branch information...
1 parent 39a4805 commit 3c8de1f425aadb71475813ddd9bebf1e41610d83 @jeremy jeremy committed Jan 26, 2013
Showing with 22 additions and 6 deletions.
  1. +1 −0 CHANGELOG.rdoc
  2. +2 −6 lib/mail/message.rb
  3. +19 −0 spec/mail/mime_messages_spec.rb
View
@@ -8,6 +8,7 @@ Performance:
* Close pull request 488 - Speed up field construction & comparison (bpot)
Bugs:
+* Fix that declaring an html_part but no text_part would use multipart/alternative anyway (jeremy)
* Close pull request 487 - Extract comments from group email addresses (bpot)
* Close pull request 481 - Correctly quote filename attributes (bpot)
* Close pull request 471 - Fix Ruby 1.8 build when UTF16/32 default to little-endian (kennyj)
View
@@ -1559,9 +1559,7 @@ def has_attachments?
# Accessor for html_part
def html_part(&block)
if block_given?
- @html_part = Mail::Part.new(&block)
- add_multipart_alternate_header unless html_part.blank?
- add_part(@html_part)
+ self.html_part = Mail::Part.new(&block)
else
@html_part || find_first_mime_type('text/html')
end
@@ -1570,9 +1568,7 @@ def html_part(&block)
# Accessor for text_part
def text_part(&block)
if block_given?
- @text_part = Mail::Part.new(&block)
- add_multipart_alternate_header unless html_part.blank?
- add_part(@text_part)
+ self.text_part = Mail::Part.new(&block)
else
@text_part || find_first_mime_type('text/plain')
end
@@ -211,6 +211,25 @@
mail.to_s.should =~ %r|Content-Type: multipart/alternative;\s+boundary="#{mail.boundary}"|
end
+ it "should set the content type to multipart/alternative if you declare html and text parts" do
+ mail = Mail.new
+ mail.text_part { }
+ mail.html_part { }
+ mail.to_s.should =~ %r|Content-Type: multipart/alternative;\s+boundary="#{mail.boundary}"|
+ end
+
+ it "should not set the content type to multipart/alternative if you declare an html part but not a text part" do
+ mail = Mail.new
+ mail.html_part { }
+ mail.to_s.should_not =~ %r|Content-Type: multipart/alternative;\s+boundary="#{mail.boundary}"|
+ end
+
+ it "should not set the content type to multipart/alternative if you declare a text part but not an html part" do
+ mail = Mail.new
+ mail.text_part { }
+ mail.to_s.should_not =~ %r|Content-Type: multipart/alternative;\s+boundary="#{mail.boundary}"|
+ end
+
it "should add the end boundary tag" do
mail = Mail.new
mail.text_part = Mail::Part.new do

0 comments on commit 3c8de1f

Please sign in to comment.