Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Avoid adding nil values to mail headers #1392

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1666 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 06052cb34c578879e2e835321eee9b14e76adf9e 1 parent 6e7e552
@jamis jamis authored
View
2  actionmailer/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Avoid adding nil header values #1392
+
* Better multipart support with implicit multipart/alternative and sorting of subparts [John Long]
* Allow for nested parts in multipart mails #1570 [Flurin Egger]
View
13 actionmailer/lib/action_mailer/part.rb
@@ -40,9 +40,9 @@ def to_mail(defaults)
# non-attachment parts)
if content_disposition == "attachment"
part.set_content_type(content_type || defaults.content_type, nil,
- "charset" => nil,
- "name" => filename)
- part.set_content_disposition(content_disposition, "filename" => filename)
+ squish("charset" => nil, "name" => filename))
+ part.set_content_disposition(content_disposition,
+ squish("filename" => filename))
else
part.set_content_type(content_type || defaults.content_type, nil,
"charset" => (charset || defaults.charset))
@@ -65,9 +65,14 @@ def to_mail(defaults)
part.set_content_type(content_type, nil, { "charset" => charset }) if content_type =~ /multipart/
end
-
part
end
+
+ private
+
+ def squish(values={})
+ values.delete_if { |k,v| v.nil? }
+ end
end
end
View
16 actionmailer/test/mail_service_test.rb
@@ -156,7 +156,15 @@ def nested_multipart(recipient)
p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2"
end
attachment :content_type => "application/octet-stream",:filename => "test.txt", :body => "test abcdefghijklmnopqstuvwxyz"
-
+ end
+
+ def unnamed_attachment(recipient)
+ recipients recipient
+ subject "nested multipart"
+ from "test@example.com"
+ body "multipart/mixed"
+ part :content_type => "text/plain", :body => "hullo"
+ attachment :content_type => "application/octet-stream", :body => "test abcdefghijklmnopqstuvwxyz"
end
@@ -621,5 +629,11 @@ def test_decode_message_with_unquoted_atchar_in_header
mail = TMail::Mail.parse(fixture)
assert_not_nil mail.from
end
+
+ def test_empty_header_values_omitted
+ result = TestMailer.create_unnamed_attachment(@recipient).encoded
+ assert_match %r{Content-Type: application/octet-stream[^;]}, result
+ assert_match %r{Content-Disposition: attachment[^;]}, result
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.