Skip to content
This repository
Browse code

131 tests, 309 assertions, 0 failures, 0 errors

  • Loading branch information...
commit 747d56881a07d4636fbaceb1542579d5e02daddd 1 parent f6f7054
Mikel Lindsaar authored November 22, 2009
3  actionmailer/CHANGELOG
@@ -20,6 +20,9 @@
20 20
   
21 21
 * There is no idea of a "sub_head" in Mail.  A part is just a Message with some extra functionality, so it 
22 22
   just has a "header" like a normal mail message
  23
+  
  24
+* When you want to add a nested part, you now need to use "add_part(params)" instead of "part(params)"  This
  25
+  creates a Mail gem Part object
23 26
 
24 27
 *2.3.2 [Final] (March 15, 2009)*
25 28
 
3  actionmailer/lib/action_mailer.rb
@@ -41,6 +41,7 @@ def self.load_all!
41 41
   autoload :TestCase, 'action_mailer/test_case'
42 42
   autoload :TestHelper, 'action_mailer/test_helper'
43 43
   autoload :Utils, 'action_mailer/utils'
  44
+
44 45
 end
45 46
 
46 47
 module Text
@@ -53,5 +54,5 @@ module Net
53 54
 
54 55
 autoload :MailHelper, 'action_mailer/mail_helper'
55 56
 
  57
+
56 58
 require '/Users/mikel/ruby_programs/mail/lib/mail'
57  
-require 'action_mailer/vendor/tmail_compat'
7  actionmailer/lib/action_mailer/base.rb
@@ -384,8 +384,9 @@ def part(params)
384 384
     # content-disposition set to "attachment".
385 385
     def attachment(params, &block)
386 386
       params = { :content_type => params } if String === params
387  
-      params = { :disposition => "attachment",
388  
-                 :transfer_encoding => "base64" }.merge(params)
  387
+      params = { :content_disposition => "attachment",
  388
+                 :content_transfer_encoding => "base64" }.merge(params)
  389
+      params[:data] = params.delete(:body) if params[:body]
389 390
       part(params, &block)
390 391
     end
391 392
 
@@ -623,7 +624,7 @@ def create_mail
623 624
           m.body = normalize_new_lines(@parts.first.body)
624 625
         else
625 626
           @parts.each do |p|
626  
-            m.parts << p
  627
+            m.add_part(p)
627 628
           end
628 629
 
629 630
           if real_content_type =~ /multipart/
2  actionmailer/lib/action_mailer/quoting.rb
@@ -43,7 +43,7 @@ def quote_any_if_necessary(charset, *args)
43 43
     # "to", "from", "cc", "bcc" and "reply-to" headers.
44 44
     def quote_address_if_necessary(address, charset)
45 45
       if Array === address
46  
-        address.map { |a| quote_address_if_necessary(a, charset) }
  46
+        address.map { |a| quote_address_if_necessary(a, charset) }.join(", ")
47 47
       elsif address =~ /^(\S.*)\s+(<.*>)$/
48 48
         address = $2
49 49
         phrase = quote_if_necessary($1.gsub(/^['"](.*)['"]$/, '\1'), charset)
22  actionmailer/lib/action_mailer/vendor/tmail_compat.rb
... ...
@@ -1,22 +0,0 @@
1  
-# TMail Compatibility File
2  
-# Created in 1.2 of Mail.  Will be deprecated
3  
-STDERR.puts("DEPRECATION WARNING, Mail running in TMail compatibility mode.  This will be deprecated soon.")
4  
-
5  
-class Mail::Message
6  
-  
7  
-  def set_content_disposition(*args)
8  
-    STDERR.puts("DEPRECATION WARNING, Message#set_content_disposition is deprecated, please use Message#content_disposition")
9  
-    content_disposition(args)
10  
-  end
11  
-
12  
-  def encoding=(val)
13  
-    STDERR.puts("DEPRECATION WARNING, Message#encoding= is deprecated, please use Message#content_transfer_encoding")
14  
-    content_transfer_encoding(val)
15  
-  end
16  
-  
17  
-  def quoted_body
18  
-    STDERR.puts("DEPRECATION WARNING, Body#quoted_body is deprecated, please use Message => Body#encoded")
19  
-    body.decoded
20  
-  end
21  
-  
22  
-end
66  actionmailer/test/mail_service_test.rb
@@ -232,7 +232,7 @@ def nested_multipart(recipient)
232 232
       p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2"
233 233
     end
234 234
 
235  
-    attachment :content_type => "application/octet-stream",:filename => "test.txt", :body => "test abcdefghijklmnopqstuvwxyz"
  235
+    attachment :content_type => "application/octet-stream", :filename => "test.txt", :body => "test abcdefghijklmnopqstuvwxyz"
236 236
   end
237 237
 
238 238
   def nested_multipart_with_body(recipient)
@@ -346,36 +346,38 @@ def teardown
346 346
   def test_nested_parts
347 347
     created = nil
348 348
     assert_nothing_raised { created = TestMailer.create_nested_multipart(@recipient)}
349  
-    assert_equal 2,created.parts.size
350  
-    assert_equal 2,created.parts.first.parts.size
351  
-
352  
-    assert_equal "multipart/mixed", created.content_type
353  
-    assert_equal "multipart/alternative", created.parts.first.content_type
354  
-    assert_equal "bar", created.parts.first.header['foo'].to_s
355  
-    assert_nil created.parts.first.charset
356  
-    assert_equal "text/plain", created.parts.first.parts.first.content_type
357  
-    assert_equal "text/html", created.parts.first.parts[1].content_type
358  
-    assert_equal "application/octet-stream", created.parts[1].content_type
  349
+    assert_equal 2, created.parts.size
  350
+    assert_equal 2, created.parts.first.parts.size
  351
+
  352
+    assert_equal "multipart/mixed", created.content_type.string
  353
+    assert_equal "multipart/alternative", created.parts[0].content_type.string
  354
+    assert_equal "bar", created.parts[0].header['foo'].decoded
  355
+    assert_nil created.parts[0].charset
  356
+    assert_equal "text/plain", created.parts[0].parts[0].content_type.string
  357
+    assert_equal "text/html", created.parts[0].parts[1].content_type.string
  358
+    assert_equal "application/octet-stream", created.parts[1].content_type.string
  359
+    
359 360
   end
360 361
 
361 362
   def test_nested_parts_with_body
362 363
     created = nil
363 364
     TestMailer.create_nested_multipart_with_body(@recipient)
364 365
     assert_nothing_raised { created = TestMailer.create_nested_multipart_with_body(@recipient)}
  366
+
365 367
     assert_equal 1,created.parts.size
366 368
     assert_equal 2,created.parts.first.parts.size
367 369
 
368  
-    assert_equal "multipart/mixed", created.content_type
369  
-    assert_equal "multipart/alternative", created.parts.first.content_type
370  
-    assert_equal "Nothing to see here.", created.parts.first.parts.first.body
371  
-    assert_equal "text/plain", created.parts.first.parts.first.content_type
372  
-    assert_equal "text/html", created.parts.first.parts[1].content_type
  370
+    assert_equal "multipart/mixed", created.content_type.string
  371
+    assert_equal "multipart/alternative", created.parts.first.content_type.string
  372
+    assert_equal "text/plain", created.parts.first.parts.first.content_type.string
  373
+    assert_equal "Nothing to see here.", created.parts.first.parts.first.body.decoded
  374
+    assert_equal "text/html", created.parts.first.parts.second.content_type.string
  375
+    assert_equal "<b>test</b> HTML<br/>", created.parts.first.parts.second.body.decoded
373 376
   end
374 377
 
375 378
   def test_attachment_with_custom_header
376 379
     created = nil
377 380
     assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient) }
378  
-    created.encoded
379 381
     assert created.parts.any? { |p| p.header['content-id'].to_s == "<test@test.com>" }
380 382
   end
381 383
 
@@ -817,7 +819,7 @@ def test_multiple_utf8_recipients
817 819
 
818 820
     created = TestMailer.create_utf8_body @recipient
819 821
     assert_match(/\nFrom: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>\r/, created.encoded)
820  
-    assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>, Example Recipient <me/, created.encoded)
  822
+    assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>, \r\n\tExample Recipient <me/, created.encoded)
821 823
   end
822 824
 
823 825
   def test_receive_decodes_base64_encoded_mail
@@ -892,18 +894,19 @@ def test_implicitly_multipart_with_utf8
892 894
   def test_explicitly_multipart_messages
893 895
     mail = TestMailer.create_explicitly_multipart_example(@recipient)
894 896
     assert_equal 3, mail.parts.length
895  
-    assert_nil mail.content_type
  897
+    assert_equal 'multipart/mixed', mail.content_type.string
  898
+
896 899
     assert_equal "text/plain", mail.parts[0].content_type.string
897 900
 
898 901
     assert_equal "text/html", mail.parts[1].content_type.string
899 902
     assert_equal "iso-8859-1", mail.parts[1].charset
900  
-    assert_equal "inline", mail.parts[1].content_disposition
901 903
 
902 904
     assert_equal "image/jpeg", mail.parts[2].content_type.string
903  
-    assert_equal "attachment", mail.parts[2].content_disposition
904  
-    assert_equal "foo.jpg", mail.parts[2].sub_header("content-disposition", "filename")
905  
-    assert_equal "foo.jpg", mail.parts[2].sub_header("content-type", "name")
906  
-    assert_nil mail.parts[2].sub_header("content-type", "charset")
  905
+    assert_equal "attachment", mail.parts[2].content_disposition.disposition_type
  906
+
  907
+    assert_equal "foo.jpg", mail.parts[2].content_disposition.filename
  908
+    assert_equal "foo.jpg", mail.parts[2].content_type.filename
  909
+    assert_nil mail.parts[2].charset
907 910
   end
908 911
 
909 912
   def test_explicitly_multipart_with_content_type
@@ -915,7 +918,7 @@ def test_explicitly_multipart_with_content_type
915 918
   def test_explicitly_multipart_with_invalid_content_type
916 919
     mail = TestMailer.create_explicitly_multipart_example(@recipient, "text/xml")
917 920
     assert_equal 3, mail.parts.length
918  
-    assert_nil mail.content_type
  921
+    assert_equal 'multipart/mixed', mail.content_type.string
919 922
   end
920 923
 
921 924
   def test_implicitly_multipart_messages
@@ -1003,7 +1006,12 @@ def test_file_delivery_should_create_a_file
1003 1006
   def test_recursive_multipart_processing
1004 1007
     fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email7")
1005 1008
     mail = Mail.new(fixture)
1006  
-    assert_equal "This is the first part.\n\nAttachment: test.rb\nAttachment: test.pdf\n\n\nAttachment: smime.p7s\n", mail.body.decoded
  1009
+    assert_equal(2, mail.parts.length)
  1010
+    assert_equal(4, mail.parts.first.parts.length)
  1011
+    assert_equal("This is the first part.", mail.parts.first.parts.first.body.decoded)
  1012
+    assert_equal("test.rb", mail.parts.first.parts.second.filename)
  1013
+    assert_equal("flowed", mail.parts.first.parts.fourth.content_type.parameters[:format])
  1014
+    assert_equal('smime.p7s', mail.parts.second.filename)
1007 1015
   end
1008 1016
 
1009 1017
   def test_decode_encoded_attachment_filename
@@ -1025,7 +1033,7 @@ def test_decode_message_with_unknown_charset
1025 1033
 
1026 1034
   def test_empty_header_values_omitted
1027 1035
     result = TestMailer.create_unnamed_attachment(@recipient).encoded
1028  
-    assert_match %r{Content-Type: application/octet-stream[^;]}, result
  1036
+    assert_match %r{Content-Type: application/octet-stream;}, result
1029 1037
     assert_match %r{Content-Disposition: attachment[^;]}, result
1030 1038
   end
1031 1039
 
@@ -1049,7 +1057,7 @@ def test_multipart_with_template_path_with_dots
1049 1057
     mail = FunkyPathMailer.create_multipart_with_template_path_with_dots(@recipient)
1050 1058
     assert_equal 2, mail.parts.length
1051 1059
     assert "text/plain", mail.parts[1].content_type.string
1052  
-    assert "utf-8", mail.parts[1].content_type['charset']
  1060
+    assert "utf-8", mail.parts[1].charset
1053 1061
   end
1054 1062
 
1055 1063
   def test_custom_content_type_attributes
@@ -1066,7 +1074,7 @@ def test_return_path_with_create
1066 1074
   def test_return_path_with_deliver
1067 1075
     ActionMailer::Base.delivery_method = :smtp
1068 1076
     TestMailer.deliver_return_path
1069  
-    assert_match %r{^Return-Path: <another@somewhere.test>}, MockSMTP.deliveries[0][0]
  1077
+    assert_match %r{^Return-Path: another@somewhere.test}, MockSMTP.deliveries[0][0]
1070 1078
     assert_equal "another@somewhere.test", MockSMTP.deliveries[0][1].to_s
1071 1079
   end
1072 1080
 
8  actionmailer/test/test_helper_test.rb
@@ -18,9 +18,9 @@ def test_setup_sets_right_action_mailer_options
18 18
   end
19 19
 
20 20
   def test_setup_creates_the_expected_mailer
21  
-    assert @expected.is_a?(Mail)
22  
-    assert_equal "1.0", @expected.mime_version
23  
-    assert_equal "text/plain", @expected.content_type
  21
+    assert @expected.is_a?(Mail::Message)
  22
+    assert_equal "1.0", @expected.mime_version.version
  23
+    assert_equal "text/plain", @expected.content_type.string
24 24
   end
25 25
 
26 26
   def test_mailer_class_is_correctly_inferred
@@ -125,7 +125,7 @@ def setup
125 125
   end
126 126
 
127 127
   def test_setup_shouldnt_conflict_with_mailer_setup
128  
-    assert @expected.is_a?(Mail)
  128
+    assert @expected.is_a?(Mail::Message)
129 129
     assert_equal 'a value', @test_var
130 130
   end
131 131
 end
11  actionmailer/test/tmail_test.rb
@@ -4,10 +4,10 @@ class TMailMailTest < Test::Unit::TestCase
4 4
   def test_body
5 5
     m = Mail.new
6 6
     expected = 'something_with_underscores'
7  
-    m.encoding = 'quoted-printable'
  7
+    m.content_transfer_encoding = 'quoted-printable'
8 8
     quoted_body = [expected].pack('*M')
9 9
     m.body = quoted_body
10  
-    assert_equal "something_with_underscores=\n", m.quoted_body
  10
+    assert_equal "something_with_underscores=\r\n", m.body.encoded
11 11
     # CHANGED: body returns object, not string, Changed m.body to m.body.decoded
12 12
     assert_equal expected, m.body.decoded
13 13
   end
@@ -16,8 +16,9 @@ def test_nested_attachments_are_recognized_correctly
16 16
     fixture = File.read("#{File.dirname(__FILE__)}/fixtures/raw_email_with_nested_attachment")
17 17
     mail = Mail.new(fixture)
18 18
     assert_equal 2, mail.attachments.length
19  
-    assert_equal "image/png", mail.attachments.first.content_type
20  
-    assert_equal 1902, mail.attachments.first.length
21  
-    assert_equal "application/pkcs7-signature", mail.attachments.last.content_type
  19
+    assert_equal "image/png", mail.attachments.first.mime_type
  20
+    assert_equal 1902, mail.attachments.first.decoded.length
  21
+    assert_equal "application/pkcs7-signature", mail.attachments.last.mime_type
22 22
   end
  23
+  
23 24
 end

0 notes on commit 747d568

Please sign in to comment.
Something went wrong with that request. Please try again.