Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor multiple parts logic and move Utils to PartContainer.

  • Loading branch information...
commit 88ba056043e22c4c60dde6b07df897e502f49491 1 parent ee70d1b
@josevalim josevalim authored
View
14 actionmailer/lib/action_mailer/base.rb
@@ -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
View
14 actionmailer/lib/action_mailer/part.rb
@@ -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 }
View
20 actionmailer/lib/action_mailer/part_container.rb
@@ -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 } ] :
View
7 actionmailer/lib/action_mailer/utils.rb
@@ -1,7 +0,0 @@
-module ActionMailer
- module Utils #:nodoc:
- def normalize_new_lines(text)
- text.to_s.gsub(/\r\n?/, "\n")
- end
- end
-end

0 comments on commit 88ba056

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