Permalink
Browse files

131 tests, 309 assertions, 0 failures, 0 errors

  • Loading branch information...
1 parent f6f7054 commit 747d56881a07d4636fbaceb1542579d5e02daddd @mikel mikel committed Nov 22, 2009
View
@@ -20,6 +20,9 @@
* There is no idea of a "sub_head" in Mail. A part is just a Message with some extra functionality, so it
just has a "header" like a normal mail message
+
+* When you want to add a nested part, you now need to use "add_part(params)" instead of "part(params)" This
+ creates a Mail gem Part object
*2.3.2 [Final] (March 15, 2009)*
@@ -41,6 +41,7 @@ def self.load_all!
autoload :TestCase, 'action_mailer/test_case'
autoload :TestHelper, 'action_mailer/test_helper'
autoload :Utils, 'action_mailer/utils'
+
end
module Text
@@ -53,5 +54,5 @@ module Net
autoload :MailHelper, 'action_mailer/mail_helper'
+
require '/Users/mikel/ruby_programs/mail/lib/mail'
-require 'action_mailer/vendor/tmail_compat'
@@ -384,8 +384,9 @@ def part(params)
# content-disposition set to "attachment".
def attachment(params, &block)
params = { :content_type => params } if String === params
- params = { :disposition => "attachment",
- :transfer_encoding => "base64" }.merge(params)
+ params = { :content_disposition => "attachment",
+ :content_transfer_encoding => "base64" }.merge(params)
+ params[:data] = params.delete(:body) if params[:body]
part(params, &block)
end
@@ -623,7 +624,7 @@ def create_mail
m.body = normalize_new_lines(@parts.first.body)
else
@parts.each do |p|
- m.parts << p
+ m.add_part(p)
end
if real_content_type =~ /multipart/
@@ -43,7 +43,7 @@ def quote_any_if_necessary(charset, *args)
# "to", "from", "cc", "bcc" and "reply-to" headers.
def quote_address_if_necessary(address, charset)
if Array === address
- address.map { |a| quote_address_if_necessary(a, charset) }
+ address.map { |a| quote_address_if_necessary(a, charset) }.join(", ")
elsif address =~ /^(\S.*)\s+(<.*>)$/
address = $2
phrase = quote_if_necessary($1.gsub(/^['"](.*)['"]$/, '\1'), charset)
@@ -1,22 +0,0 @@
-# TMail Compatibility File
-# Created in 1.2 of Mail. Will be deprecated
-STDERR.puts("DEPRECATION WARNING, Mail running in TMail compatibility mode. This will be deprecated soon.")
-
-class Mail::Message
-
- def set_content_disposition(*args)
- STDERR.puts("DEPRECATION WARNING, Message#set_content_disposition is deprecated, please use Message#content_disposition")
- content_disposition(args)
- end
-
- def encoding=(val)
- STDERR.puts("DEPRECATION WARNING, Message#encoding= is deprecated, please use Message#content_transfer_encoding")
- content_transfer_encoding(val)
- end
-
- def quoted_body
- STDERR.puts("DEPRECATION WARNING, Body#quoted_body is deprecated, please use Message => Body#encoded")
- body.decoded
- end
-
-end
@@ -232,7 +232,7 @@ 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"
+ attachment :content_type => "application/octet-stream", :filename => "test.txt", :body => "test abcdefghijklmnopqstuvwxyz"
end
def nested_multipart_with_body(recipient)
@@ -346,36 +346,38 @@ def teardown
def test_nested_parts
created = nil
assert_nothing_raised { created = TestMailer.create_nested_multipart(@recipient)}
- assert_equal 2,created.parts.size
- assert_equal 2,created.parts.first.parts.size
-
- assert_equal "multipart/mixed", created.content_type
- assert_equal "multipart/alternative", created.parts.first.content_type
- assert_equal "bar", created.parts.first.header['foo'].to_s
- assert_nil created.parts.first.charset
- assert_equal "text/plain", created.parts.first.parts.first.content_type
- assert_equal "text/html", created.parts.first.parts[1].content_type
- assert_equal "application/octet-stream", created.parts[1].content_type
+ 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 "bar", created.parts[0].header['foo'].decoded
+ 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
+
end
def test_nested_parts_with_body
created = nil
TestMailer.create_nested_multipart_with_body(@recipient)
assert_nothing_raised { created = TestMailer.create_nested_multipart_with_body(@recipient)}
+
assert_equal 1,created.parts.size
assert_equal 2,created.parts.first.parts.size
- assert_equal "multipart/mixed", created.content_type
- assert_equal "multipart/alternative", created.parts.first.content_type
- assert_equal "Nothing to see here.", created.parts.first.parts.first.body
- assert_equal "text/plain", created.parts.first.parts.first.content_type
- assert_equal "text/html", created.parts.first.parts[1].content_type
+ 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 "Nothing to see here.", created.parts.first.parts.first.body.decoded
+ assert_equal "text/html", created.parts.first.parts.second.content_type.string
+ assert_equal "<b>test</b> HTML<br/>", created.parts.first.parts.second.body.decoded
end
def test_attachment_with_custom_header
created = nil
assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient) }
- created.encoded
assert created.parts.any? { |p| p.header['content-id'].to_s == "<test@test.com>" }
end
@@ -817,7 +819,7 @@ def test_multiple_utf8_recipients
created = TestMailer.create_utf8_body @recipient
assert_match(/\nFrom: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>\r/, created.encoded)
- assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>, Example Recipient <me/, created.encoded)
+ assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>, \r\n\tExample Recipient <me/, created.encoded)
end
def test_receive_decodes_base64_encoded_mail
@@ -892,18 +894,19 @@ 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_nil mail.content_type
+ assert_equal 'multipart/mixed', mail.content_type.string
+
assert_equal "text/plain", mail.parts[0].content_type.string
assert_equal "text/html", mail.parts[1].content_type.string
assert_equal "iso-8859-1", mail.parts[1].charset
- assert_equal "inline", mail.parts[1].content_disposition
assert_equal "image/jpeg", mail.parts[2].content_type.string
- assert_equal "attachment", mail.parts[2].content_disposition
- assert_equal "foo.jpg", mail.parts[2].sub_header("content-disposition", "filename")
- assert_equal "foo.jpg", mail.parts[2].sub_header("content-type", "name")
- assert_nil mail.parts[2].sub_header("content-type", "charset")
+ 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
@@ -915,7 +918,7 @@ def test_explicitly_multipart_with_content_type
def test_explicitly_multipart_with_invalid_content_type
mail = TestMailer.create_explicitly_multipart_example(@recipient, "text/xml")
assert_equal 3, mail.parts.length
- assert_nil mail.content_type
+ assert_equal 'multipart/mixed', mail.content_type.string
end
def test_implicitly_multipart_messages
@@ -1003,7 +1006,12 @@ def test_file_delivery_should_create_a_file
def test_recursive_multipart_processing
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email7")
mail = Mail.new(fixture)
- assert_equal "This is the first part.\n\nAttachment: test.rb\nAttachment: test.pdf\n\n\nAttachment: smime.p7s\n", mail.body.decoded
+ assert_equal(2, mail.parts.length)
+ assert_equal(4, mail.parts.first.parts.length)
+ assert_equal("This is the first part.", mail.parts.first.parts.first.body.decoded)
+ assert_equal("test.rb", mail.parts.first.parts.second.filename)
+ assert_equal("flowed", mail.parts.first.parts.fourth.content_type.parameters[:format])
+ assert_equal('smime.p7s', mail.parts.second.filename)
end
def test_decode_encoded_attachment_filename
@@ -1025,7 +1033,7 @@ def test_decode_message_with_unknown_charset
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-Type: application/octet-stream;}, result
assert_match %r{Content-Disposition: attachment[^;]}, result
end
@@ -1049,7 +1057,7 @@ 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 "utf-8", mail.parts[1].content_type['charset']
+ assert "utf-8", mail.parts[1].charset
end
def test_custom_content_type_attributes
@@ -1066,7 +1074,7 @@ def test_return_path_with_create
def test_return_path_with_deliver
ActionMailer::Base.delivery_method = :smtp
TestMailer.deliver_return_path
- assert_match %r{^Return-Path: <another@somewhere.test>}, MockSMTP.deliveries[0][0]
+ assert_match %r{^Return-Path: another@somewhere.test}, MockSMTP.deliveries[0][0]
assert_equal "another@somewhere.test", MockSMTP.deliveries[0][1].to_s
end
@@ -18,9 +18,9 @@ def test_setup_sets_right_action_mailer_options
end
def test_setup_creates_the_expected_mailer
- assert @expected.is_a?(Mail)
- assert_equal "1.0", @expected.mime_version
- assert_equal "text/plain", @expected.content_type
+ assert @expected.is_a?(Mail::Message)
+ assert_equal "1.0", @expected.mime_version.version
+ assert_equal "text/plain", @expected.content_type.string
end
def test_mailer_class_is_correctly_inferred
@@ -125,7 +125,7 @@ def setup
end
def test_setup_shouldnt_conflict_with_mailer_setup
- assert @expected.is_a?(Mail)
+ assert @expected.is_a?(Mail::Message)
assert_equal 'a value', @test_var
end
end
@@ -4,10 +4,10 @@ class TMailMailTest < Test::Unit::TestCase
def test_body
m = Mail.new
expected = 'something_with_underscores'
- m.encoding = 'quoted-printable'
+ m.content_transfer_encoding = 'quoted-printable'
quoted_body = [expected].pack('*M')
m.body = quoted_body
- assert_equal "something_with_underscores=\n", m.quoted_body
+ assert_equal "something_with_underscores=\r\n", m.body.encoded
# CHANGED: body returns object, not string, Changed m.body to m.body.decoded
assert_equal expected, m.body.decoded
end
@@ -16,8 +16,9 @@ def test_nested_attachments_are_recognized_correctly
fixture = File.read("#{File.dirname(__FILE__)}/fixtures/raw_email_with_nested_attachment")
mail = Mail.new(fixture)
assert_equal 2, mail.attachments.length
- assert_equal "image/png", mail.attachments.first.content_type
- assert_equal 1902, mail.attachments.first.length
- assert_equal "application/pkcs7-signature", mail.attachments.last.content_type
+ assert_equal "image/png", mail.attachments.first.mime_type
+ assert_equal 1902, mail.attachments.first.decoded.length
+ assert_equal "application/pkcs7-signature", mail.attachments.last.mime_type
end
+
end

0 comments on commit 747d568

Please sign in to comment.