提交 88ba0560 编写于 作者: J José Valim

Refactor multiple parts logic and move Utils to PartContainer.

上级 ee70d1b6
......@@ -253,7 +253,7 @@ module ActionMailer #:nodoc:
# and appear last in the mime encoded message. You can also pick a different order from inside a method with
# +implicit_parts_order+.
class Base < AbstractController::Base
include PartContainer, Quoting, Utils
include PartContainer, Quoting
extend AdvAttrAccessor
include AbstractController::Rendering
......@@ -454,7 +454,7 @@ def process(method_name, *args) #:nodoc:
:default => method_name.humanize)
# Build the mail object itself
@mail = create_mail
create_mail
end
# Delivers a TMail::Mail object. By default, it delivers the cached mail
......@@ -582,15 +582,7 @@ def create_mail
m.set_content_type(real_content_type, nil, ctype_attrs)
m.body = normalize_new_lines(@parts.first.body)
else
@parts.each do |p|
part = (TMail::Mail === p ? p : p.to_mail(self))
m.parts << part
end
if real_content_type =~ /multipart/
ctype_attrs.delete "charset"
m.set_content_type(real_content_type, nil, ctype_attrs)
end
setup_multiple_parts(m, real_content_type, ctype_attrs)
end
@mail = m
......
......@@ -4,7 +4,7 @@ module ActionMailer
# and add them to the +parts+ list of the mailer, it is easier
# to use the helper methods in ActionMailer::PartContainer.
class Part
include PartContainer, Utils
include PartContainer
extend AdvAttrAccessor
# Represents the body of the part, as a string. This should not be a
......@@ -83,16 +83,8 @@ def to_mail(defaults)
@parts.unshift Part.new(:charset => charset, :body => @body, :content_type => 'text/plain')
@body = nil
end
@parts.each do |p|
prt = (TMail::Mail === p ? p : p.to_mail(defaults))
part.parts << prt
end
if real_content_type =~ /multipart/
ctype_attrs.delete 'charset'
part.set_content_type(real_content_type, nil, ctype_attrs)
end
setup_multiple_parts(part, real_content_type, ctype_attrs)
end
headers.each { |k,v| part[k] = v }
......
......@@ -39,8 +39,24 @@ def attachment(params, &block)
end
private
def parse_content_type(defaults=nil)
def normalize_new_lines(text) #:nodoc:
text.to_s.gsub(/\r\n?/, "\n")
end
def setup_multiple_parts(mailer, real_content_type, ctype_attrs) #:nodoc:
@parts.each do |p|
part = (TMail::Mail === p ? p : p.to_mail(self))
mailer.parts << part
end
if real_content_type =~ /multipart/
ctype_attrs.delete "charset"
mailer.set_content_type(real_content_type, nil, ctype_attrs)
end
end
def parse_content_type(defaults=nil) #:nodoc:
if content_type.blank?
return defaults ?
[ defaults.content_type, { 'charset' => defaults.charset } ] :
......
module ActionMailer
module Utils #:nodoc:
def normalize_new_lines(text)
text.to_s.gsub(/\r\n?/, "\n")
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册