Changeset 3959
- Timestamp:
- 03/18/06 23:53:07 (3 years ago)
- Files:
-
- trunk/actionmailer/CHANGELOG (modified) (1 diff)
- trunk/actionmailer/lib/action_mailer/base.rb (modified) (3 diffs)
- trunk/actionmailer/lib/action_mailer/part_container.rb (modified) (1 diff)
- trunk/actionmailer/lib/action_mailer/part.rb (modified) (5 diffs)
- trunk/actionmailer/test/mail_service_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionmailer/CHANGELOG
r3956 r3959 1 1 *SVN* 2 3 * Parse content-type apart before using it so that sub-parts of the header can be set correctly #2918 [Jamis Buck] 2 4 3 5 * Make custom headers work in subparts #4034 [elan@bluemandrill.com] trunk/actionmailer/lib/action_mailer/base.rb
r3955 r3959 414 414 headers.each { |k, v| m[k] = v } 415 415 416 real_content_type, ctype_attrs = parse_content_type 417 416 418 if @parts.empty? 417 m.set_content_type content_type, nil, { "charset" => charset }419 m.set_content_type(real_content_type, nil, ctype_attrs) 418 420 m.body = Utils.normalize_new_lines(body) 419 421 else … … 421 423 part = TMail::Mail.new 422 424 part.body = Utils.normalize_new_lines(body) 423 part.set_content_type content_type, nil, { "charset" => charset }425 part.set_content_type(real_content_type, nil, ctype_attrs) 424 426 part.set_content_disposition "inline" 425 427 m.parts << part … … 431 433 end 432 434 433 m.set_content_type( content_type, nil, { "charset" => charset }) ifcontent_type =~ /multipart/435 m.set_content_type(real_content_type, nil, ctype_attrs) if real_content_type =~ /multipart/ 434 436 end 435 437 trunk/actionmailer/lib/action_mailer/part_container.rb
r2743 r3959 39 39 end 40 40 41 private 42 43 def parse_content_type(defaults=nil) 44 return [defaults && defaults.content_type, {}] if content_type.blank? 45 ctype, *attrs = content_type.split(/;\s*/) 46 attrs = attrs.inject({}) { |h,s| k,v = s.split(/=/, 2); h[k] = v; h } 47 [ctype, {"charset" => charset || defaults && defaults.charset}.merge(attrs)] 48 end 49 41 50 end 42 51 end trunk/actionmailer/lib/action_mailer/part.rb
r3956 r3959 57 57 part = TMail::Mail.new 58 58 59 real_content_type, ctype_attrs = parse_content_type(defaults) 60 59 61 if @parts.empty? 60 62 part.content_transfer_encoding = transfer_encoding || "quoted-printable" … … 72 74 # non-attachment parts) 73 75 if content_disposition == "attachment" 74 part.set_content_type(content_type || defaults.content_type, nil, 75 squish("charset" => nil, "name" => filename)) 76 ctype_attrs.delete "charset" 77 part.set_content_type(real_content_type, nil, 78 squish("name" => filename).merge(ctype_attrs)) 76 79 part.set_content_disposition(content_disposition, 77 squish("filename" => filename) )80 squish("filename" => filename).merge(ctype_attrs)) 78 81 else 79 part.set_content_type(content_type || defaults.content_type, nil, 80 "charset" => (charset || defaults.charset)) 82 part.set_content_type(real_content_type, nil, ctype_attrs) 81 83 part.set_content_disposition(content_disposition) 82 84 end … … 85 87 part = TMail::Mail.new 86 88 part.body = body 87 part.set_content_type content_type, nil, { "charset" => charset }89 part.set_content_type(real_content_type, nil, ctype_attrs) 88 90 part.set_content_disposition "inline" 89 91 m.parts << part … … 95 97 end 96 98 97 part.set_content_type( content_type, nil, { "charset" => charset }) ifcontent_type =~ /multipart/99 part.set_content_type(real_content_type, nil, ctype_attrs) if real_content_type =~ /multipart/ 98 100 end 99 101 100 @headers.each { |k,v| part[k] = v }102 headers.each { |k,v| part[k] = v } 101 103 102 104 part … … 104 106 105 107 private 108 106 109 def squish(values={}) 107 110 values.delete_if { |k,v| v.nil? } trunk/actionmailer/test/mail_service_test.rb
r3956 r3959 244 244 cc "Three: Four <test@example.com>" 245 245 bcc "Five: Six <test@example.com>" 246 body "testing" 247 end 248 249 def custom_content_type_attributes 250 recipients "no.one@nowhere.test" 251 subject "custom content types" 252 from "some.one@somewhere.test" 253 content_type "text/plain; format=flowed" 246 254 body "testing" 247 255 end … … 788 796 assert_equal 2, mail.parts.length 789 797 end 798 799 def test_custom_content_type_attributes 800 mail = TestMailer.create_custom_content_type_attributes 801 assert_match %r{format=flowed}, mail['content-type'].to_s 802 assert_match %r{charset=utf-8}, mail['content-type'].to_s 803 end 790 804 end 791 805