aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer
diff options
context:
space:
mode:
Diffstat (limited to 'actionmailer/lib/action_mailer')
-rw-r--r--actionmailer/lib/action_mailer/base.rb69
-rw-r--r--actionmailer/lib/action_mailer/deprecated_api.rb9
-rw-r--r--actionmailer/lib/action_mailer/mail_helper.rb2
3 files changed, 52 insertions, 28 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index d75bbe952f..1f432c2a80 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -280,6 +280,7 @@ module ActionMailer #:nodoc:
extlib_inheritable_accessor :default_charset
self.default_charset = "utf-8"
+ # TODO This should be used when calling render
extlib_inheritable_accessor :default_content_type
self.default_content_type = "text/plain"
@@ -357,7 +358,7 @@ module ActionMailer #:nodoc:
begin
# TODO Move me to the instance
if @@perform_deliveries
- mail.deliver!
+ mail.deliver!
self.deliveries << mail
end
rescue Exception => e # Net::SMTP errors or sendmail pipe errors
@@ -393,32 +394,62 @@ module ActionMailer #:nodoc:
# Guard flag to prevent both the old and the new API from firing
# Should be removed when old API is deprecated
@mail_was_called = true
-
m = @message
-
- m.content_type ||= headers[:content_type] || self.class.default_content_type
- m.charset ||= headers[:charset] || self.class.default_charset
- m.mime_version ||= headers[:mime_version] || self.class.default_mime_version
-
- m.subject = quote_if_necessary(headers[:subject], m.charset) if headers[:subject]
- m.to = quote_address_if_necessary(headers[:to], m.charset) if headers[:to]
- m.from = quote_address_if_necessary(headers[:from], m.charset) if headers[:from]
- m.cc = quote_address_if_necessary(headers[:cc], m.charset) if headers[:cc]
- m.bcc = quote_address_if_necessary(headers[:bcc], m.charset) if headers[:bcc]
- m.reply_to = quote_address_if_necessary(headers[:reply_to], m.charset) if headers[:reply_to]
- m.date = headers[:date] if headers[:date]
- m.body.set_sort_order(headers[:parts_order] || self.class.default_implicit_parts_order)
-
- # # Set the subject if not set yet
- # @subject ||= I18n.t(:subject, :scope => [:actionmailer, mailer_name, method_name],
- # :default => method_name.humanize)
+ # Get default subject from I18n if none is set
+ headers[:subject] ||= I18n.t(:subject, :scope => [:actionmailer, mailer_name, action_name],
+ :default => action_name.humanize)
+
+ # Give preference to headers and fallbacks to the ones set in mail
+ headers[:content_type] ||= m.content_type
+ headers[:charset] ||= m.charset
+ headers[:mime_version] ||= m.mime_version
+
+ m.content_type = headers[:content_type] || self.class.default_content_type.dup
+ m.charset = headers[:charset] || self.class.default_charset.dup
+ m.mime_version = headers[:mime_version] || self.class.default_mime_version.dup
+
+ m.subject ||= quote_if_necessary(headers[:subject], m.charset) if headers[:subject]
+ m.to ||= quote_address_if_necessary(headers[:to], m.charset) if headers[:to]
+ m.from ||= quote_address_if_necessary(headers[:from], m.charset) if headers[:from]
+ m.cc ||= quote_address_if_necessary(headers[:cc], m.charset) if headers[:cc]
+ m.bcc ||= quote_address_if_necessary(headers[:bcc], m.charset) if headers[:bcc]
+ m.reply_to ||= quote_address_if_necessary(headers[:reply_to], m.charset) if headers[:reply_to]
+ m.date ||= headers[:date] if headers[:date]
+
+ if block_given?
+ # Do something
+ else
+ # TODO Ensure that we don't need to pass I18n.locale as detail
+ templates = self.class.template_root.find_all(action_name, {}, mailer_name)
+
+ if templates.size == 1
+ unless headers[:content_type]
+ proper_charset = m.charset
+ m.content_type = templates[0].mime_type.to_s
+ m.charset = proper_charset
+ end
+ m.body = render_to_body(:_template => templates[0])
+ else
+ templates.each do |template|
+ part = Mail::Part.new
+ part.content_type = template.mime_type.to_s
+ part.charset = m.charset
+ part.body = render_to_body(:_template => template)
+ end
+ end
+ end
+ m.body.set_sort_order(headers[:parts_order] || self.class.default_implicit_parts_order.dup)
# TODO: m.body.sort_parts!
m
end
+ def fill_in_part(part, template, charset)
+
+ end
+
# Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
# will be initialized according to the named method. If not, the mailer will
# remain uninitialized (useful when you only need to invoke the "receive"
diff --git a/actionmailer/lib/action_mailer/deprecated_api.rb b/actionmailer/lib/action_mailer/deprecated_api.rb
index 90e2aebf53..b2bb6a64aa 100644
--- a/actionmailer/lib/action_mailer/deprecated_api.rb
+++ b/actionmailer/lib/action_mailer/deprecated_api.rb
@@ -120,19 +120,12 @@ module ActionMailer
initialize_defaults(method_name)
super
unless @mail_was_called
- # Create e-mail parts
create_parts
-
- # Set the subject if not set yet
- @subject ||= I18n.t(:subject, :scope => [:actionmailer, mailer_name, method_name],
- :default => method_name.humanize)
-
- # Build the mail object itself
create_mail
end
+ @message
end
-
# Add a part to a multipart message, with the given content-type. The
# part itself is yielded to the block so that other properties (charset,
# body, headers, etc.) can be set on it.
diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb
index 702c9ba8f7..45ba6f0714 100644
--- a/actionmailer/lib/action_mailer/mail_helper.rb
+++ b/actionmailer/lib/action_mailer/mail_helper.rb
@@ -22,7 +22,7 @@ module ActionMailer
end
# Access the message instance.
- def message
+ def message #:nodoc:
@message
end
end