aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer
diff options
context:
space:
mode:
authorJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-23 21:37:34 +1100
committerJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-23 21:37:34 +1100
commitc6b16260fe3d1435848e78415bd0b40c10ad7424 (patch)
tree28000447fed5bdaf954b796fcb4c08f66af816aa /actionmailer/lib/action_mailer
parent502028a32bfa46ad18337d2a69f03e8b5dec3c4a (diff)
downloadrails-c6b16260fe3d1435848e78415bd0b40c10ad7424.tar.gz
rails-c6b16260fe3d1435848e78415bd0b40c10ad7424.tar.bz2
rails-c6b16260fe3d1435848e78415bd0b40c10ad7424.zip
Added basic explicit multipart rendering and tests
Diffstat (limited to 'actionmailer/lib/action_mailer')
-rw-r--r--actionmailer/lib/action_mailer/base.rb28
-rw-r--r--actionmailer/lib/action_mailer/mail_helper.rb2
2 files changed, 22 insertions, 8 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 94e20d4b63..28e4c88b5a 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -297,8 +297,9 @@ module ActionMailer #:nodoc:
self.default_implicit_parts_order = [ "text/plain", "text/enriched", "text/html" ]
# Expose the internal Mail message
+ # TODO: Make this an _internal ivar?
attr_reader :message
-
+
def headers(args=nil)
if args
ActiveSupport::Deprecation.warn "headers(Hash) is deprecated, please do headers[key] = value instead", caller
@@ -413,12 +414,25 @@ module ActionMailer #:nodoc:
m.reply_to ||= quote_address_if_necessary(headers[:reply_to], charset) if headers[:reply_to]
m.date ||= headers[:date] if headers[:date]
- if block_given?
- # Do something
+ if headers[:body]
+ templates = [ActionView::Template::Text.new(headers[:body], format_for_text)]
+ elsif block_given?
+ collector = ActionMailer::Collector.new(self, {:charset => charset}) do
+ render action_name
+ end
+ yield collector
+
+ collector.responses.each do |response|
+ part = Mail::Part.new(response)
+ m.add_part(part)
+ end
+
else
# TODO Ensure that we don't need to pass I18n.locale as detail
templates = self.class.template_root.find_all(action_name, {}, self.class.mailer_name)
-
+ end
+
+ if templates
if templates.size == 1 && !m.has_attachments?
content_type ||= templates[0].mime_type.to_s
m.body = render_to_body(:_template => templates[0])
@@ -430,17 +444,17 @@ module ActionMailer #:nodoc:
else
templates.each { |t| insert_part(m, t, charset) }
end
-
- content_type ||= (m.has_attachments? ? "multipart/mixed" : "multipart/alternate")
end
+ content_type ||= (m.has_attachments? ? "multipart/mixed" : "multipart/alternate")
+
# Check if the content_type was not overwriten along the way and if so,
# fallback to default.
m.content_type = content_type || self.class.default_content_type.dup
m.charset = charset
m.mime_version = mime_version
- unless m.parts.empty?
+ if m.parts.present? && templates
m.body.set_sort_order(headers[:parts_order] || self.class.default_implicit_parts_order.dup)
m.body.sort_parts!
end
diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb
index 45ba6f0714..adba94cbef 100644
--- a/actionmailer/lib/action_mailer/mail_helper.rb
+++ b/actionmailer/lib/action_mailer/mail_helper.rb
@@ -18,7 +18,7 @@ module ActionMailer
# Access the mailer instance.
def mailer #:nodoc:
- @controller
+ @_controller
end
# Access the message instance.