lib/action_mailer/base.rb in actionmailer-3.0.20 vs lib/action_mailer/base.rb in actionmailer-3.1.0.beta1

- old
+ new

@@ -3,10 +3,11 @@ require 'action_mailer/collector' require 'active_support/core_ext/array/wrap' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/proc' require 'active_support/core_ext/string/inflections' +require 'active_support/core_ext/hash/except' require 'action_mailer/log_subscriber' module ActionMailer #:nodoc: # Action Mailer allows you to send email from your application using a mailer model and views. # @@ -221,11 +222,11 @@ # An observer object must implement the <tt>:delivered_email(message)</tt> method which will be # called once for every email sent after the email has been sent. # # An interceptor object must implement the <tt>:delivering_email(message)</tt> method which will be # called before the email is sent, allowing you to make modifications to the email before it hits - # the delivery agents. Your object should make and needed modifications directly to the passed + # the delivery agents. Your object should make any needed modifications directly to the passed # in Mail::Message instance. # # = Default Hash # # Action Mailer provides some intelligent defaults for your emails, these are usually specified in a @@ -245,11 +246,11 @@ # # <tt>parts_order</tt> and <tt>charset</tt> are not actually valid <tt>Mail::Message</tt> header fields, # but Action Mailer translates them appropriately and sets the correct values. # # As you can pass in any header, you need to either quote the header as a string, or pass it in as - # an underscorised symbol, so the following will work: + # an underscored symbol, so the following will work: # # class Notifier < ActionMailer::Base # default 'Content-Transfer-Encoding' => '7bit', # :content_description => 'This is a description' # end @@ -290,18 +291,22 @@ # * <tt>:user_name</tt> - If your mail server requires authentication, set the username in this setting. # * <tt>:password</tt> - If your mail server requires authentication, set the password in this setting. # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the # authentication type here. # This is a symbol and one of <tt>:plain</tt> (will send the password in the clear), <tt>:login</tt> (will - # send password BASE64 encoded) or <tt>:cram_md5</tt> (combines a Challenge/Response mechanism to exchange + # send password Base64 encoded) or <tt>:cram_md5</tt> (combines a Challenge/Response mechanism to exchange # information and a cryptographic Message Digest 5 algorithm to hash important information) # * <tt>:enable_starttls_auto</tt> - When set to true, detects if STARTTLS is enabled in your SMTP server # and starts to use it. + # * <tt>:openssl_verify_mode</tt> - When using TLS, you can set how OpenSSL checks the certificate. This is + # really useful if you need to validate a self-signed and/or a wildcard certificate. You can use the name + # of an OpenSSL verify constant ('none', 'peer', 'client_once','fail_if_no_peer_cert') or directly the + # constant (OpenSSL::SSL::VERIFY_NONE, OpenSSL::SSL::VERIFY_PEER,...). # # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method. # * <tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>. - # * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt> with <tt>-f sender@addres</tt> + # * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt> with <tt>-f sender@address</tt> # added automatically before the message is sent. # # * <tt>file_settings</tt> - Allows you to override options for the <tt>:file</tt> delivery method. # * <tt>:location</tt> - The directory into which emails will be written. Defaults to the application # <tt>tmp/mails</tt>. @@ -342,14 +347,15 @@ include AbstractController::Layouts include AbstractController::Helpers include AbstractController::Translation include AbstractController::AssetPaths - helper ActionMailer::MailHelper + cattr_reader :protected_instance_variables + @@protected_instance_variables = [] + helper ActionMailer::MailHelper include ActionMailer::OldApi - include ActionMailer::DeprecatedApi private_class_method :new #:nodoc: class_attribute :default_params self.default_params = { @@ -425,18 +431,18 @@ self.set_payload_for_mail(payload, mail) yield # Let Mail do the delivery actions end end - def respond_to?(method, *args) #:nodoc: + def respond_to?(method, include_private = false) #:nodoc: super || action_methods.include?(method.to_s) end protected def set_payload_for_mail(payload, mail) #:nodoc: - payload[:mailer] = self.name + payload[:mailer] = name 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? @@ -444,15 +450,12 @@ payload[:date] = mail.date payload[:mail] = mail.encoded end def method_missing(method, *args) #:nodoc: - if action_methods.include?(method.to_s) - new(method, *args).message - else - super - end + return super unless respond_to?(method) + new(method, *args).message end end attr_internal :message @@ -469,35 +472,12 @@ def process(*args) #:nodoc: lookup_context.skip_default_locale! super end - class DeprecatedHeaderProxy < ActiveSupport::BasicObject - def initialize(message) - @message = message - end - - def []=(key, value) - unless value.is_a?(::String) - ::ActiveSupport::Deprecation.warn("Using a non-String object for a header's value is deprecated. " \ - "You specified #{value.inspect} (a #{value.class}) for #{key}", caller) - - value = value.to_s - end - - @message[key] = value - end - - def headers(hash = {}) - hash.each_pair do |k,v| - self[k] = v - end - end - - def method_missing(meth, *args, &block) - @message.send(meth, *args, &block) - end + def mailer_name + self.class.mailer_name end # Allows you to pass random and unusual headers to the new +Mail::Message+ object # which will add them to itself. # @@ -512,13 +492,13 @@ # The resulting Mail::Message will have the following in it's header: # # X-Special-Domain-Specific-Header: SecretValue def headers(args=nil) if args - DeprecatedHeaderProxy.new(@_message).headers(args) + @_message.headers(args) else - DeprecatedHeaderProxy.new(@_message) + @_message end end # Allows you to add attachments to an email, like so: # @@ -704,10 +684,13 @@ else m.content_type || class_default end end + # Translates the +subject+ using Rails I18n class under <tt>[:actionmailer, mailer_scope, action_name]</tt> scope. + # If it does not find a translation for the +subject+ under the specified scope it will default to a + # humanized version of the <tt>action_name</tt>. def default_i18n_subject #:nodoc: mailer_scope = self.class.mailer_name.gsub('/', '.') I18n.t(:subject, :scope => [mailer_scope, action_name], :default => action_name.humanize) end @@ -740,19 +723,12 @@ [responses, parts_order] end def each_template(paths, name, &block) #:nodoc: - Array.wrap(paths).each do |path| - templates = lookup_context.find_all(name, path) - templates = templates.uniq_by { |t| t.formats } - - unless templates.empty? - templates.each(&block) - return - end - end + templates = lookup_context.find_all(name, Array.wrap(paths)) + templates.uniq_by { |t| t.formats }.each(&block) end def create_parts_from_responses(m, responses) #:nodoc: if responses.size == 1 && !m.has_attachments? responses[0].each { |k,v| m[k] = v } @@ -769,31 +745,9 @@ def insert_part(container, response, charset) #:nodoc: response[:charset] ||= charset part = Mail::Part.new(response) container.add_part(part) end - - module DeprecatedUrlOptions - def default_url_options - deprecated_url_options - end - - def default_url_options=(val) - deprecated_url_options - end - - def deprecated_url_options - raise "You can no longer call ActionMailer::Base.default_url_options " \ - "directly. You need to set config.action_mailer.default_url_options. " \ - "If you are using ActionMailer standalone, you need to include the " \ - "routing url_helpers directly." - end - end - - # This module will complain if the user tries to set default_url_options - # directly instead of through the config object. In Action Mailer's Railtie, - # we include the router's url_helpers, which will override this module. - extend DeprecatedUrlOptions ActiveSupport.run_load_hooks(:action_mailer, self) end end