From 88ba056043e22c4c60dde6b07df897e502f49491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 25 Dec 2009 21:46:01 +0100 Subject: Refactor multiple parts logic and move Utils to PartContainer. --- actionmailer/lib/action_mailer/base.rb | 14 +++----------- actionmailer/lib/action_mailer/part.rb | 14 +++----------- actionmailer/lib/action_mailer/part_container.rb | 20 ++++++++++++++++++-- actionmailer/lib/action_mailer/utils.rb | 7 ------- 4 files changed, 24 insertions(+), 31 deletions(-) delete mode 100644 actionmailer/lib/action_mailer/utils.rb (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 478762f94f..84f5bd23a9 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/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 @@ 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 diff --git a/actionmailer/lib/action_mailer/part.rb b/actionmailer/lib/action_mailer/part.rb index 9ff962c39a..716eaae86e 100644 --- a/actionmailer/lib/action_mailer/part.rb +++ b/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 @@ 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 } diff --git a/actionmailer/lib/action_mailer/part_container.rb b/actionmailer/lib/action_mailer/part_container.rb index abfd8f8426..3fe502b1fb 100644 --- a/actionmailer/lib/action_mailer/part_container.rb +++ b/actionmailer/lib/action_mailer/part_container.rb @@ -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 } ] : diff --git a/actionmailer/lib/action_mailer/utils.rb b/actionmailer/lib/action_mailer/utils.rb deleted file mode 100644 index 26d2e60aaf..0000000000 --- a/actionmailer/lib/action_mailer/utils.rb +++ /dev/null @@ -1,7 +0,0 @@ -module ActionMailer - module Utils #:nodoc: - def normalize_new_lines(text) - text.to_s.gsub(/\r\n?/, "\n") - end - end -end -- cgit v1.2.3