diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2009-12-22 17:31:29 -0800 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2009-12-22 17:31:29 -0800 |
commit | e7ef57dd0ddec3d487d3ffd58ff028bdf11a33f9 (patch) | |
tree | dfc9e049c937a56c2fc1e80ae8e8b71880d1615d /actionmailer | |
parent | ec095456d859da4a09c7401585c211dc0f01fccd (diff) | |
parent | f737c2d69bb3659a553c7c0e21e316b1a4a1b98a (diff) | |
download | rails-e7ef57dd0ddec3d487d3ffd58ff028bdf11a33f9.tar.gz rails-e7ef57dd0ddec3d487d3ffd58ff028bdf11a33f9.tar.bz2 rails-e7ef57dd0ddec3d487d3ffd58ff028bdf11a33f9.zip |
Merge
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/lib/action_mailer.rb | 15 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 63 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/delivery_method.rb | 5 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/delivery_method/smtp.rb | 4 | ||||
-rw-r--r-- | actionmailer/test/mail_service_test.rb | 8 | ||||
-rw-r--r-- | actionmailer/test/url_test.rb | 4 |
6 files changed, 30 insertions, 69 deletions
diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index f439eb175c..d7bbbbd78c 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -41,18 +41,3 @@ module ActionMailer autoload :TestHelper autoload :Utils end - -module Text - extend ActiveSupport::Autoload - - autoload :Format, 'action_mailer/vendor/text_format' -end - -module Net - extend ActiveSupport::Autoload - - autoload :SMTP -end - - -require 'action_mailer/vendor/tmail' diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 40aff7f0d8..de78e87fb4 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,4 +1,7 @@ require 'active_support/core_ext/class' +require 'action_mailer/part' +require 'action_mailer/vendor/text_format' +require 'action_mailer/vendor/tmail' module ActionMailer #:nodoc: # Action Mailer allows you to send email from your application using a mailer model and views. @@ -250,31 +253,21 @@ module ActionMailer #:nodoc: # <tt>["text/html", "text/enriched", "text/plain"]</tt>. Items that appear first in the array have higher priority in the mail client # 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 + class Base < AbstractController::Base include AdvAttrAccessor, PartContainer, Quoting, Utils include AbstractController::Rendering include AbstractController::LocalizedCache include AbstractController::Layouts - include AbstractController::Helpers - helper ActionMailer::MailHelper - if Object.const_defined?(:ActionController) - include ActionController::UrlWriter - end + helper ActionMailer::MailHelper + include ActionController::UrlWriter include ActionMailer::DeprecatedBody private_class_method :new #:nodoc: - class_inheritable_accessor :view_paths - self.view_paths = [] - - attr_internal :formats - - cattr_accessor :logger - @@raise_delivery_errors = true cattr_accessor :raise_delivery_errors @@ -346,24 +339,13 @@ module ActionMailer #:nodoc: # have multiple mailer methods share the same template. adv_attr_accessor :template - # The mail and action_name instances referenced by this mailer. - attr_reader :mail, :action_name - - # Where the response body is stored. - attr_internal :response_body - # Override the mailer name, which defaults to an inflected version of the # mailer's class name. If you want to use a template in a non-standard # location, you can use this to specify that location. - attr_writer :mailer_name + adv_attr_accessor :mailer_name - def mailer_name(value = nil) - if value - @mailer_name = value - else - @mailer_name || self.class.mailer_name - end - end + # Expose the internal mail + attr_reader :mail # Alias controller_path to mailer_name so render :partial in views work. alias :controller_path :mailer_name @@ -453,18 +435,16 @@ module ActionMailer #:nodoc: # will be initialized according to the named method. If not, the mailer will # remain uninitialized (useful when you only need to invoke the "receive" # method, for instance). - def initialize(method_name=nil, *parameters) #:nodoc: - @_formats = [] - @_response_body = nil + def initialize(method_name=nil, *args) #:nodoc: super() - create!(method_name, *parameters) if method_name + process(method_name, *args) if method_name end - # Initialize the mailer via the given +method_name+. The body will be + # Process the mailer via the given +method_name+. The body will be # rendered and a new TMail::Mail object created. - def create!(method_name, *parameters) #:nodoc: + def process(method_name, *args) #:nodoc: initialize_defaults(method_name) - __send__(method_name, *parameters) + super # Create e-mail parts create_parts @@ -473,7 +453,7 @@ module ActionMailer #:nodoc: @subject ||= I18n.t(:subject, :scope => [:actionmailer, mailer_name, method_name], :default => method_name.humanize) - # build the mail object itself + # Build the mail object itself @mail = create_mail end @@ -488,7 +468,7 @@ module ActionMailer #:nodoc: logger.debug "\n#{mail.encoded}" end - ActiveSupport::Notifications.instrument(:deliver_mail, :mail => @mail) do + ActiveSupport::Notifications.instrument(:deliver_mail, :mail => mail) do begin self.delivery_method.perform_delivery(mail) if perform_deliveries rescue Exception => e # Net::SMTP errors or sendmail pipe errors @@ -510,23 +490,18 @@ module ActionMailer #:nodoc: @implicit_parts_order ||= @@default_implicit_parts_order.dup @mime_version ||= @@default_mime_version.dup if @@default_mime_version - @mailer_name ||= self.class.mailer_name + @mailer_name ||= self.class.mailer_name.dup @template ||= method_name - @action_name = @template @parts ||= [] @headers ||= {} @sent_on ||= Time.now - ActiveSupport::Deprecation.silence do - super # Run deprecation hooks - end + super # Run deprecation hooks end def create_parts - ActiveSupport::Deprecation.silence do - super # Run deprecation hooks - end + super # Run deprecation hooks if String === response_body @parts.unshift Part.new( diff --git a/actionmailer/lib/action_mailer/delivery_method.rb b/actionmailer/lib/action_mailer/delivery_method.rb index 29a51afdc3..4f7d3afc3c 100644 --- a/actionmailer/lib/action_mailer/delivery_method.rb +++ b/actionmailer/lib/action_mailer/delivery_method.rb @@ -1,7 +1,7 @@ -require "active_support/core_ext/class" +require 'active_support/core_ext/class' + module ActionMailer module DeliveryMethod - autoload :File, 'action_mailer/delivery_method/file' autoload :Sendmail, 'action_mailer/delivery_method/sendmail' autoload :Smtp, 'action_mailer/delivery_method/smtp' @@ -52,6 +52,5 @@ module ActionMailer superclass_delegating_accessor :settings self.settings = {} end - end end diff --git a/actionmailer/lib/action_mailer/delivery_method/smtp.rb b/actionmailer/lib/action_mailer/delivery_method/smtp.rb index 95c117c9e0..f81d64af36 100644 --- a/actionmailer/lib/action_mailer/delivery_method/smtp.rb +++ b/actionmailer/lib/action_mailer/delivery_method/smtp.rb @@ -1,8 +1,9 @@ +require 'net/smtp' + module ActionMailer module DeliveryMethod # A delivery method implementation which sends via smtp. class Smtp < Method - self.settings = { :address => "localhost", :port => 25, @@ -26,6 +27,5 @@ module ActionMailer end end end - end end diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 697265b8ec..1cd3bc77c4 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -34,13 +34,13 @@ class TestMailer < ActionMailer::Base def from_with_name from "System <system@loudthinking.com>" recipients "root@loudthinking.com" - body "Nothing to see here." + render :text => "Nothing to see here." end def from_without_name from "system@loudthinking.com" recipients "root@loudthinking.com" - body "Nothing to see here." + render :text => "Nothing to see here." end def cc_bcc(recipient) @@ -301,6 +301,7 @@ class TestMailer < ActionMailer::Base render :text => "testing" end + # This tests body calls accepeting a hash, which is deprecated. def body_ivar(recipient) recipients recipient subject "Body as a local variable" @@ -1043,7 +1044,8 @@ EOF end def test_body_is_stored_as_an_ivar - mail = TestMailer.create_body_ivar(@recipient) + mail = nil + ActiveSupport::Deprecation.silence { mail = TestMailer.create_body_ivar(@recipient) } assert_equal "body: foo\nbar: baz", mail.body end diff --git a/actionmailer/test/url_test.rb b/actionmailer/test/url_test.rb index 18eb355e7d..1140613132 100644 --- a/actionmailer/test/url_test.rb +++ b/actionmailer/test/url_test.rb @@ -12,8 +12,8 @@ class TestMailer < ActionMailer::Base @from = "system@loudthinking.com" @sent_on = Time.local(2004, 12, 12) - @body["recipient"] = recipient - @body["welcome_url"] = url_for :host => "example.com", :controller => "welcome", :action => "greeting" + @recipient = recipient + @welcome_url = url_for :host => "example.com", :controller => "welcome", :action => "greeting" end class <<self |