Skip to content
This repository
Browse code

Updating to Mail 1.5.0, including default values for all Message#fiel…

…d_name methods, can access field objects by calling Message#[:field_name]
  • Loading branch information...
commit bf6d0e2bc2c839d03d14629572ef48d8b9335cbf 1 parent 4939f95
Mikel Lindsaar authored January 03, 2010 jeremy committed January 02, 2010
9  actionmailer/CHANGELOG
... ...
@@ -1,13 +1,14 @@
1 1
 *Rails 3.0 (pending)*
2 2
 
3  
-* 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.
  3
+* 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
4 4
 
5  
-* Mail does not have "quoted_body", "quoted_subject" etc.  All of these are accessed via body.encoded, subject.encoded etc
  5
+* 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'}
6 6
 
7  
-* 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.
  7
+* 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.
8 8
 
9  
-* 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
  9
+* Mail does not have "quoted_body", "quoted_subject" etc.  All of these are accessed via body.encoded, subject.encoded etc
10 10
 
  11
+* 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.
11 12
 * Mail::Message#set_content_type does not exist, it is simply Mail::Message#content_type
12 13
 
13 14
 * 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
2  actionmailer/actionmailer.gemspec
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11 11
   s.homepage = "http://www.rubyonrails.org"
12 12
 
13 13
   s.add_dependency('actionpack', '= 3.0.pre')
14  
-  s.add_dependency('mail', '~> 1.4.3')
  14
+  s.add_dependency('mail', '~> 1.5.0')
15 15
 
16 16
   s.files = Dir['CHANGELOG', 'README', 'MIT-LICENSE', 'lib/**/*']
17 17
   s.has_rdoc = true
18  actionmailer/test/mail_layout_test.rb
@@ -72,12 +72,12 @@ def test_should_pickup_multipart_layout
72 72
     mail = AutoLayoutMailer.create_multipart(@recipient)
73 73
     # CHANGED: content_type returns an object
74 74
     # assert_equal "multipart/alternative", mail.content_type
75  
-    assert_equal "multipart/alternative", mail.content_type.string
  75
+    assert_equal "multipart/alternative", mail.mime_type
76 76
     assert_equal 2, mail.parts.size
77 77
 
78 78
     # CHANGED: content_type returns an object
79 79
     # assert_equal 'text/plain', mail.parts.first.content_type
80  
-    assert_equal 'text/plain', mail.parts.first.content_type.string
  80
+    assert_equal 'text/plain', mail.parts.first.mime_type
81 81
     
82 82
     # CHANGED: body returns an object
83 83
     # assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
@@ -85,7 +85,7 @@ def test_should_pickup_multipart_layout
85 85
 
86 86
     # CHANGED: content_type returns an object
87 87
     # assert_equal 'text/html', mail.parts.last.content_type
88  
-    assert_equal 'text/html', mail.parts.last.content_type.string
  88
+    assert_equal 'text/html', mail.parts.last.mime_type
89 89
 
90 90
     # CHANGED: body returns an object
91 91
     # assert_equal "Hello from layout text/html multipart", mail.parts.last.body
@@ -96,19 +96,19 @@ def test_should_pickup_multipartmixed_layout
96 96
     mail = AutoLayoutMailer.create_multipart(@recipient, "multipart/mixed")
97 97
     # CHANGED: content_type returns an object
98 98
     # assert_equal "multipart/mixed", mail.content_type
99  
-    assert_equal "multipart/mixed", mail.content_type.string
  99
+    assert_equal "multipart/mixed", mail.mime_type
100 100
     assert_equal 2, mail.parts.size
101 101
 
102 102
     # CHANGED: content_type returns an object
103 103
     # assert_equal 'text/plain', mail.parts.first.content_type
104  
-    assert_equal 'text/plain', mail.parts.first.content_type.string
  104
+    assert_equal 'text/plain', mail.parts.first.mime_type
105 105
     # CHANGED: body returns an object
106 106
     # assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
107 107
     assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s
108 108
 
109 109
     # CHANGED: content_type returns an object
110 110
     # assert_equal 'text/html', mail.parts.last.content_type
111  
-    assert_equal 'text/html', mail.parts.last.content_type.string
  111
+    assert_equal 'text/html', mail.parts.last.mime_type
112 112
     # CHANGED: body returns an object
113 113
     # assert_equal "Hello from layout text/html multipart", mail.parts.last.body
114 114
     assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s
@@ -116,13 +116,13 @@ def test_should_pickup_multipartmixed_layout
116 116
 
117 117
   def test_should_fix_multipart_layout
118 118
     mail = AutoLayoutMailer.create_multipart(@recipient, "text/plain")
119  
-    assert_equal "multipart/alternative", mail.content_type.string
  119
+    assert_equal "multipart/alternative", mail.mime_type
120 120
     assert_equal 2, mail.parts.size
121 121
 
122  
-    assert_equal 'text/plain', mail.parts.first.content_type.string
  122
+    assert_equal 'text/plain', mail.parts.first.mime_type
123 123
     assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s
124 124
 
125  
-    assert_equal 'text/html', mail.parts.last.content_type.string
  125
+    assert_equal 'text/html', mail.parts.last.mime_type
126 126
     assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s
127 127
   end
128 128
 
88  actionmailer/test/mail_service_test.rb
@@ -362,13 +362,13 @@ def test_nested_parts
362 362
     assert_equal 2, created.parts.size
363 363
     assert_equal 2, created.parts.first.parts.size
364 364
 
365  
-    assert_equal "multipart/mixed", created.content_type.string
366  
-    assert_equal "multipart/alternative", created.parts[0].content_type.string
  365
+    assert_equal "multipart/mixed", created.mime_type
  366
+    assert_equal "multipart/alternative", created.parts[0].mime_type
367 367
     assert_equal "bar", created.parts[0].header['foo'].to_s
368 368
     assert_nil created.parts[0].charset
369  
-    assert_equal "text/plain", created.parts[0].parts[0].content_type.string
370  
-    assert_equal "text/html", created.parts[0].parts[1].content_type.string
371  
-    assert_equal "application/octet-stream", created.parts[1].content_type.string
  369
+    assert_equal "text/plain", created.parts[0].parts[0].mime_type
  370
+    assert_equal "text/html", created.parts[0].parts[1].mime_type
  371
+    assert_equal "application/octet-stream", created.parts[1].mime_type
372 372
     
373 373
   end
374 374
 
@@ -380,11 +380,11 @@ def test_nested_parts_with_body
380 380
     assert_equal 1,created.parts.size
381 381
     assert_equal 2,created.parts.first.parts.size
382 382
 
383  
-    assert_equal "multipart/mixed", created.content_type.string
384  
-    assert_equal "multipart/alternative", created.parts.first.content_type.string
385  
-    assert_equal "text/plain", created.parts.first.parts.first.content_type.string
  383
+    assert_equal "multipart/mixed", created.mime_type
  384
+    assert_equal "multipart/alternative", created.parts.first.mime_type
  385
+    assert_equal "text/plain", created.parts.first.parts.first.mime_type
386 386
     assert_equal "Nothing to see here.", created.parts.first.parts.first.body.to_s
387  
-    assert_equal "text/html", created.parts.first.parts.second.content_type.string
  387
+    assert_equal "text/html", created.parts.first.parts.second.mime_type
388 388
     assert_equal "<b>test</b> HTML<br/>", created.parts.first.parts.second.body.to_s
389 389
   end
390 390
 
@@ -468,8 +468,8 @@ def test_custom_templating_extension
468 468
     assert_nothing_raised { created = TestMailer.create_custom_templating_extension(@recipient) }
469 469
     assert_not_nil created
470 470
     assert_equal 2, created.parts.length
471  
-    assert_equal 'text/plain', created.parts[0].content_type.string
472  
-    assert_equal 'text/html', created.parts[1].content_type.string
  471
+    assert_equal 'text/plain', created.parts[0].mime_type
  472
+    assert_equal 'text/html', created.parts[1].mime_type
473 473
   end
474 474
 
475 475
   def test_cancelled_account
@@ -731,8 +731,8 @@ def test_unquote_quoted_printable_subject
731 731
 The body
732 732
 EOF
733 733
     mail = Mail.new(msg)
734  
-    assert_equal "testing testing \326\244", mail.subject.to_s
735  
-    assert_equal "Subject: =?utf-8?Q?testing_testing_=D6=A4?=\r\n", mail.subject.encoded
  734
+    assert_equal "testing testing \326\244", mail.subject
  735
+    assert_equal "Subject: =?utf-8?Q?testing_testing_=D6=A4?=\r\n", mail[:subject].encoded
736 736
   end
737 737
 
738 738
   def test_unquote_7bit_subject
@@ -744,8 +744,8 @@ def test_unquote_7bit_subject
744 744
 The body
745 745
 EOF
746 746
     mail = Mail.new(msg)
747  
-    assert_equal "this == working?", mail.subject.to_s
748  
-    assert_equal "Subject: this == working?\r\n", mail.subject.encoded
  747
+    assert_equal "this == working?", mail.subject
  748
+    assert_equal "Subject: this == working?\r\n", mail[:subject].encoded
749 749
   end
750 750
 
751 751
   def test_unquote_7bit_body
@@ -868,7 +868,7 @@ def test_receive_attachments
868 868
     mail = Mail.new(fixture)
869 869
     attachment = mail.attachments.last
870 870
     assert_equal "smime.p7s", attachment.original_filename
871  
-    assert_equal "application/pkcs7-signature", mail.parts.last.content_type.string
  871
+    assert_equal "application/pkcs7-signature", mail.parts.last.mime_type
872 872
   end
873 873
 
874 874
   def test_decode_attachment_without_charset
@@ -913,7 +913,7 @@ def test_decode_message_with_incorrect_charset
913 913
 
914 914
   def test_multipart_with_mime_version
915 915
     mail = TestMailer.create_multipart_with_mime_version(@recipient)
916  
-    assert_equal "1.1", mail.mime_version.version
  916
+    assert_equal "1.1", mail.mime_version
917 917
   end
918 918
 
919 919
   def test_multipart_with_utf8_subject
@@ -929,29 +929,29 @@ def test_implicitly_multipart_with_utf8
929 929
   def test_explicitly_multipart_messages
930 930
     mail = TestMailer.create_explicitly_multipart_example(@recipient)
931 931
     assert_equal 3, mail.parts.length
932  
-    assert_equal 'multipart/mixed', mail.content_type.string
933  
-    assert_equal "text/plain", mail.parts[0].content_type.string
  932
+    assert_equal 'multipart/mixed', mail.mime_type
  933
+    assert_equal "text/plain", mail.parts[0].mime_type
934 934
 
935  
-    assert_equal "text/html", mail.parts[1].content_type.string
  935
+    assert_equal "text/html", mail.parts[1].mime_type
936 936
     assert_equal "iso-8859-1", mail.parts[1].charset
937 937
 
938  
-    assert_equal "image/jpeg", mail.parts[2].content_type.string
939  
-    assert_equal "attachment", mail.parts[2].content_disposition.disposition_type
940  
-    assert_equal "foo.jpg", mail.parts[2].content_disposition.filename
941  
-    assert_equal "foo.jpg", mail.parts[2].content_type.filename
  938
+    assert_equal "image/jpeg", mail.parts[2].mime_type
  939
+    assert_equal "attachment", mail.parts[2][:content_disposition].disposition_type
  940
+    assert_equal "foo.jpg", mail.parts[2][:content_disposition].filename
  941
+    assert_equal "foo.jpg", mail.parts[2][:content_type].filename
942 942
     assert_nil mail.parts[2].charset
943 943
   end
944 944
 
945 945
   def test_explicitly_multipart_with_content_type
946 946
     mail = TestMailer.create_explicitly_multipart_example(@recipient, "multipart/alternative")
947 947
     assert_equal 3, mail.parts.length
948  
-    assert_equal "multipart/alternative", mail.content_type.string
  948
+    assert_equal "multipart/alternative", mail.mime_type
949 949
   end
950 950
 
951 951
   def test_explicitly_multipart_with_invalid_content_type
952 952
     mail = TestMailer.create_explicitly_multipart_example(@recipient, "text/xml")
953 953
     assert_equal 3, mail.parts.length
954  
-    assert_equal 'multipart/mixed', mail.content_type.string
  954
+    assert_equal 'multipart/mixed', mail.mime_type
955 955
   end
956 956
 
957 957
   def test_implicitly_multipart_messages
@@ -960,12 +960,12 @@ def test_implicitly_multipart_messages
960 960
     mail = TestMailer.create_implicitly_multipart_example(@recipient)
961 961
     assert_equal 3, mail.parts.length
962 962
     assert_equal "1.0", mail.mime_version.to_s
963  
-    assert_equal "multipart/alternative", mail.content_type.string
964  
-    assert_equal "text/plain", mail.parts[0].content_type.string
  963
+    assert_equal "multipart/alternative", mail.mime_type
  964
+    assert_equal "text/plain", mail.parts[0].mime_type
965 965
     assert_equal "utf-8", mail.parts[0].charset
966  
-    assert_equal "text/html", mail.parts[1].content_type.string
  966
+    assert_equal "text/html", mail.parts[1].mime_type
967 967
     assert_equal "utf-8", mail.parts[1].charset
968  
-    assert_equal "application/x-yaml", mail.parts[2].content_type.string
  968
+    assert_equal "application/x-yaml", mail.parts[2].mime_type
969 969
     assert_equal "utf-8", mail.parts[2].charset
970 970
   end
971 971
 
@@ -974,9 +974,9 @@ def test_implicitly_multipart_messages_with_custom_order
974 974
 
975 975
     mail = TestMailer.create_implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"])
976 976
     assert_equal 3, mail.parts.length
977  
-    assert_equal "application/x-yaml", mail.parts[0].content_type.string
978  
-    assert_equal "text/plain", mail.parts[1].content_type.string
979  
-    assert_equal "text/html", mail.parts[2].content_type.string
  977
+    assert_equal "application/x-yaml", mail.parts[0].mime_type
  978
+    assert_equal "text/plain", mail.parts[1].mime_type
  979
+    assert_equal "text/html", mail.parts[2].mime_type
980 980
   end
981 981
 
982 982
   def test_implicitly_multipart_messages_with_charset
@@ -984,14 +984,14 @@ def test_implicitly_multipart_messages_with_charset
984 984
 
985 985
     assert_equal "multipart/alternative", mail.header['content-type'].content_type
986 986
 
987  
-    assert_equal 'iso-8859-1', mail.parts[0].content_type.parameters[:charset]
988  
-    assert_equal 'iso-8859-1', mail.parts[1].content_type.parameters[:charset]
989  
-    assert_equal 'iso-8859-1', mail.parts[2].content_type.parameters[:charset]
  987
+    assert_equal 'iso-8859-1', mail.parts[0].content_type_parameters[:charset]
  988
+    assert_equal 'iso-8859-1', mail.parts[1].content_type_parameters[:charset]
  989
+    assert_equal 'iso-8859-1', mail.parts[2].content_type_parameters[:charset]
990 990
   end
991 991
 
992 992
   def test_html_mail
993 993
     mail = TestMailer.create_html_mail(@recipient)
994  
-    assert_equal "text/html", mail.content_type.string
  994
+    assert_equal "text/html", mail.mime_type
995 995
   end
996 996
 
997 997
   def test_html_mail_with_underscores
@@ -1043,7 +1043,7 @@ def test_recursive_multipart_processing
1043 1043
     assert_equal(4, mail.parts.first.parts.length)
1044 1044
     assert_equal("This is the first part.", mail.parts.first.parts.first.body.to_s)
1045 1045
     assert_equal("test.rb", mail.parts.first.parts.second.filename)
1046  
-    assert_equal("flowed", mail.parts.first.parts.fourth.content_type.parameters[:format])
  1046
+    assert_equal("flowed", mail.parts.first.parts.fourth.content_type_parameters[:format])
1047 1047
     assert_equal('smime.p7s', mail.parts.second.filename)
1048 1048
   end
1049 1049
 
@@ -1081,9 +1081,9 @@ def test_headers_with_nonalpha_chars
1081 1081
     assert !mail.from_addrs.empty?
1082 1082
     assert !mail.cc_addrs.empty?
1083 1083
     assert !mail.bcc_addrs.empty?
1084  
-    assert_match(/:/, mail.from_addrs.to_s)
1085  
-    assert_match(/:/, mail.cc_addrs.to_s)
1086  
-    assert_match(/:/, mail.bcc_addrs.to_s)
  1084
+    assert_match(/:/, mail[:from].decoded)
  1085
+    assert_match(/:/, mail[:cc].decoded)
  1086
+    assert_match(/:/, mail[:bcc].decoded)
1087 1087
   end
1088 1088
 
1089 1089
   def test_deliver_with_mail_object
@@ -1095,14 +1095,14 @@ def test_deliver_with_mail_object
1095 1095
   def test_multipart_with_template_path_with_dots
1096 1096
     mail = FunkyPathMailer.create_multipart_with_template_path_with_dots(@recipient)
1097 1097
     assert_equal 2, mail.parts.length
1098  
-    assert "text/plain", mail.parts[1].content_type.string
  1098
+    assert "text/plain", mail.parts[1].mime_type
1099 1099
     assert "utf-8", mail.parts[1].charset
1100 1100
   end
1101 1101
 
1102 1102
   def test_custom_content_type_attributes
1103 1103
     mail = TestMailer.create_custom_content_type_attributes
1104  
-    assert_match %r{format="flowed"}, mail.content_type.encoded
1105  
-    assert_match %r{charset="utf-8"}, mail.content_type.encoded
  1104
+    assert_match %r{format=flowed}, mail.content_type
  1105
+    assert_match %r{charset=utf-8}, mail.content_type
1106 1106
   end
1107 1107
 
1108 1108
   def test_return_path_with_create
2  actionmailer/test/quoting_test.rb
@@ -78,7 +78,7 @@ def test_email_with_partially_quoted_subject
78 78
     mail = Mail.new(IO.read("#{File.dirname(__FILE__)}/fixtures/raw_email_with_partially_quoted_subject"))
79 79
     # CHANGED: subject returns an object now
80 80
     # assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject
81  
-    assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject.decoded
  81
+    assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject
82 82
   end
83 83
 
84 84
   private
4  actionmailer/test/test_helper_test.rb
@@ -19,8 +19,8 @@ def test_setup_sets_right_action_mailer_options
19 19
 
20 20
   def test_setup_creates_the_expected_mailer
21 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
  22
+    assert_equal "1.0", @expected.mime_version
  23
+    assert_equal "text/plain", @expected.mime_type
24 24
   end
25 25
 
26 26
   def test_mailer_class_is_correctly_inferred
4  actionmailer/test/tmail_compat_test.rb
@@ -8,7 +8,7 @@ def test_set_content_type_raises_deprecation_warning
8 8
     assert_nothing_raised do
9 9
       mail.set_content_type "text/plain"
10 10
     end
11  
-    assert_equal mail.content_type.string, "text/plain"
  11
+    assert_equal mail.mime_type, "text/plain"
12 12
   end
13 13
 
14 14
   def test_transfer_encoding_raises_deprecation_warning
@@ -17,7 +17,7 @@ def test_transfer_encoding_raises_deprecation_warning
17 17
     assert_nothing_raised do
18 18
       mail.transfer_encoding "base64"
19 19
     end
20  
-    assert_equal mail.content_transfer_encoding.value, "base64"
  20
+    assert_equal mail.content_transfer_encoding, "base64"
21 21
   end
22 22
   
23 23
 end

0 notes on commit bf6d0e2

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