diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-17 03:20:30 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-17 03:20:30 +0530 |
commit | b04230e3bbf912d60601e9e7b797c4cd43581d51 (patch) | |
tree | 97a2f784a2ec2bfae4f960af56a9280dad6f7774 /actionmailer/lib | |
parent | 867829b187969607aa12f2b0457f25da9c204db0 (diff) | |
parent | 6e3bee6cf1f0d2684152292db0a8b757249824fd (diff) | |
download | rails-b04230e3bbf912d60601e9e7b797c4cd43581d51.tar.gz rails-b04230e3bbf912d60601e9e7b797c4cd43581d51.tar.bz2 rails-b04230e3bbf912d60601e9e7b797c4cd43581d51.zip |
Merge remote branch 'mainstream/master'
Conflicts:
actionpack/lib/action_controller/metal/flash.rb
Diffstat (limited to 'actionmailer/lib')
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 40 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/railtie.rb | 3 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/railties/subscriber.rb | 20 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/test_case.rb | 3 |
4 files changed, 48 insertions, 18 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 25b8e4874e..5be1beaedb 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -259,10 +259,9 @@ module ActionMailer #:nodoc: include AbstractController::LocalizedCache include AbstractController::Layouts include AbstractController::Helpers + include AbstractController::UrlFor helper ActionMailer::MailHelper - - include ActionController::UrlWriter include ActionMailer::DeprecatedBody private_class_method :new #:nodoc: @@ -399,10 +398,12 @@ module ActionMailer #:nodoc: # ... # end # end - def receive(raw_email) - logger.info "Received mail:\n #{raw_email}" unless logger.nil? - mail = Mail.new(raw_email) - new.receive(mail) + def receive(raw_mail) + ActiveSupport::Notifications.instrument("action_mailer.receive") do |payload| + mail = Mail.new(raw_mail) + set_payload_for_mail(payload, mail) + new.receive(mail) + end end # Deliver the given mail object directly. This can be used to deliver @@ -424,7 +425,19 @@ module ActionMailer #:nodoc: self.view_paths = ActionView::Base.process_view_paths(root) end + def set_payload_for_mail(payload, mail) #:nodoc: + payload[:message_id] = mail.message_id + payload[:subject] = mail.subject + payload[:to] = mail.to + payload[:from] = mail.from + payload[:bcc] = mail.bcc if mail.bcc.present? + payload[:cc] = mail.cc if mail.cc.present? + payload[:date] = mail.date + payload[:mail] = mail.encoded + end + private + def matches_dynamic_method?(method_name) #:nodoc: method_name = method_name.to_s /^(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name) @@ -495,17 +508,14 @@ module ActionMailer #:nodoc: def deliver!(mail = @mail) raise "no mail object available for delivery!" unless mail - if logger - logger.info "Sent mail to #{Array(recipients).join(', ')}" - logger.debug "\n#{mail.encoded}" - end - - ActiveSupport::Notifications.instrument(:deliver_mail, :mail => mail) do - begin + begin + ActiveSupport::Notifications.instrument("action_mailer.deliver", + :template => template, :mailer => self.class.name) do |payload| + self.class.set_payload_for_mail(payload, mail) self.delivery_method.perform_delivery(mail) if perform_deliveries - rescue Exception => e # Net::SMTP errors or sendmail pipe errors - raise e if raise_delivery_errors end + rescue Exception => e # Net::SMTP errors or sendmail pipe errors + raise e if raise_delivery_errors end mail diff --git a/actionmailer/lib/action_mailer/railtie.rb b/actionmailer/lib/action_mailer/railtie.rb index 5410c7d75f..b05d21ae5d 100644 --- a/actionmailer/lib/action_mailer/railtie.rb +++ b/actionmailer/lib/action_mailer/railtie.rb @@ -5,6 +5,9 @@ module ActionMailer class Railtie < Rails::Railtie plugin_name :action_mailer + require "action_mailer/railties/subscriber" + subscriber ActionMailer::Railties::Subscriber.new + initializer "action_mailer.set_configs" do |app| app.config.action_mailer.each do |k,v| ActionMailer::Base.send "#{k}=", v diff --git a/actionmailer/lib/action_mailer/railties/subscriber.rb b/actionmailer/lib/action_mailer/railties/subscriber.rb new file mode 100644 index 0000000000..af9c477237 --- /dev/null +++ b/actionmailer/lib/action_mailer/railties/subscriber.rb @@ -0,0 +1,20 @@ +module ActionMailer + module Railties + class Subscriber < Rails::Subscriber + def deliver(event) + recipients = Array(event.payload[:to]).join(', ') + info("Sent mail to #{recipients} (%1.fms)" % event.duration) + debug("\n#{event.payload[:mail]}") + end + + def receive(event) + info("Received mail (%.1fms)" % event.duration) + debug("\n#{event.payload[:mail]}") + end + + def logger + ActionMailer::Base.logger + end + end + end +end
\ No newline at end of file diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb index e8632d4559..318a1e46d1 100644 --- a/actionmailer/lib/action_mailer/test_case.rb +++ b/actionmailer/lib/action_mailer/test_case.rb @@ -1,6 +1,3 @@ -require 'active_support/test_case' -require 'action_mailer/base' - module ActionMailer class NonInferrableMailerError < ::StandardError def initialize(name) |