aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer
diff options
context:
space:
mode:
authorJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-24 11:15:42 +1100
committerJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-24 11:15:42 +1100
commit258ca148004eaa63740ab2186338b3ac872b8187 (patch)
tree93901307abbe875d3f5913a1383896267db33bff /actionmailer/lib/action_mailer
parente7e4ed48df3048f32d94e398e99d0048a66ba67e (diff)
downloadrails-258ca148004eaa63740ab2186338b3ac872b8187.tar.gz
rails-258ca148004eaa63740ab2186338b3ac872b8187.tar.bz2
rails-258ca148004eaa63740ab2186338b3ac872b8187.zip
Delegated ActionMailer::Base.deliveries to Mail.deliveries, added callback support in Mail to call ActionMailer on delivery, moved deliver to deprecated API in preparation for new API
Diffstat (limited to 'actionmailer/lib/action_mailer')
-rw-r--r--actionmailer/lib/action_mailer/base.rb56
-rw-r--r--actionmailer/lib/action_mailer/deprecated_api.rb32
-rw-r--r--actionmailer/lib/action_mailer/test_case.rb2
3 files changed, 51 insertions, 39 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index e95643ca44..c1dc415728 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -275,8 +275,16 @@ module ActionMailer #:nodoc:
@@perform_deliveries = true
cattr_accessor :perform_deliveries
- @@deliveries = []
- cattr_accessor :deliveries
+ # Provides a list of emails that have been delivered by Mail
+ def self.deliveries
+ Mail.deliveries
+ end
+
+ # Allows you to over write the default deliveries store from an array to some
+ # other object. If you just want to clear the store, call Mail.deliveries.clear.
+ def self.deliveries=(val)
+ Mail.deliveries = val
+ end
extlib_inheritable_accessor :default_charset
self.default_charset = "utf-8"
@@ -342,35 +350,6 @@ module ActionMailer #:nodoc:
end
end
- # Deliver the given mail object directly. This can be used to deliver
- # a preconstructed mail object, like:
- #
- # email = MyMailer.create_some_mail(parameters)
- # email.set_some_obscure_header "frobnicate"
- # MyMailer.deliver(email)
- def deliver(mail)
- raise "no mail object available for delivery!" unless mail
-
- ActiveSupport::Notifications.instrument("action_mailer.deliver", :mailer => self.name) do |payload|
- self.set_payload_for_mail(payload, mail)
-
- mail.delivery_method delivery_methods[delivery_method],
- delivery_settings[delivery_method]
-
- begin
- # TODO Move me to the instance
- if @@perform_deliveries
- mail.deliver!
- self.deliveries << mail
- end
- rescue Exception => e # Net::SMTP errors or sendmail pipe errors
- raise e if raise_delivery_errors
- end
- end
-
- mail
- end
-
def template_root
self.view_paths && self.view_paths.first
end
@@ -380,6 +359,12 @@ module ActionMailer #:nodoc:
self.view_paths = ActionView::Base.process_view_paths(root)
end
+ def delivered_email(mail)
+ ActiveSupport::Notifications.instrument("action_mailer.deliver", :mailer => self.name) do |payload|
+ self.set_payload_for_mail(payload, mail)
+ end
+ end
+
def set_payload_for_mail(payload, mail) #:nodoc:
payload[:message_id] = mail.message_id
payload[:subject] = mail.subject
@@ -402,13 +387,6 @@ module ActionMailer #:nodoc:
process(method_name, *args) if method_name
end
- # Delivers a Mail object. By default, it delivers the cached mail
- # object (from the <tt>create!</tt> method). If no cached mail object exists, and
- # no alternate has been given as the parameter, this will fail.
- def deliver!(mail = @message)
- self.class.deliver(mail)
- end
-
# TODO Add new delivery method goodness
def mail(headers = {})
# Guard flag to prevent both the old and the new API from firing
@@ -417,6 +395,8 @@ module ActionMailer #:nodoc:
m = @message
+ m.register_for_delivery_notification(self.class)
+
# Give preference to headers and fallback to the ones set in mail
content_type = headers[:content_type] || m.content_type
charset = headers[:charset] || m.charset || self.class.default_charset.dup
diff --git a/actionmailer/lib/action_mailer/deprecated_api.rb b/actionmailer/lib/action_mailer/deprecated_api.rb
index b2bb6a64aa..a9ebd70f86 100644
--- a/actionmailer/lib/action_mailer/deprecated_api.rb
+++ b/actionmailer/lib/action_mailer/deprecated_api.rb
@@ -71,9 +71,34 @@ module ActionMailer
# Alias controller_path to mailer_name so render :partial in views work.
alias :controller_path :mailer_name
+
end
module ClassMethods
+
+ # Deliver the given mail object directly. This can be used to deliver
+ # a preconstructed mail object, like:
+ #
+ # email = MyMailer.create_some_mail(parameters)
+ # email.set_some_obscure_header "frobnicate"
+ # MyMailer.deliver(email)
+ def deliver(mail)
+ raise "no mail object available for delivery!" unless mail
+
+ ActiveSupport::Notifications.instrument("action_mailer.deliver", :mailer => self.name) do |payload|
+ self.set_payload_for_mail(payload, mail)
+
+ mail.delivery_method delivery_methods[delivery_method],
+ delivery_settings[delivery_method]
+
+ mail.raise_delivery_errors = raise_delivery_errors
+ mail.perform_deliveries = perform_deliveries
+ mail.deliver
+ end
+
+ mail
+ end
+
def respond_to?(method_symbol, include_private = false) #:nodoc:
matches_dynamic_method?(method_symbol) || super
end
@@ -104,6 +129,13 @@ module ActionMailer
@mail_was_called = false
end
+ # Delivers a Mail object. By default, it delivers the cached mail
+ # object (from the <tt>create!</tt> method). If no cached mail object exists, and
+ # no alternate has been given as the parameter, this will fail.
+ def deliver!(mail = @message)
+ self.class.deliver(mail)
+ end
+
def render(*args)
options = args.last.is_a?(Hash) ? args.last : {}
if options[:body]
diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb
index 0ca4f5494e..7c4033a125 100644
--- a/actionmailer/lib/action_mailer/test_case.rb
+++ b/actionmailer/lib/action_mailer/test_case.rb
@@ -37,7 +37,7 @@ module ActionMailer
def initialize_test_deliveries
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
- ActionMailer::Base.deliveries = []
+ ActionMailer::Base.deliveries.clear
end
def set_expected_mail