Skip to content

Commit

Permalink
Updating to Mail 1.5.0, including default values for all Message#fiel…
Browse files Browse the repository at this point in the history
…d_name methods, can access field objects by calling Message#[:field_name]
  • Loading branch information
mikel authored and jeremy committed Jan 3, 2010
1 parent 4939f95 commit bf6d0e2
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 63 deletions.
9 changes: 5 additions & 4 deletions actionmailer/CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion actionmailer/actionmailer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Gem::Specification.new do |s|
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
Expand Down
18 changes: 9 additions & 9 deletions actionmailer/test/mail_layout_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,20 @@ 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
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
Expand All @@ -96,33 +96,33 @@ 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
end

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

Expand Down
88 changes: 44 additions & 44 deletions actionmailer/test/mail_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 "<b>test</b> HTML<br/>", created.parts.first.parts.second.body.to_s
end

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -974,24 +974,24 @@ 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
mail = TestMailer.create_implicitly_multipart_example(@recipient, 'iso-8859-1')

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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion actionmailer/test/quoting_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions actionmailer/test/test_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions actionmailer/test/tmail_compat_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit bf6d0e2

Please sign in to comment.