diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG index 6f4ba96844c9853d71fe951e3a594c18a7d91d75..785bf98c55068625fd772c5141f119336716f615 100644 --- a/actionmailer/CHANGELOG +++ b/actionmailer/CHANGELOG @@ -1,13 +1,14 @@ *Rails 3.0 (pending)* -* ActionMailer::Base :default_implicit_parts_order now is in the sequence of the order you want, no reversing of ordering takes place. The default order now is text/plain, then text/enriched, then text/html and then any other part that is not one of these three. +* The Mail::Message class has helped methods for all the field types that return 'common' defaults for the common use case, so to get the subject, mail.subject will give you a string, mail.date will give you a DateTime object, mail.from will give you an array of address specs (mikel@test.lindsaar.net) etc. If you want to access the field object itself, call mail[:field_name] which will return the field object you want, which you can then chain, like mail[:from].formatted -* Mail does not have "quoted_body", "quoted_subject" etc. All of these are accessed via body.encoded, subject.encoded etc +* Mail#content_type now returns the content_type field as a string. If you want the mime type of a mail, then you call Mail#mime_type (eg, text/plain), if you want the parameters of the content type field, you call Mail#content_type_parameters which gives you a hash, eg {'format' => 'flowed', 'charset' => 'utf-8'} -* Every part of a Mail object returns an object, never a string. So Mail.body returns a Mail::Body class object, need to call #encoded or #decoded to get the string you want. +* ActionMailer::Base :default_implicit_parts_order now is in the sequence of the order you want, no reversing of ordering takes place. The default order now is text/plain, then text/enriched, then text/html and then any other part that is not one of these three. -* By default, a field will return the #decoded value when you send it :to_s and any object that is a container (like header, body etc) will return #encoded value when you send it :to_s +* Mail does not have "quoted_body", "quoted_subject" etc. All of these are accessed via body.encoded, subject.encoded etc +* Every object in a Mail object returns an object, never a string. So Mail.body returns a Mail::Body class object, need to call #encoded or #decoded to get the string you want. * Mail::Message#set_content_type does not exist, it is simply Mail::Message#content_type * Every mail message gets a unique message_id unless you specify one, had to change all the tests that check for equality with expected.encoded == actual.encoded to first replace their message_ids with control values diff --git a/actionmailer/actionmailer.gemspec b/actionmailer/actionmailer.gemspec index 201b56a73980f5367531465062e29481d7c2dedb..8adea46d3530885435bc7e5a4ad0032f16891a86 100644 --- a/actionmailer/actionmailer.gemspec +++ b/actionmailer/actionmailer.gemspec @@ -11,7 +11,7 @@ s.homepage = "http://www.rubyonrails.org" s.add_dependency('actionpack', '= 3.0.pre') - s.add_dependency('mail', '~> 1.4.3') + s.add_dependency('mail', '~> 1.5.0') s.files = Dir['CHANGELOG', 'README', 'MIT-LICENSE', 'lib/**/*'] s.has_rdoc = true diff --git a/actionmailer/test/mail_layout_test.rb b/actionmailer/test/mail_layout_test.rb index 84f13a6d3c434d6a37e12ebcd388946cdc329c41..0877e7b2cb3030a44a1a7c4cb06d4565ef40afa5 100644 --- a/actionmailer/test/mail_layout_test.rb +++ b/actionmailer/test/mail_layout_test.rb @@ -72,12 +72,12 @@ def test_should_pickup_multipart_layout mail = AutoLayoutMailer.create_multipart(@recipient) # CHANGED: content_type returns an object # assert_equal "multipart/alternative", mail.content_type - assert_equal "multipart/alternative", mail.content_type.string + assert_equal "multipart/alternative", mail.mime_type assert_equal 2, mail.parts.size # CHANGED: content_type returns an object # assert_equal 'text/plain', mail.parts.first.content_type - assert_equal 'text/plain', mail.parts.first.content_type.string + assert_equal 'text/plain', mail.parts.first.mime_type # CHANGED: body returns an object # assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body @@ -85,7 +85,7 @@ def test_should_pickup_multipart_layout # CHANGED: content_type returns an object # assert_equal 'text/html', mail.parts.last.content_type - assert_equal 'text/html', mail.parts.last.content_type.string + assert_equal 'text/html', mail.parts.last.mime_type # CHANGED: body returns an object # assert_equal "Hello from layout text/html multipart", mail.parts.last.body @@ -96,19 +96,19 @@ def test_should_pickup_multipartmixed_layout mail = AutoLayoutMailer.create_multipart(@recipient, "multipart/mixed") # CHANGED: content_type returns an object # assert_equal "multipart/mixed", mail.content_type - assert_equal "multipart/mixed", mail.content_type.string + assert_equal "multipart/mixed", mail.mime_type assert_equal 2, mail.parts.size # CHANGED: content_type returns an object # assert_equal 'text/plain', mail.parts.first.content_type - assert_equal 'text/plain', mail.parts.first.content_type.string + assert_equal 'text/plain', mail.parts.first.mime_type # CHANGED: body returns an object # assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s # CHANGED: content_type returns an object # assert_equal 'text/html', mail.parts.last.content_type - assert_equal 'text/html', mail.parts.last.content_type.string + assert_equal 'text/html', mail.parts.last.mime_type # CHANGED: body returns an object # assert_equal "Hello from layout text/html multipart", mail.parts.last.body assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s @@ -116,13 +116,13 @@ def test_should_pickup_multipartmixed_layout def test_should_fix_multipart_layout mail = AutoLayoutMailer.create_multipart(@recipient, "text/plain") - assert_equal "multipart/alternative", mail.content_type.string + assert_equal "multipart/alternative", mail.mime_type assert_equal 2, mail.parts.size - assert_equal 'text/plain', mail.parts.first.content_type.string + assert_equal 'text/plain', mail.parts.first.mime_type assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s - assert_equal 'text/html', mail.parts.last.content_type.string + assert_equal 'text/html', mail.parts.last.mime_type assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s end diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 152900259d0e6c330c26bc0f5a4e2b5a83dbd3f5..f66b4a174bcf38f4953cb9998fc17948211a54ca 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -362,13 +362,13 @@ def test_nested_parts assert_equal 2, created.parts.size assert_equal 2, created.parts.first.parts.size - assert_equal "multipart/mixed", created.content_type.string - assert_equal "multipart/alternative", created.parts[0].content_type.string + assert_equal "multipart/mixed", created.mime_type + assert_equal "multipart/alternative", created.parts[0].mime_type assert_equal "bar", created.parts[0].header['foo'].to_s assert_nil created.parts[0].charset - assert_equal "text/plain", created.parts[0].parts[0].content_type.string - assert_equal "text/html", created.parts[0].parts[1].content_type.string - assert_equal "application/octet-stream", created.parts[1].content_type.string + assert_equal "text/plain", created.parts[0].parts[0].mime_type + assert_equal "text/html", created.parts[0].parts[1].mime_type + assert_equal "application/octet-stream", created.parts[1].mime_type end @@ -380,11 +380,11 @@ def test_nested_parts_with_body assert_equal 1,created.parts.size assert_equal 2,created.parts.first.parts.size - assert_equal "multipart/mixed", created.content_type.string - assert_equal "multipart/alternative", created.parts.first.content_type.string - assert_equal "text/plain", created.parts.first.parts.first.content_type.string + assert_equal "multipart/mixed", created.mime_type + assert_equal "multipart/alternative", created.parts.first.mime_type + assert_equal "text/plain", created.parts.first.parts.first.mime_type assert_equal "Nothing to see here.", created.parts.first.parts.first.body.to_s - assert_equal "text/html", created.parts.first.parts.second.content_type.string + assert_equal "text/html", created.parts.first.parts.second.mime_type assert_equal "test HTML
", created.parts.first.parts.second.body.to_s end @@ -468,8 +468,8 @@ def test_custom_templating_extension assert_nothing_raised { created = TestMailer.create_custom_templating_extension(@recipient) } assert_not_nil created assert_equal 2, created.parts.length - assert_equal 'text/plain', created.parts[0].content_type.string - assert_equal 'text/html', created.parts[1].content_type.string + assert_equal 'text/plain', created.parts[0].mime_type + assert_equal 'text/html', created.parts[1].mime_type end def test_cancelled_account @@ -731,8 +731,8 @@ def test_unquote_quoted_printable_subject The body EOF mail = Mail.new(msg) - assert_equal "testing testing \326\244", mail.subject.to_s - assert_equal "Subject: =?utf-8?Q?testing_testing_=D6=A4?=\r\n", mail.subject.encoded + assert_equal "testing testing \326\244", mail.subject + assert_equal "Subject: =?utf-8?Q?testing_testing_=D6=A4?=\r\n", mail[:subject].encoded end def test_unquote_7bit_subject @@ -744,8 +744,8 @@ def test_unquote_7bit_subject The body EOF mail = Mail.new(msg) - assert_equal "this == working?", mail.subject.to_s - assert_equal "Subject: this == working?\r\n", mail.subject.encoded + assert_equal "this == working?", mail.subject + assert_equal "Subject: this == working?\r\n", mail[:subject].encoded end def test_unquote_7bit_body @@ -868,7 +868,7 @@ def test_receive_attachments mail = Mail.new(fixture) attachment = mail.attachments.last assert_equal "smime.p7s", attachment.original_filename - assert_equal "application/pkcs7-signature", mail.parts.last.content_type.string + assert_equal "application/pkcs7-signature", mail.parts.last.mime_type end def test_decode_attachment_without_charset @@ -913,7 +913,7 @@ def test_decode_message_with_incorrect_charset def test_multipart_with_mime_version mail = TestMailer.create_multipart_with_mime_version(@recipient) - assert_equal "1.1", mail.mime_version.version + assert_equal "1.1", mail.mime_version end def test_multipart_with_utf8_subject @@ -929,29 +929,29 @@ def test_implicitly_multipart_with_utf8 def test_explicitly_multipart_messages mail = TestMailer.create_explicitly_multipart_example(@recipient) assert_equal 3, mail.parts.length - assert_equal 'multipart/mixed', mail.content_type.string - assert_equal "text/plain", mail.parts[0].content_type.string + assert_equal 'multipart/mixed', mail.mime_type + assert_equal "text/plain", mail.parts[0].mime_type - assert_equal "text/html", mail.parts[1].content_type.string + assert_equal "text/html", mail.parts[1].mime_type assert_equal "iso-8859-1", mail.parts[1].charset - assert_equal "image/jpeg", mail.parts[2].content_type.string - assert_equal "attachment", mail.parts[2].content_disposition.disposition_type - assert_equal "foo.jpg", mail.parts[2].content_disposition.filename - assert_equal "foo.jpg", mail.parts[2].content_type.filename + assert_equal "image/jpeg", mail.parts[2].mime_type + assert_equal "attachment", mail.parts[2][:content_disposition].disposition_type + assert_equal "foo.jpg", mail.parts[2][:content_disposition].filename + assert_equal "foo.jpg", mail.parts[2][:content_type].filename assert_nil mail.parts[2].charset end def test_explicitly_multipart_with_content_type mail = TestMailer.create_explicitly_multipart_example(@recipient, "multipart/alternative") assert_equal 3, mail.parts.length - assert_equal "multipart/alternative", mail.content_type.string + assert_equal "multipart/alternative", mail.mime_type end def test_explicitly_multipart_with_invalid_content_type mail = TestMailer.create_explicitly_multipart_example(@recipient, "text/xml") assert_equal 3, mail.parts.length - assert_equal 'multipart/mixed', mail.content_type.string + assert_equal 'multipart/mixed', mail.mime_type end def test_implicitly_multipart_messages @@ -960,12 +960,12 @@ def test_implicitly_multipart_messages mail = TestMailer.create_implicitly_multipart_example(@recipient) assert_equal 3, mail.parts.length assert_equal "1.0", mail.mime_version.to_s - assert_equal "multipart/alternative", mail.content_type.string - assert_equal "text/plain", mail.parts[0].content_type.string + assert_equal "multipart/alternative", mail.mime_type + assert_equal "text/plain", mail.parts[0].mime_type assert_equal "utf-8", mail.parts[0].charset - assert_equal "text/html", mail.parts[1].content_type.string + assert_equal "text/html", mail.parts[1].mime_type assert_equal "utf-8", mail.parts[1].charset - assert_equal "application/x-yaml", mail.parts[2].content_type.string + assert_equal "application/x-yaml", mail.parts[2].mime_type assert_equal "utf-8", mail.parts[2].charset end @@ -974,9 +974,9 @@ def test_implicitly_multipart_messages_with_custom_order mail = TestMailer.create_implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"]) assert_equal 3, mail.parts.length - assert_equal "application/x-yaml", mail.parts[0].content_type.string - assert_equal "text/plain", mail.parts[1].content_type.string - assert_equal "text/html", mail.parts[2].content_type.string + assert_equal "application/x-yaml", mail.parts[0].mime_type + assert_equal "text/plain", mail.parts[1].mime_type + assert_equal "text/html", mail.parts[2].mime_type end def test_implicitly_multipart_messages_with_charset @@ -984,14 +984,14 @@ def test_implicitly_multipart_messages_with_charset assert_equal "multipart/alternative", mail.header['content-type'].content_type - assert_equal 'iso-8859-1', mail.parts[0].content_type.parameters[:charset] - assert_equal 'iso-8859-1', mail.parts[1].content_type.parameters[:charset] - assert_equal 'iso-8859-1', mail.parts[2].content_type.parameters[:charset] + assert_equal 'iso-8859-1', mail.parts[0].content_type_parameters[:charset] + assert_equal 'iso-8859-1', mail.parts[1].content_type_parameters[:charset] + assert_equal 'iso-8859-1', mail.parts[2].content_type_parameters[:charset] end def test_html_mail mail = TestMailer.create_html_mail(@recipient) - assert_equal "text/html", mail.content_type.string + assert_equal "text/html", mail.mime_type end def test_html_mail_with_underscores @@ -1043,7 +1043,7 @@ def test_recursive_multipart_processing assert_equal(4, mail.parts.first.parts.length) assert_equal("This is the first part.", mail.parts.first.parts.first.body.to_s) assert_equal("test.rb", mail.parts.first.parts.second.filename) - assert_equal("flowed", mail.parts.first.parts.fourth.content_type.parameters[:format]) + assert_equal("flowed", mail.parts.first.parts.fourth.content_type_parameters[:format]) assert_equal('smime.p7s', mail.parts.second.filename) end @@ -1081,9 +1081,9 @@ def test_headers_with_nonalpha_chars assert !mail.from_addrs.empty? assert !mail.cc_addrs.empty? assert !mail.bcc_addrs.empty? - assert_match(/:/, mail.from_addrs.to_s) - assert_match(/:/, mail.cc_addrs.to_s) - assert_match(/:/, mail.bcc_addrs.to_s) + assert_match(/:/, mail[:from].decoded) + assert_match(/:/, mail[:cc].decoded) + assert_match(/:/, mail[:bcc].decoded) end def test_deliver_with_mail_object @@ -1095,14 +1095,14 @@ def test_deliver_with_mail_object def test_multipart_with_template_path_with_dots mail = FunkyPathMailer.create_multipart_with_template_path_with_dots(@recipient) assert_equal 2, mail.parts.length - assert "text/plain", mail.parts[1].content_type.string + assert "text/plain", mail.parts[1].mime_type assert "utf-8", mail.parts[1].charset end def test_custom_content_type_attributes mail = TestMailer.create_custom_content_type_attributes - assert_match %r{format="flowed"}, mail.content_type.encoded - assert_match %r{charset="utf-8"}, mail.content_type.encoded + assert_match %r{format=flowed}, mail.content_type + assert_match %r{charset=utf-8}, mail.content_type end def test_return_path_with_create diff --git a/actionmailer/test/quoting_test.rb b/actionmailer/test/quoting_test.rb index b16d16080501afc4c6b321b93b9de70485aa71a1..7640f4b0866f6cda02f76e63c04c34d4dd3dcbac 100644 --- a/actionmailer/test/quoting_test.rb +++ b/actionmailer/test/quoting_test.rb @@ -78,7 +78,7 @@ def test_email_with_partially_quoted_subject mail = Mail.new(IO.read("#{File.dirname(__FILE__)}/fixtures/raw_email_with_partially_quoted_subject")) # CHANGED: subject returns an object now # assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject - assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject.decoded + assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject end private diff --git a/actionmailer/test/test_helper_test.rb b/actionmailer/test/test_helper_test.rb index 86d22da9bfae86d958620b1e093ebfa485a740e5..1fed26f78f6742e4a2fe135fb5610333c2c67a0c 100644 --- a/actionmailer/test/test_helper_test.rb +++ b/actionmailer/test/test_helper_test.rb @@ -19,8 +19,8 @@ def test_setup_sets_right_action_mailer_options def test_setup_creates_the_expected_mailer assert @expected.is_a?(Mail::Message) - assert_equal "1.0", @expected.mime_version.version - assert_equal "text/plain", @expected.content_type.string + assert_equal "1.0", @expected.mime_version + assert_equal "text/plain", @expected.mime_type end def test_mailer_class_is_correctly_inferred diff --git a/actionmailer/test/tmail_compat_test.rb b/actionmailer/test/tmail_compat_test.rb index faa267e3bfc6b8cc0d6d8ecf86be93b914d7b9f3..a1ca6a72437ad251e3b9c8179230abe2a8ad48bb 100644 --- a/actionmailer/test/tmail_compat_test.rb +++ b/actionmailer/test/tmail_compat_test.rb @@ -8,7 +8,7 @@ def test_set_content_type_raises_deprecation_warning assert_nothing_raised do mail.set_content_type "text/plain" end - assert_equal mail.content_type.string, "text/plain" + assert_equal mail.mime_type, "text/plain" end def test_transfer_encoding_raises_deprecation_warning @@ -17,7 +17,7 @@ def test_transfer_encoding_raises_deprecation_warning assert_nothing_raised do mail.transfer_encoding "base64" end - assert_equal mail.content_transfer_encoding.value, "base64" + assert_equal mail.content_transfer_encoding, "base64" end end