mirror of https://github.com/rails/rails
Moved sort_parts into Mail, updated mail requirement to 1.4.2
This commit is contained in:
parent
971f4ff829
commit
c039bcdb1c
2
Gemfile
2
Gemfile
|
@ -10,7 +10,7 @@ end
|
|||
gem "i18n", ">= 0.3.0"
|
||||
|
||||
# AM
|
||||
gem "mail", ">= 1.4.1"
|
||||
gem "mail", ">= 1.4.2"
|
||||
|
||||
# AR
|
||||
gem "arel", "0.2.pre", :git => "git://github.com/rails/arel.git"
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
*Mail Integration
|
||||
|
||||
* 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.
|
||||
|
||||
* Mail does not have "quoted_body", "quoted_subject" etc. All of these are accessed via body.encoded,
|
||||
subject.encoded etc
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
actionpack_path = File.expand_path('../../../actionpack/lib', __FILE__)
|
||||
$:.unshift(actionpack_path) if File.directory?(actionpack_path) && !$:.include?(actionpack_path)
|
||||
|
||||
|
||||
require 'action_controller'
|
||||
require 'action_view'
|
||||
|
||||
|
|
|
@ -282,7 +282,13 @@ module ActionMailer #:nodoc:
|
|||
@@default_mime_version = "1.0"
|
||||
cattr_accessor :default_mime_version
|
||||
|
||||
@@default_implicit_parts_order = [ "text/html", "text/enriched", "text/plain" ]
|
||||
# This specifies the order that the parts of a multipart email will be. Usually you put
|
||||
# text/plain at the top so someone without a MIME capable email reader can read the plain
|
||||
# text of your email first.
|
||||
#
|
||||
# Any content type that is not listed here will be inserted in the order you add them to
|
||||
# the email after the content types you list here.
|
||||
@@default_implicit_parts_order = [ "text/plain", "text/enriched", "text/html" ]
|
||||
cattr_accessor :default_implicit_parts_order
|
||||
|
||||
@@protected_instance_variables = %w(@parts @mail)
|
||||
|
@ -534,7 +540,6 @@ module ActionMailer #:nodoc:
|
|||
|
||||
if @parts.size > 1
|
||||
@content_type = "multipart/alternative" if @content_type !~ /^multipart/
|
||||
@parts = sort_parts(@parts, @implicit_parts_order)
|
||||
end
|
||||
|
||||
# If this is a multipart e-mail add the mime_version if it is not
|
||||
|
@ -554,35 +559,6 @@ module ActionMailer #:nodoc:
|
|||
)
|
||||
end
|
||||
|
||||
def sort_parts(parts, order = []) #:nodoc:
|
||||
order = order.collect { |s| s.downcase }
|
||||
|
||||
parts = parts.sort do |a, b|
|
||||
a_ct = a.content_type.string.downcase
|
||||
b_ct = b.content_type.string.downcase
|
||||
|
||||
a_in = order.include? a_ct
|
||||
b_in = order.include? b_ct
|
||||
|
||||
s = case
|
||||
when a_in && b_in
|
||||
order.index(a_ct) <=> order.index(b_ct)
|
||||
when a_in
|
||||
-1
|
||||
when b_in
|
||||
1
|
||||
else
|
||||
a_ct <=> b_ct
|
||||
end
|
||||
|
||||
# reverse the ordering because parts that come last are displayed
|
||||
# first in mail clients
|
||||
(s * -1)
|
||||
end
|
||||
|
||||
parts
|
||||
end
|
||||
|
||||
def create_mail #:nodoc:
|
||||
m = Mail.new
|
||||
|
||||
|
@ -606,9 +582,12 @@ module ActionMailer #:nodoc:
|
|||
m.content_type([main_type, sub_type, ctype_attrs])
|
||||
m.body = @parts.first.body.encoded
|
||||
else
|
||||
|
||||
@parts.each do |p|
|
||||
m.add_part(p)
|
||||
end
|
||||
m.body.set_sort_order(@implicit_parts_order)
|
||||
m.body.sort_parts!
|
||||
|
||||
if real_content_type =~ /multipart/
|
||||
ctype_attrs.delete "charset"
|
||||
|
|
|
@ -930,7 +930,6 @@ EOF
|
|||
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 "text/html", mail.parts[1].content_type.string
|
||||
|
@ -938,7 +937,6 @@ EOF
|
|||
|
||||
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_nil mail.parts[2].charset
|
||||
|
@ -963,11 +961,11 @@ EOF
|
|||
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 "application/x-yaml", mail.parts[0].content_type.string
|
||||
assert_equal "text/plain", mail.parts[0].content_type.string
|
||||
assert_equal "utf-8", mail.parts[0].charset
|
||||
assert_equal "text/plain", mail.parts[1].content_type.string
|
||||
assert_equal "text/html", mail.parts[1].content_type.string
|
||||
assert_equal "utf-8", mail.parts[1].charset
|
||||
assert_equal "text/html", mail.parts[2].content_type.string
|
||||
assert_equal "application/x-yaml", mail.parts[2].content_type.string
|
||||
assert_equal "utf-8", mail.parts[2].charset
|
||||
end
|
||||
|
||||
|
@ -976,9 +974,9 @@ EOF
|
|||
|
||||
mail = TestMailer.create_implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"])
|
||||
assert_equal 3, mail.parts.length
|
||||
assert_equal "text/html", mail.parts[0].content_type.string
|
||||
assert_equal "application/x-yaml", mail.parts[0].content_type.string
|
||||
assert_equal "text/plain", mail.parts[1].content_type.string
|
||||
assert_equal "application/x-yaml", mail.parts[2].content_type.string
|
||||
assert_equal "text/html", mail.parts[2].content_type.string
|
||||
end
|
||||
|
||||
def test_implicitly_multipart_messages_with_charset
|
||||
|
|
Loading…
Reference in New Issue