1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Refactor multiple parts logic and move Utils to PartContainer.

This commit is contained in:
José Valim 2009-12-25 21:46:01 +01:00
parent ee70d1b6ad
commit 88ba056043
4 changed files with 24 additions and 31 deletions

View file

@ -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 @@ module ActionMailer #: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 @@ module ActionMailer #:nodoc:
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

View file

@ -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 @@ module ActionMailer
@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 }

View file

@ -39,8 +39,24 @@ module ActionMailer
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 } ] :

View file

@ -1,7 +0,0 @@
module ActionMailer
module Utils #:nodoc:
def normalize_new_lines(text)
text.to_s.gsub(/\r\n?/, "\n")
end
end
end